I had my first DE Shaw India interview for SDE position (2022 new grads). The problem statement goes here:
Given a time series of a particular stock price (eg. DE Shaw) and a window of size k, you need to construct another time series for the following operations:
a) Compute mode of each window (if mode does not exists, output -1 corresponding to that window):
Input: stock_prices = [10, 10, 15, 15, 6, 6, 7, 15, 20, 6, 8, 10, 10, 15], k=3
Output: [10, 15, 15, 6, 6, -1, -1, -1, -1, -1, 10, 10]b) Compute whether the same k size window has occured before or not in the past:
Input: stock_prices = [10, 10, 15, 15, 6, 6, 7, 15, 20, 6, 8, 10, 10, 15], k=3
Output: [False, False, False, False, False, False, False, False, False, False, False, True]I was not able to do both the parts with expected O(n) time complexity. Please help me with the optimal approach and implementation. Thank you.