Posts

Search

Postmen

QUESTION DESCRIPTION

The kamali is on vacation in the beautiful country of Chefville. The island is a narrow strip of land running from north to south. A single road from north to south connects all the villages in the country. There, he observed, the postal services works in a very curious way.

There is a postman for every village. In the morning, say postman A, starts traveling to the North, disbursing all the mails on the way. When he meets another postman coming from the opposite direction on the way, say B, A hands over all the mails to B which are to be delivered to addresses that lie in the North and vice versa for B.

Then both turn back and start traveling in the opposite directions. So, now A travels to the South and when he meets another postman on the way, the same thing happens again.

This keep on till the duty hours of the day finishes and they don't loose any time in the swapping and turning back. All postmen travel at the same speed of 1 m/s always and they arbitrarily choose their direction to start with in the morning. Now you Find the given numbers in sequential file allocation or not

TEST CASE 1

INPUT

4
1 4 3 2
5
2 3 4 5 1
1
1
0
OUTPUT
sequential
not sequential
sequential

TEST CASE 2

INPUT

3
1 4 3 
4
2 3 4 5  
1
1
0
OUTPUT
not sequential
not sequential
sequential

Code :


#include <iostream>
using namespace std;
int main() {
 int n[15],arr[15][10],count,inc;
    for(int i = 0;i>-1;i++){ 
       cin>>n[i];
       if(n[i]==0)
         break;
       for(int j = 0;j<n[i];j++){
          cin>>arr[i][j];
       }
      count=1;
      inc=1;
      for(int j=n[i]-1;j>0;j--){
            if(arr[i][j] == arr[i][0]+inc){
                 count++;
            }
            else{
               break;
            }
         inc++;
      }
      if(count==n[i]){
        cout<<"sequential"<<endl;
      }
      else{
        cout<<"not sequential"<<endl;
      }
    }
 return 0;
}