Dsa
Binary Search
Medium
Stock Price Analyzer
You are given historical stock prices with timestamps. Your task is to design a program to find the index of a specific stock price within a sorted array of prices. If the price is not found, return -1.
Input format:
- The first line contains an integer N, the number of stock prices.
- The second line contains N integers of stock prices in ascending order.
- The third line contains an integer P, the target stock price.
Output format:
- Output the index of the stock price if found, or -1 if not found.
Example:
Input:
5
150 200 300 400 500
300
Output:
2
Key concepts
binary_searcharray
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