 # ALONE - Editorial

Author: Prathamesh Sogale
Tester: Prathamesh Sogale
Editorialist: Ram Agrawal

EASY

Loops

# PROBLEM:

One day Vaibhav gave a task to Meena. He gave him an array AA of size NN, array is of special type, each element is repeated exactly 3 times in this array except only one element appears only once. In this task Meena needs to find the element that occurs only once in this array.

• Note!Note! You cannot use sorting in this problem

# QUICK EXPLANATION:

In this Question, you have to find a number that is present only 1 time in an array.

# EXPLANATION:

In this question, you can count the number of times every element is present in an array and then print the element which is present only one time

# SOLUTIONS:

Setter's Solution
``````/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc=new Scanner(System.in);
int T=sc.nextInt();
while(T-->0){
int N=sc.nextInt();
long arr[]=new long[N];
for(int i=0;i<arr.length;i++){
arr[i]=sc.nextLong();
}
long one=0;
long two=0;
long not_three;
long x;
for(int i=0;i<arr.length;i++){
x=arr[i];
two |= one & x;
one ^= x;
not_three = ~(one & two);
one &= not_three;
two &= not_three;

}

System.out.println(one);

}
}
}
``````
Tester's Solution
``````#include <bits/stdc++.h>
using namespace std;

int main() {
int t;
cin>>t;
while(t--){
long long int n;
cin>>n;
long long int arr[n];
unordered_map<long long int , long long int>mp;
for(int i=0;i<n;i++){
cin>>arr[i];
mp[arr[i]]++;
}
for(auto x:mp){
if(x.second==1){
cout<<x.first<<endl;
}
}

}
return 0;
}
``````
Editorialist's Solution
``````T = int(input())
for _ in range(T):
N = int(input())
n = map(int,input().split())
k = list(n)
for i in k:
if k.count(i) == 1:
print(i)
break
``````