Problem · Array
Array Transformation Steps (Early Career)
Learn this problemProblem statement
You are given an array, and the task is to determine how many steps it takes to transform an array of all zeros into the given array. In each step, you can add a contiguous sequence of 1's to the array.
Function
transformationSteps(array: int[]) → intExamples
Example 1
array = [2, 1, 0, 2]return = 4The transformation can be done in 4 steps as follows:
- 0000 -> 1100: Add a contiguous sequence of 1's covering the first two elements.
- 1100 -> 2100: Add a contiguous sequence of 1's covering the first element.
- 2100 -> 2101: Add a contiguous sequence of 1's covering the fourth element.
- 2101 -> 2102: Add a contiguous sequence of 1's covering the fourth element again.
Constraints
🐻❄️🐻❄️More Google problems
- Deduplicate Logs: Keep FirstONSITE INTERVIEW · Seen Jul 2026
- Deduplicate Logs: Keep LatestONSITE INTERVIEW · Seen Jul 2026
- Find a Template Across Binary-Tree LeavesONSITE INTERVIEW · Seen Jul 2026
- Maximum Programmer-Problem MatchingONSITE INTERVIEW · Seen Jul 2026
- Minimum Direction ViolationsONSITE INTERVIEW · Seen Jul 2026
- Stream Latest Log VersionsONSITE INTERVIEW · Seen Jul 2026
- Stream Unique Logs in Timestamp OrderONSITE INTERVIEW · Seen Jul 2026
- Top-K IP Addresses from File RecordsONSITE INTERVIEW · Seen Jul 2026