We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 5b7450b + 9af80d7 commit 9a2b735Copy full SHA for 9a2b735
1331. Rank Transform of an Array
@@ -0,0 +1,29 @@
1
+// Approach - 01 [ No Sorting function]
2
+class Solution {
3
+public:
4
+ vector<int> arrayRankTransform(vector<int>& a) {
5
+ map<int,int> mp;
6
+ // store values in ordered map
7
+ for(auto& val: a){
8
+ mp[val]++;
9
+ }
10
+
11
+ // start assign value their rank
12
+ // from top to bottom
13
+ int rank=1;
14
+ for(auto& val:mp){
15
+ val.second = rank;
16
+ rank++;
17
18
19
+ // traverse on array and assign them
20
+ // rank based on map
21
+ vector<int> ans(a.size());
22
+ for(int i=0;i<a.size();i++){
23
+ ans[i] = mp[a[i]];
24
25
26
+ // return the ranks
27
+ return ans;
28
29
+};
0 commit comments