Problem
Given an integer array where every element appears three times except for one element which appears exactly once, find that single element. Must run in O(n) time and O(1) space.
References
Difficulty
🟡 Medium
Companies
Flipkart, PhonePe, Zomato
Notes
Language: Java
Count set bits at each position modulo 3. The bit that gives remainder 1 belongs to the single element. Can also use two bitmask approach with 'ones' and 'twos'.
Problem
Given an integer array where every element appears three times except for one element which appears exactly once, find that single element. Must run in O(n) time and O(1) space.
References
Difficulty
🟡 Medium
Companies
Flipkart, PhonePe, Zomato
Notes
Language: Java
Count set bits at each position modulo 3. The bit that gives remainder 1 belongs to the single element. Can also use two bitmask approach with 'ones' and 'twos'.