Optiver OA Question 1
Problem Statement
Complete the following functions:
- recordLog(logId, timestamp): Records a new log entry.
- Each log has a
logIdand atimestamp(in seconds). - Ignore logs with timestamps earlier than the latest recorded log.
- The same
logIdmay appear multiple times.
- Each log has a
getLogs(): Returns a comma-separated string of the latest m logIds from the last hour, in the order received.
- Format:
"logId1,logId2,…", where the last ID is the most recent.
getLogCount(): Returns the total number of logs received in the last hour from the most recent log’s timestamp (even if > ).
Input Format
The first line: integer m (max logs for getLogs()).
The second line: integer q (# of queries), followed by q lines:
RECORD logId timestampGET_LOGSCOUNT
Constraints
- 1 ≤ m ≤ 1000
- 1 ≤ q ≤ 10⁶
logId,timestampare integers
Output Format
For each GET_LOGS and COUNT query, print the result on its own line.
Sample Input
100
10
RECORD 1 0
RECORD 2 300
GET_LOGS
COUNT
RECORD 3 1200
RECORD 1 1800
GET_LOGS
COUNT
RECORD 4 3900
GET_LOGS
Sample Output
1,2
2
1,2,3,1
4
3,1,4
Optiver OA Question 2: Future Pricing
Problem Statement
Compute future stock prices given dividends. If today’s price is S, and a dividend A is paid at day D:
- For days 0 to D−1: price =
S. - From day D onwards: price =
S − A. - Multiple dividends subtract cumulatively.
Example
S = 1000, dividends: (1) A₁=100 at day 10, (2) A₂=50 at day 100
Prices:
- Day 0–9: 1000
- Day 10–99: 900
- Day 100+: 850
Constraints
- 1 ≤ number of dividends ≤ 1000
- 1 ≤ q ≤ 10⁶
- All amounts and days are integers
參考資料
Optiver OA | 一亩三分地
Optiver Online Assessment
If you need interview or OA support services, please contact us .