Design Gurus Logo
Single Number II (medium)

Problem Statement

Given an array of integers nums where each element appears three times, and one element appears exactly once, return the single element.

Note: You must solve the problem with linear runtime complexity and use only constant extra space.

Examples

  • Example 1:
    • Input: nums = [4, 3, 3, 3]
    • Expected Output: 4
    • Justification: 4 is the only number that appears once, while 3 appears three times.
  • Example 2:
    • Input: nums = [99, 1, 99, 99, 2, 2, 2]
    • Expected Output: 1
    • Justification: 1 appears exactly once whereas 99 and 2 each appear three times.
  • Example 3:
    • Input: nums = [0, 7, 2, 7, 2, 7, -1, 2, -1, -1]
    • Expected Output: 0
    • Justification: 0 is the unique number appearing once, while 7, 2 and -1 appear three times.

Try it yourself

Try solving this question here:

Python3
Python3

. . . .

.....

.....

.....

Unlock this and all other premium problems.
No code editor for this lesson
This lesson focuses on concepts and theory