From 94de23c34ab2ea8d498d49fc3a82932fe40a1313 Mon Sep 17 00:00:00 2001 From: Abhishek Tripathi <42455093+abhishektripathi66@users.noreply.github.com> Date: Wed, 2 Oct 2024 15:39:27 +0530 Subject: [PATCH] Create RankTransform.java --- Leetcode/RankTransform.java | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 Leetcode/RankTransform.java diff --git a/Leetcode/RankTransform.java b/Leetcode/RankTransform.java new file mode 100644 index 0000000..a666ccb --- /dev/null +++ b/Leetcode/RankTransform.java @@ -0,0 +1,35 @@ +/** + +1331. Rank Transform of an Array +Solved +Easy +Topics +Companies +Hint +Given an array of integers arr, replace each element with its rank. + +The rank represents how large the element is. The rank has the following rules: + +Rank is an integer starting from 1. +The larger the element, the larger the rank. If two elements are equal, their rank must be the same. +Rank should be as small as possible. + + **/ +class Solution { + public int[] arrayRankTransform(int[] arr) { + int n = arr.length,i=0; + TreeMap map = new TreeMap<>(); + for(i=0;i entry:map.entrySet()){ + map.put(entry.getKey(),i); + i++; + } + for(i=0;i