We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Climbing the Leaderboard
- Discussions
Climbing the Leaderboard
Climbing the Leaderboard
Sort by
recency
|
93 Discussions
|
Please Login in order to post a comment
This would be a terrible interview question and is wasting people's time. The problem should be clarified by HackerRank.
It expects output values that would arise if each player was ranked within continuous operation but handles input/output in batches. The pre-sorted player scores add to the confusion. The solver then needs to ignore available information (later player scores) and provide "wrong" or "stale" answers.
We cannot practice eliciting and solving for requirements if they are not presented in the question and there is no interviewer.
C++ solution vector uniqueScores {}; vector result; int lastScore = ranked[0]; uniqueScores.push_back(lastScore); for(int i=1;i uniqueScores[mid]) { right = mid -1; } else { left = mid +1; } } int left_bound = (right>=0)? right:-1; int right_bound = (left< uniqueScores.size())?left:-1; if(left_bound == right_bound) { result.push_back(left_bound+1); } else if(left_bound == -1) { result.push_back(1); } else if(right_bound == -1) { result.push_back(uniqueScores.size()+1); } else { result.push_back(right_bound+1); } } return result;
Java 8 - Uses the stream distince and a modified binary search search algorithem.