A unival tree (short for “universal value tree”) is a tree in which all nodes have the same value.
Given the root of a binary tree, determine how many unival subtrees it contains.
For example, the following tree has 5 unival subtrees:
January 6, 2025 | Binary Tree, dsa, DSA Sheet, Google | No comments
An XOR-linked list is a memory-efficient version of a doubly linked list. Instead of each node storing separate next and prev pointers, each node contains a single field called both, which stores the result of the XOR operation on the memory addresses of the next and previous nodes.
January 4, 2025 | dsa, DSA Sheet, Google | No comments
Given the root of a binary tree, create two functions:
serialize(root) – Converts the binary tree into a string representation.
deserialize(s) – Reconstructs the binary tree from its string representation.
January 1, 2025 | array, dsa, DSA Sheet, Google | No comments