Dsa
Two Pointers
Easy
Popular Movie Ratings
You are given a list of movie ratings and a threshold. Your task is to find the number of pairs of movies (i, j) such that the combined rating of the movies is greater than the specified threshold. The ratings list is sorted in increasing order. Pairs (i, j) should be counted where i < j.
Input format:
- The first line contains an integer n (1 ≤ n ≤ 1000), the number of ratings.
- The second line contains n space-separated integers representing the movie ratings.
- The third line contains an integer threshold.
Output format:
- Output a single integer representing the number of valid pairs.
Example:
Input:
5
1 2 3 4 5
6
Output:
4
(The valid pairs are (2, 4), (1, 5), (3, 4), (2, 5))
Key concepts
two_pointersarrayssorting
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