Java: Search in Rotated Sorted Array

Level : Intermediate
Mentor: Amit Kumar Ghosh
Type : GuidedLab
Points : 10
Duration : 00:25:00

Lab Details

Difficulty Level: MEDIUM

Problem Statement:

You are given an integer array `nums` sorted in ascending order (with distinct values), and an integer `target`. Suppose that `nums` is rotated at some pivot unknown to you beforehand. You are given a `target` value to search. If found in the array, return its index, otherwise return `-1`

Input:

nums = [4,5,6,7,0,1,2], target = 0

Output:

4

The array was rotated at index 4, and the target 0 is found at index 4.

Self-paced Membership
  • 22+ Video Courses
  • 800+ Hands-On Labs
  • 400+ Quick Notes
  • 55+ Skill Tests
  • 45+ Interview Q&A Courses
  • 10+ Real-world Projects
  • Career Coaching Sessions
  • Email Support
Upto 60% OFF
Know More
Still have some questions? Let's discuss.
CONTACT US
Accept cookies & close this