Agreed. Very few problems in LeetCode specify the numerical constraints, usually, any number within the int range can appear. This is just okay, but I am not very comfortable with the fact that very very few problems specify the input size also. You can only "feel" how large the input is (1) by your intuition, (2) through the test case you TLEed. Specifically, for (2), if you are lucky, you can just read the "n" from the first line, and if you are not, you have to search how many commas there are in the given array to know the input size. This seems unfriendly, and I don't think knowing the input size precisely is a bad thing.
Clearly, one can first come up with an O(n^2 * k) DP solution, and then optimize it to an O(nk) one. The good part for LeetCode is that it has a test case for k = MAX_INT, which simply leads to an O(min(nk, n^2)) algorithm. But the bad part is that all the extreme test cases only focus on the following two aspects:
Very large n and a small k,
Very large n and very large k, where k >= n / 2.
The time limit is set to let the O(min(nk, n^2)) solution fail for the second case. This somehow forces one to break his/her solution into two branches, i.e., use the above method to solve case 1, and use the O(n) solution of Stock ii to hack case 2.
Most of the existing solutions posted online are all on this track, but I personally think this trick is ugly, and it is unnecessary to design the test cases in such a way to gruffly combine two problems. For instance, when k is sufficiently large, but k < n / 2, we cannot apply the O(n) solution, and the O(nk) one turns out to be slow as well. This case can simply crash many existing solutions, though it is not included in the OJ.
I am no offensive to this problem or the existing solutions. I just want to use it as an example to show the importance of being specific to the input size. Let me know if you disagree with me, or you have any other ideas.
I don't mean anything special by "environment". I just mean the Python editor on OJ. In the past, I've been able to copy and paste the class and functional definition to my own editor and tabs would be copied over. Now I find that 4 spaces are copied instead. I thought that maybe OJ had updated, but maybe its my editor that updated without me knowing.
@vinod23 Yes, the shortcut is Ctrl+' and Ctrl+Enter for Run code and Submit solution respectively (Or Cmd+' and Cmd+Enter for Mac). When you hover over the Run code and Submit solution buttons, you should see the keyboard shortcut hint being shown as a tooltip. Does that work for you?
@LHearen NodeBB is the BBS software this forum is using, it's open source and I'm studying its source code recently then surprisingly found that leetcode's forum is using it too. sorry for confusing you. :)