Find the Single Number
Logic Building: Rotations & Sets DSA practice problem on Onlearn.
Difficulty: medium.
Topics: Find the single element in an array where every other element appears twice, Arrays, Hashing, Hash Tables, Map, Frequency Counting, XOR, Time Complexity, Space Complexity, Big O Notation, Loops, bit manipulation, space complexity, hashing, hash map, search algorithms, array traversal, time complexity analysis, Hashing with Arrays, Hashing & Hash Maps, Bitwise XOR.
Problem Statement Given a non empty array of integers arr, every element appears twice except for one. Find that single one. Input Specification The input consists of a single line containing space separated integers representing the array arr. Output Specification Output a single integer, which is the element that appears only once. Sample Test Cases Example 1: Input Format: arr[] = {2,2,1} Result: 1 Explanation: In this array, only the element 1 appears once, and so it is the answer. Example 2: Input Format: arr[] = {4,1,2,1,2} Result: 4 Explanation: In this array, only element 4 appears once, and the other elements appear twice. So, 4 is the answer.