Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Maximum Matrix Sum
Bookmark
Input
2x2 Even neg
3x3 Mixed
3x3 Odd neg
2x2 Mixed
Custom
matrix
=
[[1,-1],[-1,1]]
0
1
0
1
1
-1
-1
1
0
1
0
1
1
-1
-1
1
total =
0
negatives =
0
0
1
0
1
1
-1
-1
1
total =
0
, min = ∞, negatives =
0
total =
1
negatives =
0
0
1
0
1
1
min
-1
-1
1
|
1
| = 1 → total =
1
, min =
1
total =
2
negatives =
1
0
1
0
1
1
min
-1
-1
1
|
-1
| = 1 → total =
2
, negatives =
1
total =
3
negatives =
2
0
1
0
1
1
min
-1
-1
1
|
-1
| = 1 → total =
3
, negatives =
2
total =
4
negatives =
2
0
1
0
1
1
min
-1
-1
1
|
1
| = 1 → total =
4
total =
4
negatives =
2
(even)
0
1
0
1
1
min
-1
-1
1
negatives = 2
(even)
→ all cancel in pairs
total =
4
negatives =
2
(even)
0
1
0
1
1
1
1
1
Maximum sum =
4
algo
master
.
io
Step:
Start: Flip adjacent pairs of signs to maximize the matrix sum
0 / 7
Input
2x2 Even neg
3x3 Mixed
3x3 Odd neg
2x2 Mixed
Custom
matrix
=
[[1,-1],[-1,1]]
0 / 7
algo
master
.
io
Step:
Start: Flip adjacent pairs of signs to maximize the matrix sum