Given an array of integers A, with each move you can select an arbitrary range and increment all the numbers in that range by 1. Return the number of moves needed to transform an array starting with all zeros into A.
Examples
01 · Example 1
A = [2, 1, 3] return = 4
To transform [0, 0, 0] into [2, 1, 3] requires 4 moves, as follows:
[0, 0, 0] -> [1, 1, 1] -> [2, 1, 1] -> [2, 1, 2] -> [2, 1, 3]
Constraints
🍅🍅More Google problems
- Consolidate On-Call RotationsOA · Seen Jun 2026
- Detonate Bombs with Chain ReactionsONSITE INTERVIEW · Seen May 2026
- Evaluate a Nested Math ExpressionONSITE INTERVIEW · Seen May 2026
- Tic-Tac-Toe Game StatusPHONE SCREEN · Seen May 2026
- Longest Dictionary TokenizationPHONE SCREEN · Seen May 2026
- Minimum Cars for Rental RequestsONSITE INTERVIEW · Seen Apr 2026
- Shortest Path with Mandatory WaypointONSITE INTERVIEW · Seen Apr 2026
- Merge Intervals with NamesONSITE INTERVIEW · Seen Jun 2025
public int minMoves(int[] A) {
// write your code here
}
A[2, 1, 3]
expected4
sign in to submit