Long ATM Queue

Due to the demonetization move, there is a long queue of people in front of ATMs. Due to the 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?

Example:

Input:  n = 4, a = [1,2,3,4]
Output: 1

Approach

C++

#include <bits/stdc++.h>
using namespace std;

int longAtmQueue(int nint a[])
{
    int res = 0;
    int i = 0;
    while (i < n - 1)
    {
        if (a[i] > a[i + 1])
            res++;
        i++;
    }
    return res + 1;
}
int main()
{
    int n = 4;

    int a[n] = {1234};

    cout << longAtmQueue(n, a) << "\n";

    return 0;
}


No comments:

Post a Comment