So when I was trying to do TWOFL question I don’t know I was getting RunTimeError for some of the cases and only in subtasks 2 and 3. So I wonder whether this is because of big values. Then somehow in my program I made all value as 1 and traversed it for n=1000 and m=1000. Clearly on my PC I got an error of StackOverFlow. I thought may be my program is going in an infinite recursion so I tried more and couldn’t find why is this happening. Then I thought of looking at one of the accepted codes in CPP and changing it into Java. Still it was giving RunTimeError on same cases. Then I looked at others code of Java and many were getting the same error and hence I was sure that this is only with Java who is doing in recursive fashion.
I hope this will help you.