Code and logic explanation of binary gap solution with dynamic max value allowed
Find the longest sequence of zeros in a binary number based on an Integer. For example: the binary of 45 is 00101101 the gap is 1.
- Has to be an integer.
- Has to be greater than 0 but less than the specific value.
- If there's not gap options, return zero.
- Find the first 1
- Find the second (next) 1
- Count zeros between the indexes; keep it on a global variable
- If the second index is minor than the array size, remove the already counted values
- Repeat steps 1 to 4 until there's not more gap posibilities.
- Finally, return the max gap found.