Dsa
Binary Search
Medium
Stock Price Target Search
A financial analyst wants to find the earliest day when a stock price meets or exceeds a certain target. Given a list of stock prices for n days, find the index of the earliest day that meets or exceeds the target stock price. If not found, return -1.
Input format:
- The first line contains an integer n, the number of days.
- The second line contains n sorted integers (the stock prices).
- The third line contains the target price p.
Output format:
- Print the index of the earliest day that meets or exceeds p or -1 if not found.
Example:
Input:
5
10 20 30 40 50
30
Output:
2
Key concepts
binary_searcharraysfinancial_analysis
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