← Back to companies
[ OK ] Loaded —
[ INFO ]
$ cd
$ ls -lt
01
02
03
04
05
$ ls -lt
01
02
03
04
05
user@intervues:~/$
You are given an array of integers representing the daily closing prices of a stock, and a list of queries. Each query is a single integer representing a day index (1-based). For each query, you must find the nearest previous day (smaller index) whose price was strictly lower than the price on the queried day. If there is a tie in distance (i.e., the same distance to a lower price exists both before and after the queried day), return the earlier day. If no such day exists, return -1. The problem is essentially a nearest smaller element query that must be answered efficiently for multiple queries.