From 9af80d7b3e13cdbe7cf6a95388c5a201a48817a5 Mon Sep 17 00:00:00 2001 From: chayan das <110921638+Chayandas07@users.noreply.github.com> Date: Wed, 2 Oct 2024 16:27:11 +0530 Subject: [PATCH] Create 1331. Rank Transform of an Array --- 1331. Rank Transform of an Array | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 1331. Rank Transform of an Array diff --git a/1331. Rank Transform of an Array b/1331. Rank Transform of an Array new file mode 100644 index 0000000..487e5d4 --- /dev/null +++ b/1331. Rank Transform of an Array @@ -0,0 +1,29 @@ +// Approach - 01 [ No Sorting function] +class Solution { +public: + vector arrayRankTransform(vector& a) { + map 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 ans(a.size()); + for(int i=0;i