Find the first element in an array whose frequency is exactly one.
Given an array of integers, return the first element whose value appears exactly once in the array.
If no such element exists, return -1.
The answer should be the element that appears earliest in the original array among all values with frequency one.
nums.nums whose frequency is 1, or -1 if none exists.1 <= nums.lengthExample 1
Input
nums = [9, 4, 9, 6, 7, 4]
Output
6
Explanation
Frequencies are: 9 -> 2, 4 -> 2, 6 -> 1, 7 -> 1. The first value with frequency one is 6.
Example 2
Input
nums = [1, 1, 2, 2, 3, 3]
Output
-1
Explanation
Every value appears more than once, so there is no unique element.
Example 3
Input
nums = [5, 8, 5, 9, 8]
Output
9
Explanation
Only 9 appears exactly once, so it is the answer.
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.