Skip to content

Commit 823bfa4

Browse files
authored
refine the comments
1 parent 0b4a22f commit 823bfa4

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

algorithms/cpp/maximumValueAtAGivenIndexInABoundedArray/MaximumValueAtAGivenIndexInABoundedArray.cpp

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,32 +45,39 @@ This problem can be treat as a pyramid which shaped by 1, it looks like below:
4545
1 1 1 1 1 1 1
4646
So, from the top, for each layer, we need the 1,3,5,7,9.... 2*n-1 ONE(s).
4747
48-
But we need to deal with the edge case - it could be out of the array bound
48+
But we need to deal with the edge case - it could be out of the array boundary
4949
5050
For example: index=2, lenght=3, maxSum=18
5151
5252
1) at first, we put `1 1 1` on bottom layer - Array[2] = 1
5353
54-
2) then we start from the top - Array[2] = 2
54+
2) then we start from the top
5555
5656
1 <-- the top first layer
5757
1 1 1 <-- bottom
58+
59+
now, we have Array[2] is 2
5860
5961
3) we keep doing tthe 2nd layer - Array[2] = 3
6062
1 <-- the 1st layer
61-
1 1 [1] <-- the 2nd layer, which has 1 out of the bound
63+
1 1 [1] <-- the 2nd layer, which has 1 out of the boundary
6264
1 1 1 <-- bottom
65+
66+
now, we have Array[2] is 3
6367
6468
4) the 3rd layer - Array[2] = 4
6569
1 <-- the 1st layer
66-
1 1 [1] <-- the 2nd layer, which has 1 out of the bound
67-
1 1 1 [1] [1] <-- the 3rd layer, which has 2 out of the bound
70+
1 1 [1] <-- the 2nd layer, which has 1 out of the boundary
71+
1 1 1 [1] [1] <-- the 3rd layer, which has 2 out of the boundary
6872
1 1 1 <-- bottom
73+
74+
now, we have Array[2] is 4
6975
70-
5) Now, the rest layers no need to be cacluated, they all are `3`
71-
So far, we spent 9 of `1`, we still have 9, so 9/3 = 3
72-
73-
6) Finally, the maximum of Array[2] = 4 + 3 = 7
76+
5) Now, the rest layers no need to be cacluated, they all are `3`.
77+
Since 4), we spent 9 of `1`, we still have 18 - 9 = 9 of `1`
78+
So, we can have 9/3 = 3 layer.
79+
80+
6) Finally, the maximum of Array[2] = 4 + 3 = 7
7481
*/
7582

7683
class Solution {

0 commit comments

Comments
 (0)