FastPrepPlaying with Zeroes and Ones
Problems/Playing with Zeroes and Ones

Playing with Zeroes and Ones

Intuit logoIntuit● MediumINTERNOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an Intuit intern online assessment. The photos of the task give the ratio, the limits and the modulus. Our function keeps the task. It is about 100% the same as the reported question.

Count nonempty contiguous subarrays in which the number of zeroes to the number of ones is x:y. In other words, zeroCount*y must equal oneCount*x. Return the count modulo 1000000007. The ratio need not be reduced.

Function

ratioSubarrays(nums: int[], x: int, y: int) → int

Examples

Example 1

nums = [0,1,0,1]x = 1y = 1return = 4

The balanced subarrays start/end at (0,1),(1,2),(2,3),(0,3).

Example 2

nums = [0,0,1]x = 2y = 1return = 1

Only the whole array has two zeroes for one one.

Constraints

  • 1 <= nums.length <= 100000, each value 0 or 1, and 1 <= x,y <= 100000.
  • Use 64-bit prefix balances and counts before taking the modulus.

More Intuit Online Assessment questions

  • Employee Promotion OpportunitiesOA · Seen Oct 2026
  • Next Pascal Row CoefficientOA · Seen Oct 2026
  • Parse Router LogsOA · Seen Oct 2026
  • Longest Repeated Letter Block with Adjacent SwapsOA · Seen Oct 2026
  • Maximum Square-Free DivisorOA · Seen Oct 2026
  • Two Tribes from Taller-Person CountsOA · Seen Oct 2026
  • Shortest Path from an Encoded GraphOA · Seen Sep 2026
  • Oldest and Youngest EmployeesOA · Seen Sep 2026
  • Pressure-Isolation Shutdown OrderOA · Seen Sep 2026
  • Submask Sum QueriesOA · Seen Sep 2026

Similar questions at other companies

  • Subscription and Usage-Based Billing CalculatorStripe · OAStripe interview questions
  • Count Subarrays with a Perfect-Square ProductMicrosoft · OAMicrosoft interview questions
  • Shortest Digit Prefix for Target MultisetsVisa · OAVisa interview questions
  • Longest Balanced Substring After One SwapTekion · OATekion interview questions
  • Count Zero-Sum FragmentsTesla · OATesla interview questions
  • Count Special StringsAmazon · OA
  • Count Stable Server SubsegmentsScale AI · OAScale AI interview questions
  • Number of Unique Elements After Modifications 🍁Infosys · OAInfosys interview questions
  • Count Paired Subarrays Reaching a TargetZipRecruiter · OAZipRecruiter interview questions
  • Longest Substring with Even OccurrencesDeloitte · OADeloitte interview questions

Interview reports that mention this question

  • Intuit OA: What It Tests (2026)

Intuit interview experiences

  • Intuit Software Engineering Intern - Full Stack OA Format
All Intuit interview questionsSee Intuit hiring insights
Saved
class Solution {
    public int ratioSubarrays(int[] nums, int x, int y) {
        // Write your code here
    }
}
Checking account…