Uber Interview Question for Software Engineers


Team: Marketplace
Country: United States




Comment hidden because of low score. Click to expand.
0
of 0 vote

I'll give you a hint. You can use hash tables for this.

Simply iterate over the array and store the element and the number of occurrence in that array.

Now return the element which has the highest number of occurrences in your hash table. This should be O(n) solution.

Please correct me if I've made any mistakes.

- utkarsh.bhatt12 January 04, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

"element which has the highest number of occurrences in your hash table". that will give you the first one. not the Kth one.

- pascal January 11, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Over my interpretation, most frequent is different of longest sequence.

And i have a question, if there is more elements with the same frequency? Should return a list of them?

from collections import Iterable

def get_most_frequent(input_list):
	max_sequence = 0
	most_frequent = None
	numbers_frequence = {}

	if(not isinstance(input_list, Iterable)):
		return most_frequent

	for n in input_list:
		if(numbers_frequence.get(n, False) is not False):
			numbers_frequence[n] += 1
		else:
			numbers_frequence[n] = 1

		if(numbers_frequence[n] > max_sequence):
			max_sequence = numbers_frequence[n]
			most_frequent = [n]
		elif(numbers_frequence[n] is max_sequence):
			most_frequent.append(n)

	return most_frequent


print(get_most_frequent([0,1,2,3,4,4,4]))
print(get_most_frequent([5,5,5,7,7,7,8,9]))
print(get_most_frequent([0]))

- vitoralbano January 14, 2018 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More