Skip to content
Programmingoneonone
Programmingoneonone
  • Home
  • CS Subjects
    • IoT ? Internet of Things
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programmingoneonone

HackerEarth Inverse List problem solution

YASH PAL, 31 July 2024
In this HackerEarth Inverse List problem solution, There are many ways to order a list of integers from 1 to n. For example, if n = 3, the list could be : [3 1 2].
But there is a special way to create another list from the given list of integers. In this list, the position of the integer i is the ith number in the given list. So following this rule, the given list will be written as: [2 3 1]. This list is called the inverse list. Now there exists some list whose inverse list is identical. For example, the inverse list of [1 2 3] is the same as the given list. Given a list of integers you have to determine whether the list is inverse or not.
The input contains several test cases. The first line is the number of test cases t (1 <= t <= 100). The first line of each test case contains an integer n (1 <= n <= 10000). Then a list of the integers 1 to n follows in the next line.
HackerEarth Inverse List problem solution

HackerEarth Inverse List problem solution.

#include <bits/stdc++.h>

using namespace std;

int org [100000 + 10];
int arr [100000 + 10];

int main()
{
int n , t;

cin >> t ;

while( t-- ){

cin >> n;

for(int i = 1; i <= n; i++){

cin >> org[i];
arr[ org[i] ] = i;
}

bool revers = true;

for(int i = 1; i <= n; i++){

if(org[i] != arr[i]){

revers = false;
break;
}
}

if(revers) cout << "inversen";
else cout << "not inversen";
}

return 0;
}
coding problems solutions

Post navigation

Previous post
Next post

Pages

  • About US
  • Contact US
  • Privacy Policy

Programing Practice

  • C Programs
  • java Programs

HackerRank Solutions

  • C
  • C++
  • Java
  • Python
  • Algorithm

Other

  • Leetcode Solutions
  • Interview Preparation

Programming Tutorials

  • DSA
  • C

CS Subjects

  • Digital Communication
  • Human Values
  • Internet Of Things
  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2025 Programmingoneonone | WordPress Theme by SuperbThemes