Interview Question for Software Engineer / Developers


Country: United States
Interview Type: In-Person




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

Can a caching policy with LRU be of any help here. You can use LinkedHashMap and implement the removeEldestEntry when size is more than capacity(i.e., n). Assuming those records are unique.

For duplicate records, you can use a map with key equal to song name and an integer value representing the frequency of how many times the song was listened for. You can then output the first n songs with maximum frequency.

- Ahmed.Ebaid August 18, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

we can use cache techniques for this .
First of all we will create a priority queue . entry's which we want we can access easily

- star_akd August 18, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Use

Map<Date, List<Integer>> map = new HashMap<Date, List<Integer>>

Insert :
List<Integer> songsId = map.get(currentDate);
songsId.add(newSongId);
map.add(currentDate, songsId );

retrieve:
for(Map::EntrySet<Date, List<Integer>> entry : map){
if(DateWithinWeek( entry.getKey())){
for(Integer songsId : entry.getVal){
// output the result
}
}
}

- hprem991 August 18, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Assumption: multiple users IDs with tracks they listened to in the last one week have been given to you.
Solution: Use a HashMap with UserId as the key and a Priority Queue (Max heap) of Songs based on the number of times that particular user has listened to. So the priority queue's top holds the song that was listened to the maximum number of times.
Alternatively, you could use a hashmap of treemaps reverse sorted based on the number of times a song has been listened to. Hope I am making sense.

- sriharshitav August 18, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Just got an idea, what if we set the expiry of the record to 7 days. That way every record that is there in cache is within the time limit. Then we simply have to return the top n records of all records for the user within that time frame. Does that make sense? Anybody who can suggest the code for this?

- Ccq15 August 19, 2017 | 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