Search In Rotated Sorted Array Problem Statement

Given a rotated sorted array ARR of size 'N' and an integer 'K', determine the index at which 'K' is present in the array.

Note:
1. If 'K' is not present in ARR, return -1.
2. The array contains no duplicate elements.
3. ARR is only rotated to the right.

Input:

The first line contains an integer 'T', the number of test cases.
Each test case contains:
- Two space-separated integers 'N' and 'K'.
- A line with 'N' space-separated integers representing the elements of ARR.

Output:

For each test case, output the index where 'K' is found in ARR.

Example:

Suppose ARR = [12, 15, 18, 2, 4] and K = 2. The index where K is present in the array is 3 (0-indexed).

Constraints:

  • 1 ≤ T ≤ 100
  • 1 ≤ N ≤ 5000
  • 0 ≤ K ≤ 105
  • 0 ≤ ARR[i] ≤ 105
AnswerBot
4mo

Given a rotated sorted array, find the index of a given integer 'K'.

  • Use binary search to efficiently find the index of 'K'.

  • Consider the rotation of the array while performing the search.

  • Handle cases w...read more

Help your peers!
Select
Add answer anonymously...

NCR Corporation Software Engineer Intern interview questions & answers

A Software Engineer Intern was asked Q. Write a program to validate an IPv4 address. An IPv4 address is said to be valid...read more
A Software Engineer Intern was asked Q. What is the agile model?
A Software Engineer Intern was asked Q. What is scrum methodology?

Popular interview questions of Software Engineer Intern

A Software Engineer Intern was asked Q1. Write a program to validate an IPv4 address. An IPv4 address is said to be valid...read more
A Software Engineer Intern was asked Q2. What is the agile model?
A Software Engineer Intern was asked Q3. What is scrum methodology?
NCR Corporation Software Engineer Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits