Five Consecutive Ones
Give me array with 5 consecutive ones
Five Consecutive Ones
Problem Statement
Given a 64-bit binary value, generate or validate that the value contains exactly 5 ones and they are all consecutive (adjacent).
Constraints
- Value size: 64 bits
- Total number of 1s: exactly 5
- Pattern: 5 consecutive 1s starting at a random position
Examples
Example 1:
Binary: 0000...00011111 (last 5 bits are 1s)
Explanation: 5 consecutive 1s at positions [0:4]Example 2:
Binary: 0000...0111110000000000
Explanation: 5 consecutive 1s at positions [10:14]Example 3:
Binary: 11111000...000
Explanation: 5 consecutive 1s at positions [59:63]Example 4:
Binary: 0000...0001000001000 (1s not consecutive)
Invalid
Explanation: Total count is correct (5 ones) but they are not consecutiveExample 5:
Binary: 0000...011111100 (6 consecutive 1s)
Invalid
Explanation: Pattern has 6 consecutive 1s instead of 5Loading the interactive workspace...