Quantcast
Channel: CodeChef Discuss - latest questions
Viewing all articles
Browse latest Browse all 40121

Ambiguous Permutation Problem

$
0
0

Hello everyone. I tried the Ambiguous Permutation problem under the Easy category, and I've written a code that seems to be working perfectly but for some reason the website says it's the wrong answer. Can someone please help me out in identifying what the problem is? The code is as follows:

include <iostream>

using namespace std;

int main() { int t = 0, n = 0;

cin >> t;

bool check[t];

for(int i = 0; i < t; i++)
{
    cin >> n;

    int a[n];

    for(int j = 0; j < n; j++)
        cin >> a[j];

    int b[n];

    for(int j = 0; j < n; j++)
    {
        b[a[j]-1] = j + 1;
    }

    for(int j = 0; j < n; j++)
    {
        if(a[j] == b[j])
            check[i] = true;
        else
            check[i] = false;
    }
}

for(int i = 0; i < t; i++)
{
    if(check[i] == true)
        cout << "ambiguous" << endl;

    else
        cout << "not ambiguous" << endl;
}

return 0;

}


Viewing all articles
Browse latest Browse all 40121

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>