Uber SDE 2 | Phone screen

Difficulty: MEDIUMCategory: InterviewExperienceFrequency: 1Asked On 2024-09-27Added By Anonymous
Source: Link

Company: Uber

Role: Software Engineer II

Interview Stage: Phone Screen


Original Post Content:


I had Uber phone screen last week after OA.

I was told it was leetcode style problem for this 60-minute interview. At the beginning, interviewer sort of spent 15 minutes to go over the resume / past experience. The rest is for a leetcode medium question.


Question: Implement a Counter class that has the following methods:


1. put(number): put the number to the data structure


2. count(number): count the number of times number was put during the last window=5 minutes


3. countAll(): count the number of times any number was put during the last window=5 minutes.


Example:


At t = 10PM, put(2)

At t = 10:02PM, put(2)

At t = 10:03PM, put(3)

At t = 10:04PM, count(2) should return 2

At t = 10:04PM, countAll() should return 3

At t = 10:06PM, count(2) should return 1 (the one that was put at 10:02PM)

At t = 10:06PM, countAll() should return 2


Follow-ups:


1. If you were to write unit tests, what would they be

2. If your code was to be in production, what issues may it cause?

I'm going to onsite.

Comments