I was trying to solve a programming puzzle
here, and i wrote to codes with same logic but different data structures. They are as follow.
and
The second code where i use ArrayList worked only for two
test cases but the one where i used arrays worked for all cases.Here are the outupts of my codes
output1 and
output2 respectively. Can anyone please explain why this is happening even when i am using the same logic.