My issue
I followed this approach to solve the problem - CodeChef: Practical coding for everyone
Why is the test cases failing ?
Am I missing something ? Can someone please explain ?
My code
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int test_cases;
cin >> test_cases;
while (test_cases--)
{
long long int n;
cin >> n;
if (n<=3)
{
for (long long int i=1; i<=n; i++)
cout << i << " ";
cout << endl;
continue;
}
vector<long long int> ans(n);
long long int x = ceil(n/2.0);
long long int p = 0;
long long int q = 1;
for (long long int i=1; i<=x; i++)
{
ans[p] = i;
p += 2;
}
for (long long int j=x+1; j<=n; j++)
{
ans[q] = j;
q += 2;
}
for (long long int idx=0; idx<n; idx++)
{
cout << ans[idx] << " ";
}
cout << endl;
}
}
Problem Link: Permutation Construction Practice Coding Problem