This online assessment contained two coding problems:
-
Maximum requests in a time window
You are given a non-decreasing integer array
requestTimes
, where
requestTimes[i]
is the second at which the
i
-th request arrives, and an integer
windowSize
. Return the maximum number of requests that occur within any inclusive time interval of length
windowSize
seconds. In other words, find the largest number of elements that can fit inside some interval
[t, t + windowSize]
.
-
Simultaneous swaps in a binary string
You are given a binary string
s
consisting only of
'0'
and
'1'
. Every second, all adjacent occurrences of
'01'
are swapped simultaneously to become
'10'
. Repeat this process until the string no longer contains
'01'
. Return the number of seconds required.
Example: s = "001011" transforms as follows:
001011 -> 010101 -> 101010 -> 110100 -> 111000
So the answer is 4 seconds.