Dsa
Binary Search
Medium
Paid Subscription Search
You have a list of subscription prices sorted in ascending order. Given a target subscription price, write a program that determines the index of the price if it exists, or the index where it can be inserted to maintain the order if it does not exist.
Input Format:
- The first line contains a space-separated list of integers (subscription prices).
- The second line contains a single integer (target price).
Output Format:
- A single integer representing the index of the target price or the position to insert it.
Example:
Input:
10 20 30 40 50
25
Output:
2
Key concepts
binary_searchpricingarrays
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