Solved LeetCode program · 350 of 1,000
#0474 · Ones and Zeroes
Original English source
Keep a shared words holding "10", "0001", "111001", "1", and "0". Keep a shared zeros as an empty list of whole numbers. Keep a shared ones as an empty list of whole numbers. Keep a shared current as empty text. Keep a shared zcount of 0. Keep a shared ocount of 0.
To measure from spot (a whole number) with limit (a whole number). If spot is more than limit, return. If character spot of current is "0", add 1 to zcount. If character spot of current is "1", add 1 to ocount. Measure from spot plus 1 with limit.
Keep a shared last of 0. The endword is the last position of words. Set last to endword.
For every index from 0 to last.
Set current to item index of words. Set zcount to 0. Set ocount to 0. The limit is the last position of current. Measure from 0 with limit. Place zcount into zeros. Place ocount into ones.
Keep a shared best of 0. Keep a shared maxzeros of 5. Keep a shared maxones of 3. Keep a shared usedzeros of 0. Keep a shared usedones of 0.
To walk from spot (a whole number) with taken (a whole number). If spot is more than last and taken is more than best, set best to taken. If spot is more than last, return. Walk from spot plus 1 with taken. The zcost is item spot of zeros. The ocost is item spot of ones.
If usedzeros plus zcost is at most maxzeros and usedones plus ocost is at most maxones.
Add zcost to usedzeros. Add ocost to usedones. Walk from spot plus 1 with taken plus 1. Subtract zcost from usedzeros. Subtract ocost from usedones.
Walk from 0 with 0. Show best.
Expected stdout
4