Single Number - I

Bit Manipulation Problems Medium

Given an array of nums of n integers. Every integer in the array appears twice except one integer. Find the number that appeared once in the array.

Examples:

Input : nums = [1, 2, 2, 4, 3, 1, 4]

Output : 3

Explanation : The integer 3 has appeared only once.

Input : nums = [5]

Output : 5

Explanation : The integer 5 has appeared only once.

Input : nums = [1, 3, 10, 3, 5, 1, 5]

Constraints

  • 1 <= n <= 105
  • -3*105 <= nums[i] <= 3*105

Hints

  • When you XOR all the numbers in the array, the duplicate numbers cancel out, leaving only the unique number.
  • Traverse the array and XOR all the elements together. At the end of the traversal, the result will be the number that appears only once because the XOR of duplicates will be zero.

Company Tags

Byju's Optum Roblox Instacart Wayfair Zoho Roche Philips Healthcare Teladoc Health HCL Technologies Visa Texas Instruments Activision Blizzard IBM Freshworks GE Healthcare OYO Rooms Intel Rakuten Cerner Twilio Zynga Cloudflare Docker JPMorgan Chase Google Microsoft Amazon Meta Apple Netflix Adobe