You are given a binary array nums (containing only 0s and 1s). Your task is to check each binary prefix of this array to see if it represents a number divisible by 5.
More specifically, for each index i, we define x_i as the decimal number whose binary representation is formed by the subarray nums[0..i] (from most-significant-bit to least-significant-bit).
Example: If nums = [1,0,1], then:
• x_0 = 1 (binary "1")
• x_1 = 2 (binary "10")
• x_2 = 5 (binary "101")
Return an array of booleans answer where answer[i] is true if x_i is divisible by 5, and false otherwise.
Challenge: The binary numbers can become extremely large, so you'll need to use modular arithmetic to solve this efficiently!
Input & Output
Constraints
- 1 ≤ nums.length ≤ 105
- nums[i] is either 0 or 1
- The binary numbers can become extremely large (up to 105 bits)