Ctrl K

Even and Odd Ladders

Hard
You are given two arrays first and second that contain only 0s and 1s. Replace every 0 with a positive **even** number and every 1 with a positive **odd** number. After the replacement both arrays must be strictly increasing, and all numbers across both arrays must be distinct: no number may be used twice, whether in the same array or in different ones. Return the smallest possible value of the largest number that appears in the arrays after the replacement.
Example 1
first=[1, 1], second=[0] → 3

For instance first = [1, 3] and second = [2]: all numbers are distinct, odd ones replace the 1s and the even one replaces the 0. Nothing above 3 is needed.

Example 2
first=[0, 0], second=[0, 0] → 8

Four distinct even numbers are needed; the smallest are 2, 4, 6 and 8, e.g. first = [2, 6] and second = [4, 8].

Example 3
first=[], second=[0, 1, 1] → 5

The first array is empty, and the second becomes [2, 3, 5].

Constraints
  • 0 ≤ len(first) ≤ 1000
  • 1 ≤ len(second) ≤ 1000
  • first and second contain only 0 and 1
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsWater Between Walls HardBiggest Solid Panel Block HardProfit From Two Trades HardEvery Way to Space the Words HardCrossing the Cave Hard
loading Python…
Input
first=[1, 1], second=[0]
Expected
3

Run checks the first 3 tests in your browser. Submit checks all 120 tests on the server, hidden ones included.