Talentd
FleetCode

1133. Largest Unique Number

Easy71.3% acceptance1 companyPremium elsewhere, free here

Given an integer array nums, return the largest integer that only occurs once. If no integer occurs once, return -1.

Example 1:

Input: nums = [5,7,3,9,4,9,8,3,1]
Output: 8
Explanation: The maximum integer in the array is 9 but it is repeated. The number 8 occurs only once, so it is the answer.

Example 2:

Input: nums = [9,9,8,8]
Output: -1
Explanation: There is no number that occurs only once.

Constraints:

  • 1 <= nums.length <= 2000
  • 0 <= nums[i] <= 1000

Asked at 1 company

Hints open one at a time

Hint 1
Find the number of occurrences of each value.
Hint 2
Use an array or a hash table to do that.
Hint 3
Look for the largest value with number of occurrences = 1.
10:17
Still stuck?Read the written solution, or watch a walkthrough.
Open solution
Loading editor…
1class Solution:
2 def solve(self):
3 pass
4
Starter codePython 3Spaces: 4
Examples
Input
[5,7,3,9,4,9,8,3,1]
Input
[9,9,8,8]
Your code is saved on this device.Solution