Binary Tree Implemented with Option<Box<T>>. Box is a smart pointer that allocates on the heap, ideal for recursive types that would ohterwise have unbounded size. LeetCode often uses Option<Rc<RefCell<T>>>, which is quite bloated. #[derive(PartialEq)] enum ChildSide {...
A Trie (pronounced "try") is a specialized tree structure designed for efficient string storage and retrieval. This data structure excels at operations like autoocmplete suggestions and spell checking, where prefix-based lookups are frequent. This implementation provides a Trie class with...
Data Structure Overview A Trie (prefix tree) is an efficient ordered tree data structure commonly used for retrieving values associated with string keys. In this implementation, each node in the tree represents a single character of a key. A boolean flag distinguishes intermediate nodes from termina...
Problem A: Building Height Comparison Given an array of building heights, find the first building taller than the first one. #include <cstdio> const int MAX_SIZE = 105; int heights[MAX_SIZE]; int main() { int n; scanf("%d", &n); int result = -1; for (int i = 1; i <= n; i++) {...
Givan a colection of words, the objective is to detremine the shortest unique prefix for each word. A prefix is a substring starting from the first character. For instance, the word "carbon" has prefixes: "c", "ca", "car", "carb", "carbo",...