To solve this problem, you'll have to open it on the computer

Street Parade

Stacks
medium
Score: 20

For sure, the love mobiles will roll again on this summer’s street parade. Each year, the organisers decide on a fixed order for the decorated trucks. Experience taught them to keep free a side street to be able to bring the trucks into order.

The side street is so narrow that no two cars can pass each other. Thus, the love mobile that enters the side street last must necessarily leave the side street first. Because the trucks and the ravers move up closely, a truck cannot drive back and re-enter the side street or the approach street.

You are given the array order in which the love mobiles arrive. Return 1 if love mobiles can be re-arranged to sorted order, else return 0.

Input Format :-

First Parameter - number n

Second Parameter - array order of size n

Output :-

Return a number

Example 1 :-

Input :- 
    5
    5 1 2 4 3
Output :-
    1
 Explanation :- 

img img img img img img

Constraints :-

  • n == order.length
  • 1 <= n <= 105
  • 1 <= order[i] <= n
  • Expected Time Complexity : O(n)
  • Expected Space Complexity : O(n)
Submit code to see the your result here