Find the Unique Element Among Pairs
Updated
Problem statement
You are given a nonempty integer array nums. Exactly one value appears once and every other value appears exactly twice.
Return the value that appears once. The input is not necessarily sorted.
Function
singleNumber(nums: int[]) → intExamples
Example 1
nums = [4,1,2,1,2]return = 4The values 1 and 2 form pairs, leaving 4.
Example 2
nums = [-7,3,3]return = -7The two 3 values cancel as a pair.
Constraints
1 <= nums.length <= 200001.nums.lengthis odd.-1000000000 <= nums[i] <= 1000000000.- Exactly one value appears once; every other value appears twice.
More Chubb interview questions
- Reverse a Singly Linked ListPHONE SCREEN · Seen Oct 2026
- Second-Highest Distinct SalaryPHONE SCREEN · Seen Oct 2026
- Count Pairs with K Divisible Values in the IntervalOA · Seen Oct 2026
- Index of the Maximum After Left RotationsOA · Seen Oct 2026
- Maximize Revenue from Decreasing InventoryOA · Seen Oct 2026
- Minimize the Maximum Array ElementOA · Seen Oct 2026
- Minimum Distinct Prefix CostOA · Seen Oct 2026
- Flat JSON Value DifferencesOA · Seen Sep 2026
- Maximum Student-Teacher DistanceOA · Seen Sep 2026
- Minimum Cost to Reach a Target WeightOA · Seen Sep 2026
Similar questions at other companies
- The One Repeated NumberAdobe · PHONE SCREENAdobe interview questions
- Wildcard Address-Book QueriesGoogle · PHONE SCREENGoogle interview questions
- Palindrome-Rearrangeable PairsExpedia · OAExpedia interview questions
- Count Subarrays with a Perfect-Square ProductMicrosoft · OAMicrosoft interview questions
- Optimize Discount Selection Under a Point BudgetPalantir · OAPalantir interview questions
- Bitwise XOR SubsequencesJP Morgan Chase · OAJP Morgan Chase interview questions
- Count Valid Bitwise PairsStripe · OAStripe interview questions
- Bitwise XOR SubsequencesGoldman Sachs · OAGoldman Sachs interview questions
- Count Subarrays With Given XORInMobi · OAInMobi interview questions
- Sparse Vector Dot Product from TuplesMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions