To the Top
File:  root - text - article - 2019 - 10 - floor-and-ceiling-of-a-binary-search-tree.txt
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Problem, Data Structures and Algorithms, | English | Home Page | Category: Computing | 302 Views, 20486 Search Bots | 119 Words

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

Given an integer k and a binary search tree, find the floor (less than or equal to) of k, and the ceiling (larger than or equal to) of k. If either does not exist, then print them as None.

Here is the definition of a node for the tree.


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

def findCeilingFloor(root_node, k, floor=None, ceil=None):
# Fill this in.

root = Node(8)
root.left = Node(4)
root.right = Node(12)

root.left.left = Node(2)
root.left.right = Node(6)

root.right.left = Node(10)
root.right.right = Node(14)

print findCeilingFloor(root, 5)
# (4, 6)
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Problem, Data Structures and Algorithms, | English | Home Page | Cateogry: Computing | 302 Views, 20486 Search Bots | 119 Words Subscribe to Feed Burner

Related Articles

  1. Daily Interview Problem: Deepest Node in a Binary Tree
  2. Algorithm Interview: Smallest Number that is not a Sum of a Subset of List
  3. PHP Unit Tests on VPS Server
  4. Skip the readings, focus on problems. And use all the hints!
  5. Daily Interview Problem: Reverse Words in a String
  6. Top K Frequent words
  7. [Daily Problem] Longest Palindromic Substring
  8. Algorithm Interview: String Compression
  9. Daily Interview Puzzle: Minimum Size Subarray Sum
  10. Progess made

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" />