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

Method createStackR

java/Chapter 9/Question9_10/Question.java:19–41  ·  view source on GitHub ↗
(Box[] boxes, Box bottom)

Source from the content-addressed store, hash-verified

17 }
18
19 public static ArrayList<Box> createStackR(Box[] boxes, Box bottom) {
20 int max_height = 0;
21 ArrayList<Box> max_stack = null;
22 for (int i = 0; i < boxes.length; i++) {
23 if (boxes[i].canBeAbove(bottom)) {
24 ArrayList<Box> new_stack = createStackR(boxes, boxes[i]);
25 int new_height = stackHeight(new_stack);
26 if (new_height > max_height) {
27 max_stack = new_stack;
28 max_height = new_height;
29 }
30 }
31 }
32
33 if (max_stack == null) {
34 max_stack = new ArrayList<Box>();
35 }
36 if (bottom != null) {
37 max_stack.add(0, bottom);
38 }
39
40 return max_stack;
41 }
42
43 public static ArrayList<Box> createStackDP(Box[] boxes, Box bottom, HashMap<Box, ArrayList<Box>> stack_map) {
44 if (bottom != null && stack_map.containsKey(bottom)) {

Callers

nothing calls this directly

Calls 3

stackHeightMethod · 0.95
canBeAboveMethod · 0.80
addMethod · 0.45

Tested by

no test coverage detected