Searching for all intervals meeting a specific condition

Published: 11/01/2019
Searching for all intervals meeting a specific condition
Source: STACKOVERFLOW.COM

How can I search for all intervals in an array of 0 s, 1 s and 2 s that contain the same amount of 1 s and 2 s? Example: [0,1,1,2,2] Would return 3 intervals [0,1,1,2,2] [1,1,2,2] [1,2] I don't want to brute force it. Is there any very simple algorithm which can be used for such instances? I'd need something flexible.

Read more
Related news
Comment
FACEBOOK