Binary Prefix Divisible By 5

EasyMathmath

Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.

Practice this as a mock interviewFree to start, no account needed

Problem

You are given an array nums of bits (each 0 or 1). For every index i, let x_i be the integer whose binary representation is nums[0..i], with nums[0] as the most significant bit. Return a boolean array answer of the same length where answer[i] is true exactly when x_i is divisible by 5. The prefixes grow to thousands of bits, so avoid building the full numbers.

Examples

Input: nums = [0,1,1]
Output: [true,false,false]
The prefixes are 0, 1 and 3; only 0 is a multiple of 5.
Input: nums = [1,1,1]
Output: [false,false,false]
The prefixes are 1, 3 and 7.
Input: nums = [1,0,1,0]
Output: [false,false,true,true]
The prefixes are 1, 2, 5 and 10.

Constraints

  • 1 <= nums.length <= 10^5
  • nums[i] is either 0 or 1

What the interviewer grades

A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.

More math problems