FastPrepFind the Value That Appears Once
Problems/Find the Value That Appears Once

Find the Value That Appears Once

Indeed logoIndeed● EasyFULLTIMEPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: You get an array in which every value is the same except one, and you find the one that differs.

The report gives no limits. Here, you return the number instead of printing it, the array has 3 to 5 * 10^4 values, and each value is between -10^9 and 10^9.

The judged task matches the report at about 95%.

You are given an integer array nums that holds exactly two different values. One value appears exactly once. The other value fills every other position.

Return the value that appears exactly once.

Function

findSingle(nums: int[]) → int

Examples

Example 1

nums = [1,2,2,2,2]return = 1

The value 2 appears four times and 1 appears once. The answer is 1.

Example 2

nums = [3,3,3,3,4]return = 4

The value 3 appears four times and 4 appears once, at the end. The answer is 4.

Example 3

nums = [2,2,3,2,2,2]return = 3

The value 2 appears five times and 3 appears once, in the middle. The answer is 3.

Constraints

  • 3 <= nums.length <= 5 * 10^4
  • -10^9 <= nums[i] <= 10^9
  • nums holds exactly two different values, and one of them appears exactly once.

More Indeed problems

  • Insert into an Unrolled Linked ListPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Course Completion OrderPHONE SCREEN · Seen May 2025
  • Recipes You Can PreparePHONE SCREEN · Seen May 2025
All Indeed interview questionsSee Indeed hiring insights
Saved
class Solution {
    public int findSingle(int[] nums) {
        // Write your code here.
    }
}
Checking account…