Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions 1331. Rank Transform of an Array
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Approach - 01 [ No Sorting function]
class Solution {
public:
vector<int> arrayRankTransform(vector<int>& a) {
map<int,int> mp;
// store values in ordered map
for(auto& val: a){
mp[val]++;
}

// start assign value their rank
// from top to bottom
int rank=1;
for(auto& val:mp){
val.second = rank;
rank++;
}

// traverse on array and assign them
// rank based on map
vector<int> ans(a.size());
for(int i=0;i<a.size();i++){
ans[i] = mp[a[i]];
}

// return the ranks
return ans;
}
};
Loading