PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#BS0000091. Tìm phần tử trong dãy xoay (Search in Rotated Sorted Array)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Tìm phần tử trong dãy xoay (Search in Rotated Sorted Array)
Search in Rotated Sorted Array
Source: LeetCode
Version: Phuoc Hung OJ Extended
Problem Statement
Given a possibly rotated strictly increasing array with distinct elements, find the zero-based index of , or if absent.
Input
The first line contains and the next line contains array values after rotation.
Output
Print the zero-based index of , or -1.
Subtasks
- Subtask 1 (20 points): ; ; distinct values; a cyclic rotation of a strictly increasing array.
- Subtask 2 (30 points): ; ; distinct values; a cyclic rotation of a strictly increasing array.
- Subtask 3 (50 points): ; ; distinct values; a cyclic rotation of a strictly increasing array.
Examples
Input
7 0
4 5 6 7 0 1 2
Output
4
Explanation
The target is the fifth entry of , at zero-based index .