While considering no. of test cases , is it right to print the output for each test case as soon as I get the input for that particular test case ? Or should I use an array to store all outputs and display it at last?
It doesn’t really matter. As long as the output is displayed in the correct order you are fine.