Skip to content

Create 2373. Largest Local Values in a Matrix #476

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Create 2373. Largest Local Values in a Matrix
  • Loading branch information
Chayandas07 authored May 12, 2024
commit 29a84c0ff54d9bbb394468dc4861b5fdf221c1bd
27 changes: 27 additions & 0 deletions 2373. Largest Local Values in a Matrix
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
class Solution {
public:
vector<vector<int>> largestLocal(vector<vector<int>>& grid) {
int n = grid.size();

for(int i = 1; i < n - 1; ++i) {
for(int j = 1; j < n - 1; ++j) {
int temp = 0;

for(int k = i - 1; k <= i + 1; ++k) {
for(int l = j - 1; l <= j + 1; ++l) {
temp = max(temp, grid[k][l]);
}
}

grid[i - 1][j - 1] = temp;
}
}

grid.resize(n - 2);
for (int i = 0; i < grid.size(); ++i) {
grid[i].resize(n - 2);
}

return grid;
}
};
Loading