Just took IMC OA. We are given 120 minutes for 2 problems.
You start at (x, y) and would like to reach (a, b). In one step, you can go from (x, y) to:
(x + y, y)(x, x + y)(x + c, y + c)In additional the the rules above, there are also obstacles that you must avoid. Obstacles exist on any cell (i, j) where i+j is a perfect square.
You will be given a, b, x, y, c. Determine whether a path exists.
Constraints
0 <= x, y, a, b <= 10001 <= c <= 15(a, b) and/or (x, y) to be blocked.My Solution
bad array of size 2001 to mark the perfect square.There are two streets denoted as MAIN STREET (0), and FIRST STREET (1). These streets are 1-way and thus you need to help them determine the time (in second) in which the cars will be pass through the intersection! They follow the rules:
You are given an array Arrival donoting the arrival time for car i, and an array Street denoting which street the car is on, with 0 being MAIN STREET and 1 being FIRST STREET.
Return an array of size Arrival.length such that ans[i] is the time on which car i passes through the intersection.
Constraints
1 <= Arrival.length <= 1000001 <= Arrival[i] <= 1000000000Arrival is sorted in non-decreasing order (2 cars can arrive together on the same street).Street[i] is either 0 or 1My Solution
idx, and set time to the current arrival time of that car.+1 to time at the end.