Sale
Summer Offer: $190/yr $99/yr
00 : 00 : 00 : 00
Get this deal
Backend Engineer Senior programming

Given a rotated sorted array, write a function to search for a target value. If found, return its index; otherwise, return -1.


Function Signature


def search(nums: List[int], target: int) -> int:

Constraints


  • 1 <= nums.length <= 5000

  • -10^4 <= nums[i] <= 10^4


Examples


1. Input: search([4,5,6,7,0,1,2], 0)
Output: 4
2. Input: search([4,5,6,7,0,1,2], 3)
Output: -1
Suggested Answer

Trusted by 100+ professionals preparing for interviews

Trusted by 100+ professionals 50+ Company Question Banks 5+ Supported Languages

Practice More Questions Like This

Generate unlimited interview questions with structured answers, code runner, and AI-powered walkthroughs.

Get Started Free
Link copied to clipboard