I have not run your program, but I take it from you that your code is working for small input arrays.
According to the specs of that exercise, the sizes of the two arrays can be 10^5, so if you get such arrays, and r1, r1 , c1 and c2 are 1 and max (and knowing HackerRank a little, I'm sure they will give you these) that means that you are trying to calculate 10^10 gcd's, and that number is way too large to calculate them all. You can test whether that is the problem, just add to your 'calGCDSubMatrix' method some print statements, for instance what r1, c1, r2 and c2 are, and the number of the calculations that must be performed ((r2 - r1 + 1) * (c2 - c1 + 1)), and print out, say, every 1000th of these calculations. That gives you an idea how fast it goes.
At least you can see if your code is still running, and how long that submatrix will be going to take.
I've executed your program and it finishes without error. To confirm that the program is completed, try adding a Sysout.out.println() to the end of the main() method:
This was the output I got:
All things are lawful, but not all things are profitable.
Our first order of business must be this tiny ad:
ScroogeXHTML 8.7 - RTF to HTML5 and XHTML converter