Oracle phone interview

Difficulty: MEDIUMCategory: InterviewExperienceFrequency: 1Asked On 2023-05-31Added By Anonymous
Source: Link

Company: Oracle
Role: unknown
Interview Stage: Phone Screen
Location: unknown
Year: unknown

Original Post Content:

Hi,

I had phone interview with Oracle with a HackerRank link.

I was asked following problem:

Given an array of integers nums. Find lucky numbers in that array and if multiple such numbers found, return max. If none found, return -1. A number is lucky if it occurs that many times in the array.

Eg., [1,2,2,3,3,3]
Output: 3.
Explanation: 1 occurs 1 time., 2 occurs 2 times and 3 occurs 3 times. So they all are lucky numbers. But max is 3.

Another example
[2,3,5]
Output: -1
Explanation: There is no number that occurs that many times in the array.

I gave straightforward solution.
1. Create map of (number) -> (count of that number).
2. Iterate over it and return max key.

Another way is to sort the array and then iterate over it.

Both solutions have pros and cons.

But I was rejected.

Maybe there is a better solution?

Comments