BackeasyHashing Meesho

Unique Element Finder Solution

Problem Statement

Given the list of batch IDs, find the ID of the rogue batch that appears exactly once. Note that the input list may be empty, and the rogue batch may be anywhere in the list.

Example 1
Input
[7, 7, 6, 6, 5, 5, 4, 4, 3, 3, 2, 2, 1, 1]
Output
7

Explanation: Step-by-step: Given the list of batch IDs [7, 7, 6, 6, 5, 5, 4, 4, 3, 3, 2, 2, 1, 1], we create a HashMap to store the frequency of each batch ID. We iterate through the list and for each ID, we increment its frequency in the HashMap. Finally, we iterate through the HashMap and return the ID with a frequency of 1.

Example 2
Input
[1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7]
Output
1

Explanation: Step-by-step: Given the list of batch IDs [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7], we create a HashMap to store the frequency of each batch ID. We iterate through the list and for each ID, we increment its frequency in the HashMap. Finally, we iterate through the HashMap and return the ID with a frequency of 1.

Constraints

  • 1 <= n <= 10^5
  • n is always odd.
Live Compiler
Loading...
Test Cases & Output
🔒 Sign up to run your code

🚀 Practice this problem

Run code, get AI hints & track streak

Sign Up Free