Playing with Zeroes and Ones
Updated
Problem statement
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) → intExamples
Example 1
nums = [0,1,0,1]x = 1y = 1return = 4The balanced subarrays start/end at (0,1),(1,2),(2,3),(0,3).
Example 2
nums = [0,0,1]x = 2y = 1return = 1Only 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