A ground station keeps one long recorded tape of bits for a satellite -- a string of characters 0 and 1. Mission control numbers every orbital pass starting at 1, and writes each pass number in plain binary with no leading zero. Before archiving the tape, engineers want to confirm it already contains, as one contiguous run of bits somewhere on the tape, the binary form of every pass number from 1 through n. Determine whether the tape provides that coverage.
s, a string made only of the characters 0 and 1.n.Print true if the binary representation (no leading zeros) of every integer from 1 to n appears somewhere in s as a contiguous substring, and false otherwise.
s is 0 or 1.Example 1
Input
11010 3
Expected
true
Explanation
binary(1)="1" appears in "11010" (e.g. its first character); binary(2)="10" appears (characters at positions 2-3, 0-indexed); binary(3)="11" appears (the first two characters). All three pass numbers are covered, so the tape covers 1 through 3.
Example 2
Input
11010 5
Expected
false
Explanation
Pass numbers 1, 2 and 3 are covered exactly as in Example 1, but binary(4)="100" never occurs as a contiguous substring of "11010" (its length-3 substrings are "110", "101", and "010"), so coverage already fails at 4 and the tape does not cover 1 through 5.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →