MCPcopy Index your code
hub / github.com/careercup/ctci / maxRectangle

Method maxRectangle

java/Chapter 18/Question18_13/Question.java:26–48  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

24 * forms a word (reading top to bottom) from the list.
25 */
26 public Rectangle maxRectangle() {
27 // The dimensions of the largest possible rectangle.
28 int maxSize = maxWordLength * maxWordLength;
29
30 for (int z = maxSize; z > 0; z--) {
31 // Find out all pairs i,j less than maxWordLength
32 // such that i * j = z
33 for (int i = 1; i <= maxWordLength; i ++ ) {
34 if (z % i == 0) {
35 int j = z / i;
36 if (j <= maxWordLength) {
37 // Check if a Rectangle of length i and height
38 // j can be created.
39 Rectangle rectangle = makeRectangle(i,j);
40 if (rectangle != null) {
41 return rectangle;
42 }
43 }
44 }
45 }
46 }
47 return null;
48 }
49
50 /* This function takes the length and height of a rectangle as
51 * arguments. It tries to form a rectangle of the given length and

Callers 1

mainMethod · 0.95

Calls 1

makeRectangleMethod · 0.95

Tested by

no test coverage detected