Posts Party of Couples (geeksforgeeks - SDE Sheet)
Post
Cancel

Party of Couples (geeksforgeeks - SDE Sheet)

PROBLEM DESCRIPTION

You are given an integer array arr[] of size n, representing n number of people in a party, each person is denoted by an integer. Couples are represented by the same number ie: two people have the same integer value, it means they are a couple. Find out the only single person in the party of couples.

geeksforgeeks

SOLUTION

1
2
3
4
5
6
7
8
9
10
11
12
13
14
class Solution{

    static int findSingle(int n, int arr[]){

        int x = 0;

        for(Integer i: arr)
            x ^= i;

        return x;

    }

}
This post is licensed under CC BY 4.0 by the author.