Long ATM Queue

QUESTION

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).\n\nSwapy 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?\n\nInput format:\n\nThe first line of input contains one positive integer N. The second line contains N space-separated integers \nH[i] denoting the height of i-th person. Each group has group members standing in increasing order of their height.\n\nOutput format:\n\nPrint the minimum number of groups that are at least present in the queue?\n\nConstraints:\n1N1,000,000\n1H[i]1,000,000.

“TESTCASE_1”: “4\n1 2 3 4\n###—###SEPERATOR—###—\n1”, “TESTCASE_2”: “7\n1 3 2 10 9 4 1\n###—###SEPERATOR—###—\n5”, “TESTCASE_3”: “2\n186144 654841\n###—###SEPERATOR—###—\n1”, “TESTCASE_4”: “10\n1 11 3 2 10 9 4 1 99 100\n###—###SEPERATOR—###—\n6”, “TESTCASE_5”: “0\n###—###SEPERATOR—###—\n0

ANSWER

#include <stdio.h>

int main()
{
    int n,i;
    scanf("%d", &n);
    int a[n];
    for(i = 0; i < n; i++)
        scanf("%d", &a[i]);
    int cnt = 1;
    for(i = 1; i < n; i++)
    {
        if(a[i]>=a[i-1])
            continue;
        else
            cnt++;
    }
    printf("%d\n",cnt);
    return 0;
}
Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.