FunctionRacerProblemsRace

Contiguous Array

MediumHash mapsPython, JavaScript, TypeScript, Java, C++

nums holds only 0s and 1s. Find the longest contiguous stretch that has the same number of 0s and 1s, and return its length (0 if there is none).

Example 1

nums [0,1,0]
returns 2

[0, 1] or [1, 0], length 2.

Example 2

nums [1,1,1]
returns 0

No 0s, so 0.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Hash maps problems