Company: DE Shaw

Difficulty: medium

Problem Statement

Stock Trade Generator You are given the price of a stock on `n` consecutive days. Produce the transactions generated by the following rule: buy at the first day of every maximal strictly increasing run and sell at the last day of that run. A transaction is printed as `buy_price buy_day sell_price sell_day`. Days are numbered from `0` to `n - 1`. Do not print a transaction when no profit is possible. Input The first line contains an integer `n`. The second line contains `n` non-negative integer prices. Output For each generated transaction, print one line containing `buy_price buy_day sell_price sell_day`, in chronological order. Print nothing if there are no profitable transactions. Constraints - `1 <= n <= 200000` - `0 <= price[i] <= 10^9` Example Input: `6` `7 1 5 3 6 4` Output: `1 1 5 2` `3 3 6 4` Notes - A run must be strictly increasing, so equal consecutive prices do not belong to the same transaction. - This output is the line-based representation of the requested ge

More DE Shaw OA questionsInterview experiences