Atlassian Interview DSA round
Anonymous User
3744

I gave atlassian interview DSA round few days back. The question was very similar to the leetcode voting system. This round happened on local system. Unlike here we dont get the inputs and expected output in the question. We have to identiify that based on the statements given in the question.
It took me some time to identify the input correctly.
Question -
Process a list of ballots, and return all candidates sorted in descending order by their
total number of points.
// List getResults(List 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.

The solution was pretty simple (can check solutions on leetcode). However the interviewer asked follow up questions on this which was the tricky part.

  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 -> supposed 2 candidates (A, B) have same points. We have to declare the candidate as winner whoever reaches the winning point 1st.
2nd strategy -> votes placed in the ballot. Whoever has the maxium votes in ballot at 0th index then 1st index and then last index.

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

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

Can someone think of a better solution to the problem?

Comments (8)