JPMorgan & Chase | OA | SWE 24 Intern - US
Anonymous User
280
  1. Find all intervals of length k where the stock price is strictly increasing. Given array stockPrices of ints [1, IntMax).

This is essentially find all monotonically increasing subarrays of length k or greater. Can be done in O(n) time O(1) space if you iterate while i<j and stock[i] < stock[j]. Total result of increasing arrays on [i, j] is: max(0, j - i - k + 1), and continue iteration at j.

  1. Given a list of strings and maxReplacements. Each string in expressions consists of only < and >, determine if each expression is balanced. If it's not, any > in expression[i] may be replaced with <> at most maxReplacements[i] times.

It is feasible to run LC's balanced parantheses on each expression to check for balance. The hard part is determining if parts expression[i] can be swapped, and then check for balance. I could use any tips for determining swaps efficiently. I ran out of time while testing greedy swapping.

Return an array of length len(expression) where arr[i] is 0 if expression[i] is balanced/can be balanced with less than maxReplacements[i], or 1 if it is not possible to balance.

Comments (0)