# Maximum Strictly Increasing Cells in a Matrix - LeetCode Contest

Sun May 28 2023 11:06:04 GMT+0000 (Coordinated Universal Time)

Saved by @DxBros #c++ #dynammic_programming

```    int maxIncreasingCells(vector<vector<int>>& mat) {
int n = mat.size(), m = mat[0].size();
unordered_map<int,vector<pair<int,int>>> mp;
set<int> st;
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
mp[mat[i][j]].push_back({i,j});
st.insert(-mat[i][j]);
}
}
vector<vector<int>> val(n, vector<int>(m));
vector<int> rowPath(n), colPath(m);
for(auto num : st){
num = -num;
for(auto pos : mp[num]){
int r = pos.first;
int c = pos.second;
val[r][c] = max(rowPath[r], colPath[c]) + 1;
}

for(auto pos : mp[num]){
int r = pos.first;
int c = pos.second;
rowPath[r] = max(rowPath[r], val[r][c]);
colPath[c] = max(colPath[c], val[r][c]);
}
}
int ans = 0;
for(auto len : rowPath)
ans = max(len ,ans);
for(auto len : colPath)
ans = max(len , ans);
return ans;
}```
content_copyCOPY

This was a hard problem and I didn't solve

https://leetcode.com/contest/weekly-contest-347/problems/maximum-strictly-increasing-cells-in-a-matrix/