Zero Array Transformation I
Updated
Problem statement
You are given an integer array nums and a list of inclusive index ranges queries. Each query has the form [left, right].
Process the queries in order. For each query, you may choose any subset of indices between left and right, inclusive, and decrement the value at every chosen index by 1. You may choose a different subset for every query.
Return true if all values in nums can be made exactly 0 after all queries are processed. Otherwise, return false.
Function
isZeroArray(nums: int[], queries: int[][]) → booleanExamples
Example 1
nums = [1,0,1]queries = [[0,2]]return = trueThe only query covers the whole array. Decrement indices 0 and 2; index 1 is already zero.
Example 2
nums = [4,3,2,1]queries = [[1,3],[0,2]]return = falseIndex 0 is covered only once, so its value can decrease from 4 to at best 3. Reaching an all-zero array is impossible.
Constraints
1 <= nums.length <= 10^5.0 <= nums[i] <= 10^5.1 <= queries.length <= 10^5.queries[i].length == 2.0 <= queries[i][0] <= queries[i][1] < nums.length.
More Google Onsite Interview questions
- Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Distinct Subset SumsONSITE INTERVIEW · Seen Nov 2026
- Playlist With No Same Artist in a RowONSITE INTERVIEW · Seen Nov 2026
- Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Delete Nodes and Return Forest RootsONSITE INTERVIEW · Seen Nov 2026
- Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- First and Last Target Position in a Mountain ArrayONSITE INTERVIEW · Seen Nov 2026
- Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- 0/1 Knapsack with Weight and Volume LimitsONSITE INTERVIEW · Seen Nov 2026
- Batched Subsequence Word MatchesONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Peak Chat Load Across AgentsCresta · PHONE SCREENCresta interview questions
- Earliest Time to Schedule a MeetingMathWorks · OAMathWorks interview questions
- Earliest Meeting Start on a 24-Hour ClockIMC Trading · OAIMC Trading interview questions
- Majority Labels over Audio IntervalsNooks · PHONE SCREEN
- Earliest Time to Schedule a MeetingMicrosoft · OAMicrosoft interview questions
- Earliest Common Meeting StartVisa · OAVisa interview questions
- Smallest Most-Lit Street PositionHudson River Trading · OAHudson River Trading interview questions
- Most Visited Sprint MarkerChubb · OAChubb interview questions
- Earliest Common Meeting TimeZipRecruiter · OAZipRecruiter interview questions
- File Download Coverage PercentagePersona · OAPersona interview questions