O73

Search in Rotated Sorted Array

Mid / Senior Engineer
Target Time: 25 - 35 Minutes
Type: NUMERIC

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) -> int

Input & 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 benzersizdir

Example 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 -> -1

Example Test Scenarios (3)

Example 1
Input:[[4,5,6,7,0,1,2],0]
Expected Output:4
Example 2: Yok
Input:[[4,5,6,7,0,1,2],3]
Expected Output:-1
Example 3: Single Element
Input:[[1],0]
Expected Output:-1
Loading Python Editor...
Input Parameters
[
  [
    4,
    5,
    6,
    7,
    0,
    1,
    2
  ],
  0
]
Expected Output
4