Single Number - I

Bit Manipulation Problems Medium
  • This problem is a simplified version of the one faced by data scientists and software engineers while working with big data
  • It's common in data analysis to encounter datasets where most entities are duplicates and a single unique item must be found
  • Efficiently solving this problem is an important aspect of tasks like data deduplication, where you want to find and remove duplicate data in databases to improve data quality, or anomaly detection, where the aim is to find data points that are different from the majority to identify potential issues or insights
  • It is certainly a fundamental concept in the world of big data handling and manipulation

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