Amazon Interview SDE1 | DSA
Difficulty: MEDIUMCategory: InterviewExperienceFrequency: 1Asked On 2024-07-28Added By Anonymous
Source: Link
Company: Amazon
Role: SDE1
Interview Stage: Phone Screen
Location: unknown
Year: unknown
Original Post Content:
Question :- Given an array of positive integers including 0. At each operation, you can choose a non empty subarray and decrement all element in it by 1. Find minimum number of operation required to make all elements of array equal to 0.
for eg : arr = [3,1,4,2]
* subarray[0:3] -> [2,0,3,1]
* subarray[2:3] -> [2,0,2,0]
* subarray[0:0] (2 times) -> [0,0,2,0]
* subarray[2:2] (2 times) -> [0,0,0,0]
total => 1+1+2+2 = 6
so. ans = 6
Constraint : size of array can be 1e5.
Expected to do it in O(NlogN) or better?