Code RoomSingle element appears once
MediumPrep Room Coding #1404

Single element appears once

CodingAlgorithms & data structuresMid–Senior~20 min

Every integer in the input array appears exactly three times except for one element that appears exactly once. Find and return that single element. Use constant extra space (no hash map of counts): for each of the 32 bit positions, sum the bit across all numbers; the bits whose total is not a multiple of 3 belong to the unique element. Assume all values fit in a signed 32-bit range and are non-negative for this variant.

Implement
single_number_iii(nums: list[int]) → int
Examples
in[[2,2,3,2]]out3
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

0:00 of about 20 min
InputExpectedGot
[[2,2,3,2]]3not run yetsample