Unable to reduce the time exceeded

The question is uncle johny - easy section .
using namespace std;

int main() {
int t;
vector v;
{ int n ;
int j,k;
int num;
for(j =0;j<n;j++)
int pos;
cin>> pos;
int temps = v[pos-1];

     for(j =0;j<n;j++)
     { if(v[j]==temps)
return 0;


this is the solution that i had written and i am unable to understand how to reduce the time limit. thankyou in advance!

Providing link to question and your solution, would have helped viewers understand better.

sorry new to this platform…but would keep that in mind!
Problem statement : https://www.codechef.com/problems/JOHNY
My solution : https://www.codechef.com/viewsolution/34189225

Time complexity to use sort function will be O(nlog(n)) [worst case].
Think of any other approach to solve in O(n) [worst time]. :+1:

Try thinking of a logic that would work without sorting !

@rattle087 just look at the position where u have declared the vector.Vector just pushes every value to last element. So in your case it is just pushing every element of every test case.your vector contains all the value of test cases.Hope it will help you. Happy Coding!