commit 68e28b853cb3834ccec809f44fc186ba7e129420 parent ce6f945800069b9047d3c6ad526ff6724308f174 Author: Dimitrije Dobrota <mail@dimitrijedobrota.com> Date: Sat, 5 Oct 2024 13:53:14 +0200 1 Random Problem Diffstat:
A | Problems/1914.cpp | | | 24 | ++++++++++++++++++++++++ |
M | README.md | | | 1 | + |
2 files changed, 25 insertions(+), 0 deletions(-)
diff --git a/Problems/1914.cpp b/Problems/1914.cpp @@ -0,0 +1,24 @@ +class Solution { + public: + vector<vector<int>> rotateGrid(vector<vector<int>> &grid, int k) const { + const int n = size(grid), m = size(grid[0]); + + for (int l = 0; l < n / 2 && l < m / 2; l++) { + const int elems = (m + n - 4 * l - 2) * 2; + for (int count = 0; count < k % elems; count++) { + const int tmp = grid[l][l]; + for (int j = l + 1; j < m - l; j++) + grid[l][j - 1] = grid[l][j]; + for (int i = l + 1; i < n - l; i++) + grid[i - 1][m - l - 1] = grid[i][m - l - 1]; + for (int j = m - l - 2; j >= l; j--) + grid[n - l - 1][j + 1] = grid[n - l - 1][j]; + for (int i = n - l - 2; i >= l; i--) + grid[i + 1][l] = grid[i][l]; + grid[l + 1][l] = tmp; + } + } + + return grid; + } +}; diff --git a/README.md b/README.md @@ -1052,6 +1052,7 @@ for solving problems. | 1910 | Medium | [Remove All Occurrences of a Substring](Problems/1910.cpp) | | 1911 | Medium | [Maximum Alternating Subsequence Sum](Problems/1911.cpp) | | 1913 | Easy | [Maximum Product Difference Between Two Pairs](Problems/1913.cpp) | +| 1914 | Medium | [Cyclically Rotating a Grid](Problems/1914.cpp) | | 1915 | Medium | [Number of Wonderful Substrings](Problems/1915.cpp) | | 1920 | Easy | [Build Array from Permutation](Problems/1920.cpp) | | 1921 | Medium | [Eliminate Maximum Number of Monsters](Problems/1921.cpp) |