easyHashingPattern: Bit Manipulation / Hashing

Single Occurrence Identifier Solution

Problem Statement

You are given an array of integers `batchIds` where every element appears exactly twice except one. Find the integer that appears only once.

Examples

Example 1:
Input:[2, 2, 3, 4, 4]
Output:3
Explanation: The item with batch ID 3 appears exactly once.
Example 2:
Input:[1, 1, 2, 2, 3, 4, 4]
Output:3
Explanation: The item with batch ID 3 appears exactly once.

Constraints

  • 1 <= n <= 10^5
  • n is always odd.
Time: O(N) Space: O(1)
Use a hash map to count the occurrences of each batch ID in O(n) time complexity

Run, Test & Submit Code

Ready to practice this challenge? Launch our interactive compilation environment with compiler validation.

Solve on Interactive Workspace

Tested Solutions

No solution code is currently loaded.
Complete this code in the workspace editor.