Timestamps
0:00 Intro
0:54 Thought Process
8:07 Programming (Recursive)
27:45 Outro
Code:
class Solution:
def leastBricks(wall):
brickSplitDict = {}
allRowSums = []
for row in wall:
lengthSum = 0
rowSum = []
for brickLength in range(len(row) - 1):
lengthSum += row[brickLength]
if lengthSum not in brickSplitDict:
brickSplitDict[lengthSum] = 1
else:
brickSplitDict[lengthSum] += 1
rowSum.append(lengthSum)
allRowSums.append(rowSum)
maxKey = 0
maxValue = 0
for key, value in brickSplitDict.items():
if maxValue != max(maxValue, value):
maxKey = key
maxValue = max(maxValue, value)
return len(wall) - maxValue