bits made of 0 and 1 and a non-negative integer cap. Cross out some characters (the rest keep their order) so that the remaining string, read as a binary number, is at most cap.
Leading zeros are allowed, and an empty string counts as 0. Return the greatest possible length of the remaining string.bits="0110101", cap=6 → 5
For example, "00101" is 5, which does not exceed 6. Six characters are impossible: they would keep at least three ones, and the number would exceed 6.
bits="111", cap=2 → 1
The possible subsequences are "1", "11" and "111", that is 1, 3 and 7. Only "1" fits.
bits="1000", cap=1 → 3
Take the three zeros, which make 0. Keeping the leading one would give at least 4.
bits contains only 0 and 1bits="0110101", cap=6
5
Run checks the first 3 tests in your browser. Submit checks all 101 tests on the server, hidden ones included.