Dsa
Binary Search
Warm-up
Movie Rating Finder
You are given a sorted list of movie ratings (from 1 to 10). Your task is to find the position of a specific rating using binary search. If the rating does not exist in the list, return -1.
Input format:
- The first line contains an integer n (1 ≤ n ≤ 100) representing the number of ratings.
- The second line contains n space-separated integers representing the movie ratings.
- The third line contains an integer representing the rating you want to find.
Output format:
- Print a single integer: the index of the rating, or -1 if it is not found.
Example:
Input:
5
8 8 9 10 10
9
Output:
2
Key concepts
binary_searcharraysearch
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now