Once Once, Once Twice

You are given an integer array nums. In this array:

  • Exactly one element appears once.
  • Exactly one element appears twice.
  • All other elements appear exactly three times.

Return an integer array nums such that:

nums[0] = element appearing 1 times

nums[1] = element appearing 2 times

Your solution must run in O(n) time and O(1) space.

Example 1:

Input: nums = [2,2,3,2,5,5,5,7,7]

Output: [3,7]

Explanation:

The element 3 appears once, and the element 7 appears twice. The remaining elements each appear three times.

Example 2:

Input: nums = [4,4,6,4,9,9,9,6,8]

Output: [8,6]

Explanation:

The element 8 appears once, and the element 6 appears twice. The remaining elements each appear three times.

Now Your Turn!

Pick the correct output for the given input

Input: nums = [1,2,2,3,3,3]

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Constraints:

  • 3 <= nums.length <= 105
  • -231 <= nums[i] <= 231 - 1
  • nums.length is a multiple of 3
  • One element appears once, one element appears twice, and all other elements appear three times.

Hints

Interview Follow-up Questions

0
class Solution {
public:
vector<int> onceOnceOnceTwice(vector<int> nums) {
}
};
 
Test Case

Input:

Input