insidcode
ProblemsDuelLeaderboardStats
Sign In
  1. Home
  2. Problems
  3. Find the only element in an array that appears once while all other elements appear twice (using XOR).

Find the only element in an array that appears once while all other elements appear twice (using XOR).

Difficulty: Medium

Phase: 6 · Mixed Logical Challenges

XP Reward: 20 XP

Topics: Mixed Logical Challenges, Medium

Supported Languages: Python, JavaScript, C, C++, Java

Problem Description

Given array of N integers where every element appears twice except one, find that single element using XOR. Input Format: Read input from standard input (stdin). Output Format: Print the result to standard output (stdout).

Constraints

  • -10^9 <= N <= 10^9

Examples

Example 1

Input: 5 4 1 2 1 2

Output: 4

Explanation: Sample execution for input 5 4 1 2 1 2