1743B - Permutation Value - CodeForces Solution


greedy

Please click on ads to support us..

Python Code:

for _ in range(int(input())):
    n=int(input())
    
    ans=[1]
    
    for j in range(3,n+1):
        ans.append(j)
        
    ans.append(2)
    
    for i in range(n):
        if(i<n-1):
            print(ans[i],end=' ')
        else:
            print(ans[i])

C++ Code:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
    ll t;
    cin>>t;
    while(t--){
      ll n;
      cin>>n;
      ll a[n];
      ll i=0;
      ll j=1;
      while(i<n/2){
          a[i]=j;
          j++;
          a[n-1-i]=j;
          j++;
          i++;
      }
      if(n%2==1){
          a[n/2]=n;
      }
      for(ll k=0;k<n;k++){
          cout<<a[k]<<" ";
      }
      cout<<endl;
    }
	return 0;
}


Comments

Submit
0 Comments
More Questions

A. Movement
Numbers in a matrix
Sequences
Split houses
Divisible
Three primes
Coprimes
Cost of balloons
One String No Trouble
Help Jarvis!
Lift queries
Goki and his breakup
Ali and Helping innocent people
Book of Potion making
Duration
Birthday Party
e-maze-in
Bricks Game
Char Sum
Two Strings
Anagrams
Prime Number
Lexical Sorting Reloaded
1514A - Perfectly Imperfect Array
580A- Kefa and First Steps
1472B- Fair Division
996A - Hit the Lottery
MSNSADM1 Football
MATCHES Playing with Matches
HRDSEQ Hard Sequence