I submitted two solution for a problem which only differ by two lines of seemingly inconsequential nature. One solution gives TLE but other one passes. The solution that gives TLE is NOT using Scanner class. The solution that passes has two additional lines which import and initialize a Scanner class. The additional lines are given below. If anyone can provide a reason for this, it will help a lot. Thanks.
import java.util.Scanner; Scanner in = new Scanner(System.in);
Solution which initializes Scanner obj (passes):
Solution without Scanner obj (gives TLE):