I was going through the editorial at ZCO16002 - Editorial and I have some doubts regarding some pieces of code given there.
Note:- The following are just some parts of the code given in the editorial.
return dp[i][j] = 2;
if (i < 0 || j < 0 || i >= n || j >= n) return 0; if (dp[i][j] != -1) return dp[i][j]; else if (i == 0) return dp[i][j] = 2; else
As you can see the function returns dp[i][j] = 2, but what I have learnt till now is that a function returns a value according to its type whereas here the function is assigning a value to another variable, how is this possible?
Then in the second part, I saw an ‘if’ followed by another ‘if’ and then an ‘else if’, so my doubt is that which ‘if’ statement serves as the basis for the ‘else if’ and ‘else’ statement? And is it alright to use an ‘if’ followed by some more ‘if’ and then using ‘else if’?