Jaguar Land Rover | OA | On-Campus | 2020
Anonymous User
2489

Q1. Given an array of non-negative integers, destruction of an element ( A[i] ) on a particular day will occur if ( A[i-1]< A[i] ) is satisfied. You have to return the number of days this process will continue.

Constraints :
**1<= n <= 10^5 ** where n is the size of array

Example 1:
Input = [6, 5 , 8, 4, 7 ,10, 9]
Output = 2

Explanation:
Day 1, A[2], A[4], A[5} will get destroyed because A[1] < A[2] , A[3] < A[4] and A[4] < A[5] is satisfied .
So, remaining array = [6, 5, 4 ,9]

Day 2, A[3] will get destroyed because A[2] < A[3].
So, remaining array = [6, 5, 4]

Now no more destruction is possible. So answer is 2 days

Can anyone explain, how to do it without getting TLE ?

Comments (4)