Grokking the Engineering Manager Coding Interview
Vote

0% completed

Largest Unique Number (easy)

Problem Statement

Try it yourself

Problem Statement

Given an array of integers, identify the highest value that appears only once in the array. If no such number exists, return -1.

Examples:

  1. Example 1:

    • Input: [5, 7, 3, 7, 5, 8]
    • Expected Output: 8
    • Justification: The number 8 is the highest value that appears only once in the array.
  2. Example 2:

    • Input: [1, 2, 3, 2, 1, 4, 4]
    • Expected Output: 3
    • Justification: The number 3 is the highest value that appears only once in the array.
  3. Example 3:

    • Input: [9, 9, 8, 8, 7, 7]
    • Expected Output: -1
    • Justification: There is no number in the array that appears only once.

Constraints:

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

Try it yourself

Try solving this question here:

Python3
Python3

. . . .
Mohammed Dh Abbas

Mohammed Dh Abbas

· 2 years ago

def largestUniqueNumber(self, A: List[int]) -> int: counter = Counter(A) max_num = -1 for num, freq in counter.items(): if num > max_num and freq == 1: max_num = num return max_num

On This Page

Problem Statement

Try it yourself