HACKEREARTH seating arrangement problem

I tried this question from morning but not able to get its generalised solution.
please help,
problem link:-
https://www.hackerearth.com/practice/basic-programming/input-output/basics-of-input-output/practice-problems/algorithm/seating-arrangement-1/

Thanks

A typical Python Solutoin

1 Like

In c++ how to take range ?

Just run a for loop dude. If you are not aware of Python, just try to understand.
And btw, I have used a dictionary in Python, it will work even with arrays. U just need to understand the logic. I wrote it in Python, because it has better readability ( atleast for me).

Ok thanks,
Actually i code in c++

why would you use 2 loops for assigning pair? I guess one would be enough.

It’s a nice implementation problem
the following is my code in cpp

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

// https://www.hackerearth.com/practice/basic-programming/input-output/basics-of-input-output/practice-problems/algorithm/seating-arrangement-1/

map<int , pair<int,string> > m1;

void precal(){

map<int,string> m11;
// WS, MS or AS.

m11[0]="WS";
m11[1]="MS";
m11[2]="AS";
m11[3]="AS";
m11[4]="MS";
m11[5]="WS";

///

for(int i=0; i<=16;i+=2){
    
    ///start
    int count=0;
    int dif=11;
    
    for(int j= 6*i + 1 ; count<6;j++){
        
        m1[j]     =   { dif+j , m11[count] };
        m1[dif+j] =   { j ,     m11[count] };
        
        dif-=2;
        
        count++;
    }
     }

   }


 void sol(){
int n1;
cin>>n1;
cout<<m1[n1].first<<" "<<m1[n1].second<<endl;
 }

  int main(void)
   {   
    precal();
    int t;
     cin>>t;
    while(t--){
    sol();
   }
 }

Yes, I guess. But it doesn’t matter whether you are using two for loops or one, if they aren’t Nested.
Btw, I appreciate your observation.