Long ATM Queue
Practice
3.4 (200 votes)
Approved
Data structures
Easy
Greedy algorithms
One Dimensional
Approved
Problem
86% Success 43985 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code

Due to the demonetization move, there is a long queue of people in front of ATMs. Due to withdrawal limit per person per day, people come in groups to withdraw money. Groups come one by one and line up behind the already present queue. The groups have a strange way of arranging themselves. In a particular group, the group members arrange themselves in increasing order of their height(not necessarily strictly increasing).

Swapy observes a long queue standing in front of the ATM near his house. Being a curious kid, he wants to count the total number of groups present in the queue waiting to withdraw money. Since groups are standing behind each other, one cannot differentiate between different groups and the exact count cannot be given. Can you tell him the minimum number of groups that can be observed in the queue?

Input format:

The first line of input contains one positive integer N. The second line contains N space-separated integers \(H[i]\) denoting the height of i-th person. Each group has group members standing in increasing order of their height.

Output format:

Print the minimum number of groups that are at least present in the queue?

Constraints:

  • \(1 ≤ N ≤ 1,000,000\)
  • \(1 ≤ H[ i ] ≤ 1,000,000\)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
30 votes
Tags:
ArraysData StructuresEasyOne-dimensional
Points:20
28 votes
Tags:
ArraysData StructuresEasyOne-dimensionalPrefix sumprefix-sum
Points:20
58 votes
Tags:
ArraysData StructuresEasyOne-dimensionalPartial SumPrefix sumSegment Trees