2328. Number of Increasing Paths in a Grid || SLIDING WINDOW APROACH Explained✅ #DSA #Leetcode

preview_player
Показать описание
2328. Number of Increasing Paths in a Grid
You are given an m x n integer matrix grid, where you can move from a cell to any adjacent cell in all 4 directions.

Return the number of strictly increasing paths in the grid such that you can start from any cell and end at any cell. Since the answer may be very large, return it modulo 109 + 7.

Two paths are considered different if they do not have exactly the same sequence of visited cells.

________________________________

______________________________

The code is pinned in the comments too!
If you liked the explanation, please like, comment and subs to the channel:)
Рекомендации по теме
Комментарии
Автор

class Solution {
public:
vector<int> getAverages(vector<int>& nums, int k) {
//initial configuration of sliding window
long long sum = 0, n= nums.size(), window_size= 2*k;

vector<int> ans(n, -1);

//slide window
for(int i=0, j=0; i<n; i++){
sum += nums[i]; //keep adding new values to window

//store avg for k radius index and discard old values
if(i>= window_size){
ans[k++] = sum/(window_size+1);
sum -= nums[j++];
}
}

return ans;
}
};

ignition
join shbcf.ru