← Back to companies
[ OK ] Loaded —
[ INFO ]
$ cd
$ ls -lt
01
02
03
04
05
$ ls -lt
01
02
03
04
05
user@intervues:~/$
Problem Statement
You are given an integer array nums sorted in ascending order (with distinct values), and it might have been rotated at an unknown pivot index. Write a function that searches for a given target value and returns its index if found, otherwise return -1. Your solution must achieve O(log n) time complexity using a modified binary search approach.[1][2][7]
Input/Output Examples
nums = [4,5,6,7,0,1,2], target = 0 → Output: 4 (target at index 4).[2]nums = [4,5,6,7,0,1,2], target = 3 → Output: -1 (target not found).[1]nums = [1], target = 0 → Output: -1.[7]Constraints
1 <= nums.length <= 5000[2]-10^4 <= nums[i] <= 10^4[7]nums[i] are unique (no duplicates).[1][2]nums was originally sorted in ascending order.[7][1]