Created
November 19, 2016 00:55
-
-
Save jianminchen/d438d60381f2193d0dfba3a7fa10137c to your computer and use it in GitHub Desktop.
HackerRank - university codesprint - Array construction - add more debug info - figure out source code line 118, line 119 n-p meaning.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
w[p, sum, diffsum] is not true w[0,0,0] | |
For loop (A - E): for(; i<=s;i++) i=0 s=3 | |
n-p=? 3 | |
iterate on i =0 | |
A: review sum, diffsum 0 0 | |
B: newSum, newDiffSum 0 0 | |
C: i, n, p i=0 n=3 p=0 | |
D-set A[p]=i, A[p]=0 where p=0 and i=0 | |
D-Normal: loop start to end: From 0 to 3 current i = 0 and arguments:0 0 1 | |
E: Array A is [0,0,0] | |
F: recursive call construct - arguments: (A,0,0,1) | |
w[p, sum, diffsum] is not true w[1,0,0] | |
i=A[p-1], p=1, i=0; | |
For loop (A - E): for(; i<=s;i++) i=0 s=3 | |
n-p=? 2 | |
iterate on i =0 | |
A: review sum, diffsum 0 0 | |
B: newSum, newDiffSum 0 0 | |
C: i, n, p i=0 n=3 p=1 | |
D-set A[p]=i, A[p]=0 where p=1 and i=0 | |
D-Normal: loop start to end: From 0 to 3 current i = 0 and arguments:0 0 2 | |
E: Array A is [0,0,0] | |
F: recursive call construct - arguments: (A,0,0,2) | |
w[p, sum, diffsum] is not true w[2,0,0] | |
i=A[p-1], p=2, i=0; | |
For loop (A - E): for(; i<=s;i++) i=0 s=3 | |
n-p=? 1 | |
iterate on i =0 | |
A: review sum, diffsum 0 0 | |
B: newSum, newDiffSum 0 0 | |
C: i, n, p i=0 n=3 p=2 | |
D-set A[p]=i, A[p]=0 where p=2 and i=0 | |
D-Normal: loop start to end: From 0 to 3 current i = 0 and arguments:0 0 3 | |
E: Array A is [0,0,0] | |
F: recursive call construct - arguments: (A,0,0,3) | |
p==n return 0 whereas p=3 n=3 | |
n-p=? 1 | |
iterate on i =1 | |
A: review sum, diffsum 0 0 | |
B: newSum, newDiffSum 1 2 | |
C: i, n, p i=1 n=3 p=2 | |
D-set A[p]=i, A[p]=1 where p=2 and i=1 | |
D-Normal: loop start to end: From 0 to 3 current i = 1 and arguments:1 2 3 | |
E: Array A is [0,0,1] | |
F: recursive call construct - arguments: (A,1,2,3) | |
p==n return 0 whereas p=3 n=3 | |
n-p=? 1 | |
iterate on i =2 | |
A: review sum, diffsum 0 0 | |
B: newSum, newDiffSum 2 4 | |
C: i, n, p i=2 n=3 p=2 | |
D-set A[p]=i, A[p]=2 where p=2 and i=2 | |
D-Normal: loop start to end: From 0 to 3 current i = 2 and arguments:2 4 3 | |
E: Array A is [0,0,2] | |
F: recursive call construct - arguments: (A,2,4,3) | |
p==n return 0 whereas p=3 n=3 | |
n-p=? 1 | |
iterate on i =3 | |
A: review sum, diffsum 0 0 | |
B: newSum, newDiffSum 3 6 | |
C: i, n, p i=3 n=3 p=2 | |
D-Exception: newSum, newDiffSum are bigger than s, k 3 6 exit for loop. | |
return 0 | |
n-p=? 2 | |
iterate on i =1 | |
A: review sum, diffsum 0 0 | |
B: newSum, newDiffSum 2 2 | |
C: i, n, p i=1 n=3 p=1 | |
D-set A[p]=i, A[p]=1 where p=1 and i=1 | |
D-Normal: loop start to end: From 0 to 3 current i = 1 and arguments:1 1 2 | |
E: Array A is [0,1,2] | |
F: recursive call construct - arguments: (A,1,1,2) | |
w[p, sum, diffsum] is not true w[2,1,1] | |
i=A[p-1], p=2, i=1; | |
For loop (A - E): for(; i<=s;i++) i=1 s=3 | |
n-p=? 1 | |
iterate on i =1 | |
A: review sum, diffsum 1 1 | |
B: newSum, newDiffSum 2 2 | |
C: i, n, p i=1 n=3 p=2 | |
D-set A[p]=i, A[p]=1 where p=2 and i=1 | |
D-Normal: loop start to end: From 1 to 3 current i = 1 and arguments:2 2 3 | |
E: Array A is [0,1,1] | |
F: recursive call construct - arguments: (A,2,2,3) | |
p==n return 0 whereas p=3 n=3 | |
n-p=? 1 | |
iterate on i =2 | |
A: review sum, diffsum 1 1 | |
B: newSum, newDiffSum 3 4 | |
C: i, n, p i=2 n=3 p=2 | |
D-set A[p]=i, A[p]=2 where p=2 and i=2 | |
D-Normal: loop start to end: From 1 to 3 current i = 2 and arguments:3 4 3 | |
E: Array A is [0,1,2] | |
F: recursive call construct - arguments: (A,3,4,3) | |
sum == s && diffsum == k - find the solution! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment