MCPcopy Create free account
hub / github.com/careercup/ctci / height

Method height

python/Chapter 9/Question9_10/tallest_stack.py:61–75  ·  view source on GitHub ↗

Return the height of a valid stack of Boxes. The Boxes must be given in a sorted sequence, where the first element is the bottom of the stack and the last one its top. In other words: the box at index i must be strictly larger in width, height and depth than the box

(seq)

Source from the content-addressed store, hash-verified

59
60 @staticmethod
61 def height(seq):
62 """ Return the height of a valid stack of Boxes.
63
64 The Boxes must be given in a sorted sequence, where the first element
65 is the bottom of the stack and the last one its top. In other words:
66 the box at index i must be strictly larger in width, height and depth
67 than the box at index i + 1. AssertionError is raised otherwise.
68
69 """
70
71 if __debug__:
72 for index in xrange(0, len(seq) - 1):
73 assert seq[index] > seq[index + 1]
74
75 return sum(box.height for box in seq)
76
77 @memoize
78 def find_tallest(self):

Callers 1

find_tallestMethod · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected