My toString() method's time complexity is supposed to be O(Row*Col). What I can see from the code is that there are two for-loops where one of them is running through the rows and the other one is running through the cols.
Does the declaration of String variables take a lot of time? I have written code but does it have that exact time complexity?
toString()method. Create a method calledprintBoard()instead.toString()is for returning a string representation of the object, e.g. for debugging, so a return value of "board(10 x 15)" would be appropriate.secondLine1 += "|" + " ".subString(0," ".length() - temp.length()) + temp;. String.format is quite slow. Externalize this string " "