Panda Guru LogoPanda
Guru

Atlassian Interview DSA round

Round 1

Questions: Process a list of ballots, and return all candidates sorted in descending order by their total number of points.

// List<String> getResults(List<Ballot> ballots)

We pass in a list of ballots and we return a list of candidate names in descending order of the total number of points that each candidate received. Assume that we extract the candidates' names from the votes as we process them. A voter is allowed to vote for up to three different candidates. The order of the votes is important. The first vote that a voter places is worth three points. The second vote is worth two points. The third vote is worth one point. The function should return a list of candidates in descending order of the total number of points received by the candidate.

Follow-up Questions:

  1. How to handle the scenario where the candidates have the same points? What strategies can be used?
  2. He proposed 2 strategies and I was supposed to implement both of them based on the input.

1st Strategy -> Suppose 2 candidates (A, B) have the same points. We have to declare the candidate as winner whoever reaches the winning point first.
2nd Strategy -> Votes placed in the ballot. Whoever has the maximum votes in ballot at 0th index then 1st index and then last index.

Candidate's Approach

For strategy 1, I implemented a doubly linked list having each node as a set. Basically, I was trying to implement the ALL O(1) problem's solution. With this, I can return the 0th index on the list's node.
For strategy 2, I tried maintaining an array of points at each index for each candidate. For example, A: [0,0,0].

Interviewer's Feedback

The interviewer was looking for a better solution for strategy 1. I checked multiple times with him if he was looking for a continuous output so that I could implement something similar to a heap, but he told me that only after getting all the votes we wanted to declare the winner.