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 | 589 Views, 29084 Search Bots | 119 Words
| Browse | Archive
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Problem, Data Structures and Algorithms, | English | Home Page | Category: Computing | 589 Views, 29084 Search Bots | 119 Words
| 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.
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Problem, Data Structures and Algorithms, | English | Home Page | Cateogry: Computing | 589 Views, 29084 Search Bots | 119 Words 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)
Related Articles
- [Daily Problem] Remove Consecutive Nodes that Sum to 0
- Daily Interview Question: Edit Distance
- Progess made
- CPU Utilization
- Compare Version Numbers
- Daily Interview Problem: Reconstrunct Binary Tree from Preorder and Inorder Traversals
- Algorithm Interview: String Compression
- Fibonacci coding
- Daily Interview Problem: Full Binary Tree
- YES!!
©2006~2024 SteakOverCooked - 0.0085 Seconds(s) - 2173.076 KB/s - 43 Online Memory: 493.42 KB
18:54:01 up 13 days, 18:33, 2 users, load average: 0.98, 0.86, 0.73 - Server PHP Version: 7.4.33
How to Cook a Perfect Steak? | <meta name="robots" content="noindex, follow" />
18:54:01 up 13 days, 18:33, 2 users, load average: 0.98, 0.86, 0.73 - Server PHP Version: 7.4.33
Comments (0)
Read & Write - Normal - Mini - Post - All Comments - Statistics
Be the first one to comment this page !