FastPrepDo the Range Decrements Zero the Array
Problems/Do the Range Decrements Zero the Array

Do the Range Decrements Zero the Array

Adobe logoAdobe● MediumFULLTIMEPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: This problem decides whether a list of ranges, each lowering every number inside it by one, brings a positive array exactly to all zeros. An Adobe MTS-2 report describes such a check as the one coding question of its first round, in a few informal lines, alongside questions on Amazon S3 and machine learning; it gives no limits or examples.

Our choices: a range lowers every number in it (not a chosen few, which is another common reading), ranges include both ends, a number lowered too often fails, at most 2000 numbers and 2000 ranges with values up to 2000, and new examples.

The judged task matches the report at about 75%.

You have an array nums of positive integers and a list of ranges queries. Applying a range [l, r] lowers every number at indexes l through r (both included) by exactly 1.

After applying every range once, is the array all zeros? Return true if every number ends at exactly 0, and false otherwise (a number lowered too many times ends below 0, which also counts as false).

Function

canReachZero(nums: int[], queries: int[][]) → boolean

Examples

Example 1

nums = [1,2,1]queries = [[0,1],[1,2]]return = true

The first query lowers indexes 0 and 1, the second lowers 1 and 2. Index 1 is lowered twice and the others once, matching [1, 2, 1] exactly: true.

Example 2

nums = [2,1]queries = [[0,1]]return = false

One query lowers both numbers once, leaving [1, 0]: false.

Example 3

nums = [1,1]queries = [[0,1],[1,1]]return = false

Index 1 is lowered twice and ends at -1, not 0: false.

Constraints

  • 1 <= nums.length <= 2000 and 1 <= nums[i] <= 2000
  • 1 <= queries.length <= 2000, each queries[j] = [l, r] with 0 <= l <= r < nums.length

More Adobe problems

  • Evaluate a Parenthesized Integer ExpressionPHONE SCREEN · Seen Oct 2026
  • All Elements of Two BSTs in OrderPHONE SCREEN · Seen Aug 2026
  • Rotate an Array In PlaceOA · PHONE SCREEN · Seen Aug 2026
All Adobe interview questionsSee Adobe hiring insights
Saved
public boolean canReachZero(int[] nums, int[][] queries) {
    // Write your code here.
}
Checking account…