O73
Search in Rotated Sorted Array
Problem Statement & Objective
Given the array nums after the possible rotation and an integer target, return the index of target if it is in nums, or -1 if it is not in nums.
Function Signature (Python)
search_rotated_array(nums: list[int], target: int) -> intInput & Output Contract
Output Rule:Hedefin indeksi veya -1.
System Constraints
1 <= sayilar.length <= 10^5
-10^4 <= sayilar[i], hedef <= 10^4
Tüm elemanlar benzersizdirExample Execution Walkthrough
sayilar = [4, 5, 6, 7, 0, 1, 2], hedef = 0 -> indeks 4
sayilar = [4, 5, 6, 7, 0, 1, 2], hedef = 3 -> yok -> -1Example Test Scenarios (3)
Example 1
Input:
[[4,5,6,7,0,1,2],0]Expected Output:
4Example 2: Yok
Input:
[[4,5,6,7,0,1,2],3]Expected Output:
-1Example 3: Single Element
Input:
[[1],0]Expected Output:
-1