Largest Unique Number - Problem
Given an integer array nums, return the largest integer that only occurs once. If no integer occurs exactly once, return -1.
An integer occurs once if it appears exactly one time in the array, meaning it has no duplicates.
Input & Output
Example 1 — Basic Case
$
Input:
nums = [2,1,3,2,1]
›
Output:
3
💡 Note:
Numbers 2 and 1 each appear twice, but 3 appears only once. Since 3 is the largest unique number, return 3.
Example 2 — No Unique Numbers
$
Input:
nums = [1,1,2,2]
›
Output:
-1
💡 Note:
Every number appears exactly twice, so there are no unique numbers. Return -1.
Example 3 — Single Element
$
Input:
nums = [5]
›
Output:
5
💡 Note:
The array has only one element, which appears exactly once, so return 5.
Constraints
- 1 ≤ nums.length ≤ 1000
- -1000 ≤ nums[i] ≤ 1000
Visualization
Tap to expand
Understanding the Visualization
1
Input Array
Array with some duplicate numbers
2
Count Frequencies
Identify which numbers appear exactly once
3
Find Maximum
Return the largest unique number
Key Takeaway
🎯 Key Insight: Use frequency counting to identify unique elements, then find the maximum among them
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code