DevHireLab
TutorialsBootcamp
Problems
Code SimulatorAI InterviewSoonContact
DevHireLab
TutorialsBootcamp
Problems
Code SimulatorAI InterviewSoonContact
Back to Arena
easy
Array

Single Number

**Problem Statement:** Given a non-empty array of integers `nums`, every element appears twice except for one. Find that single one. You must implement a solution with a linear runtime complexity and use only constant extra space. **Hint / Expected Approach:** XOR cancels duplicates **Edge Cases to Consider:** - (1) Single element array - (2) All elements appear twice except first - (3) Negative numbers

Examples

Example 1
Input: [2, 2, 1]
Output: 1
Example 2
Input: [4, 1, 2, 1, 2]
Output: 4
Example 3
Input: [1]
Output: 1

Constraints

  • ▪1 <= nums.length <= 10^4
  • ▪-10^9 <= nums[i] <= 10^9
  • ▪Time complexity should be O(n) or O(n log n)

Watch Out For Edge Cases

  • ▪Single element array
  • ▪All elements appear twice except first
  • ▪Negative numbers
Frequently Asked At
AmazonMicrosoftGoogleAdobeInfosys