[InterviewBit] Kingdom War

Kingdom War

  • Time :
  • Space :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
int Solution::solve(vector<vector<int>> &A) {
int n = A.size(), m = A[0].size();
int res = INT_MIN;
vector<int> dp(m,0);
for(int i = n - 1; i >= 0; i--) {
int now = 0;
for(int j = m - 1; j >= 0; j--) {
dp[j] += A[i][j];
now += dp[j];
res = max(res, now);
}
}
return res;
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2022/10/25/PS/interviewbit/kingdom-war/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.