To the Top
File:  root - text - article - 2020 - 02 - binary-tree-level-with-minimum-sum.txt
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | English | Home Page | Category: Computing | 156 Views, 18999 Search Bots | 111 Words

Subscribe to Feed Burner | Browse | Archive
Hi, here's your problem today. This problem was recently asked by Twitter:

You are given the root of a binary tree. Find the level for the binary tree with the minimum sum, and return that value.

For instance, in the example below, the sums of the trees are 10, 2 + 8 = 10, and 4 + 1 + 2 = 7. So, the answer here should be 7.


class Node:
def __init__(self, value, left=None, right=None):
self.val = value
self.left = left
self.right = right

def minimum_level_sum(root):
# Fill this in.

# 10
# / \
# 2 8
# / \ \
# 4 1 2
node = Node(10)
node.left = Node(2)
node.right = Node(8)
node.left.left = Node(4)
node.left.right = Node(1)
node.right.right = Node(2)

print minimum_level_sum(node)
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | English | Home Page | Cateogry: Computing | 156 Views, 18999 Search Bots | 111 Words Subscribe to Feed Burner

Related Articles

  1. Staying on a Chess Board
  2. Daily Interview Question: Create a Simple Calculator
  3. Daily Interview Puzzle: Ways to Traverse a Grid
  4. Detect Linked List Cycle
  5. Number of Ways to Climb Stairs
  6. [Daily Problem] Longest Palindromic Substring
  7. Making a Height Balanced Binary Search Tree
  8. Linode Support Ticket 10029540 - Other - Important Notice Regarding Ubuntu 17.10 Image
  9. Daily Interview Problem: Room scheduling
  10. Algorithm Interview: Level Order Traversal of Binary Tree

Comments (0)

Your Email (Domain Part Not Exposed):

Your Comments:

Privately By Mail Colors More Smileys S x y @

Verification (Click Image 2 Refresh):

    Be the first one to comment this page !


Page Edited: October 30 2020 14:21:09 | RSS Subscription
How to Cook a Perfect Steak? | <meta name="robots" content="noindex, follow" />