Skip to content

Instantly share code, notes, and snippets.

@piusayowale
Created August 17, 2022 16:29
Show Gist options
  • Select an option

  • Save piusayowale/eecb3e41309af22385e2c463c98108f4 to your computer and use it in GitHub Desktop.

Select an option

Save piusayowale/eecb3e41309af22385e2c463c98108f4 to your computer and use it in GitHub Desktop.
this solution is still failing for 2 cases
vector<int> climbingLeaderboard(vector<int> ranked, vector<int> player) {
vector<int> player_ranks;
set<int> score_cache{ranked.begin(), ranked.end()};
unordered_map<int, int> dp;
//int dp[INT16_MAX] = {0}; segmentation fault for some cases
for(auto d : player){
score_cache.insert(d);
cout << d << "\n";
if(dp[d] == 0){
int dpv = distance( score_cache.find(d), score_cache.end());
dp[d] = dpv;
player_ranks.push_back(dpv);
}else{
player_ranks.push_back(dp[d]);
}
}
return player_ranks;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment