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 | 591 Views, 29144 Search Bots | 119 Words
| Browse | Archive
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Problem, Data Structures and Algorithms, | English | Home Page | Category: Computing | 591 Views, 29144 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 | 591 Views, 29144 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
- Algorithm Interview: Lowest Common Ancestor of 2 Nodes in Binary Tree
- Daily Interview Problem: Merge K Sorted Linked Lists
- Algorithm Interview Question: Symmetric k-ary Tree
- Daily Interview Problem: Circle of Chained Words
- Maximum In A Stack
- Kaprekar
- PHP Unit Tests on VPS Server
- [Daily Problem] Add two numbers as a linked list
- Fibonacci coding
- Daily Interview Question: Create a Simple Calculator
©2006~2024 SteakOverCooked - 0.01245 Seconds(s) - 1545.583 KB/s - 20 Online Memory: 492.38 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 !