To the Top
File:  root - text - article - 2019 - 11 - get-all-values-at-a-certain-height-in-a-binary-tree.txt.txt
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | English | Home Page | Category: Computing | 227 Views, 20736 Search Bots | 81 Words

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

Given a binary tree, return all values given a certain height h.

Here's a starting point:


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

def valuesAtHeight(root, height):
# Fill this in.

# 1
# / \
# 2 3
# / \ \
# 4 5 7

a = Node(1)
a.left = Node(2)
a.right = Node(3)
a.left.left = Node(4)
a.left.right = Node(5)
a.right.right = Node(7)
print valuesAtHeight(a, 3)
# [4, 5, 7]
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | English | Home Page | Cateogry: Computing | 227 Views, 20736 Search Bots | 81 Words Subscribe to Feed Burner

Related Articles

  1. Binary Tree Level with Minimum Sum
  2. Daily Interview Problem: Longest Substring With K Distinct Characters
  3. Sorting a list with 3 unique numbers
  4. Sort a Partially Sorted List
  5. Print a tree level-by-level, with line-breaks
  6. Daily Interview Question: Find Cycles in a Graph
  7. Daily Interview Question: Edit Distance
  8. Daily Interview Problem: Trapping Rainwater
  9. Algorithm Interview: Subarray With Target Sum
  10. Algorithm Interview Question: Find the Single Element in an Array of Duplicates

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: May 11 2024 14:36:49 | RSS Subscription
How to Cook a Perfect Steak? | <meta name="robots" content="noindex, follow" />