commit 079f8655a3505f5ecd5b5756ffc201133955856c
parent 3625b6037f16d2c955c6a3aa8016c9702ca3d109
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date: Wed, 2 Oct 2024 22:39:17 +0200
Daily Problem
Diffstat:
2 files changed, 22 insertions(+), 0 deletions(-)
diff --git a/Problems/1331.cpp b/Problems/1331.cpp
@@ -0,0 +1,21 @@
+class Solution {
+ public:
+ vector<int> arrayRankTransform(const vector<int> &arr) const {
+ const int n = size(arr);
+ vector<pair<int, int>> vec(n);
+ vector<int> ans(n);
+
+ for (int i = 0; int x : arr)
+ vec[i++] = {x, i};
+ sort(begin(vec), end(vec));
+
+ int curr = 0, prev = INT_MIN;
+ for (const auto &[x, i] : vec) {
+ if (x > prev) curr++;
+ ans[i] = curr;
+ prev = x;
+ }
+
+ return ans;
+ }
+};
diff --git a/README.md b/README.md
@@ -785,6 +785,7 @@ for solving problems.
| 1327 | Easy | [List the Products Ordered in a Period](Problems/1327.cpp) |
| 1328 | Medium | [Break a Palindrome](Problems/1328.cpp) |
| 1329 | Medium | [Sort the Matrix Diagonally](Problems/1329.cpp) |
+| 1331 | Easy | [Rank Transform of an Array](Problems/1331.cpp) |
| 1333 | Medium | [Filter Restaurants by Vegan-Friendly, Price and Distance](Problems/1333.cpp) |
| 1334 | Medium | [Find the City With the Smallest Number of Neighbors at a Threshold Distance](Problems/1334.cpp) |
| 1335 | Hard | [Minimum Difficulty of a Job Schedule](Problems/1335.cpp) |