Convert a sorted linked list to a height-balanced BSTCodingYou get the head of a singly linked list whose values are in strictly increasing order. Build a binary search tree holding exactly those values that is height-balanced: at every…
Last asked Nov 2026
+1
Settle group debts with the fewest transfersCodingA group of friends shared costs, and the record of who owes whom is a list of debts (debtor, creditor, amount). Return the smallest number of money transfers that settles every…
Expand placeholders from a variable storeCodingImplement a small store of variables with template substitution, as in a shell startup file where export NAME="Tom" defines a variable. Any string can refer to a variable as…
Last asked Nov 2026
Maximum root-to-leaf path sum in a binary treeCodingGiven a non-empty binary tree whose nodes hold numbers, return the largest sum of values along a path that starts at the root and ends at a leaf (a node with no children). Values…
Validate a binary search treeCodingDecide whether a binary tree is a valid binary search tree: for every node, every value in its left subtree is strictly smaller and every value in its right subtree is strictly…
Parse nested generic type expressionsCodingA message type is written like a generic type: a name made of letters and digits, optionally followed by angle brackets holding one or more comma-separated child types, nested to…
Last asked Sep 2026
Binary search tree keys within a rangeCodingGiven a binary search tree and an inclusive range [low, high], return every key in the tree that lies in the range, in ascending order. Use the search tree's ordering so you skip…
Delete leaves with a target value, repeatedlyCodingGiven a binary tree and a target value, delete every leaf that holds the target. Deleting a leaf can turn its parent into a leaf; if that parent also holds the target, delete it…
Last asked Sep 2026
Render nested JSON in a code-style viewerCodingBuild a read-only React component that shows a JSON value the way a code editor would: indentation, braces and brackets, keys and values coloured by type, and objects and arrays…
Last asked Sep 2026
Range sum of a binary search treeCodingGiven a binary search tree with distinct values and two bounds low and high, return the sum of every node value v with low <= v <= high. Skip subtrees that can't contain any…
Last asked Sep 2026
+1
Lowest common ancestor of a binary treeCodingGiven a binary tree whose values have no ordering, and two distinct nodes in it, return their lowest common ancestor: the deepest node that has both nodes in its subtree. A node…
Filter an n-ary tree by substring and render it indentedCodingEach node of an n-ary tree holds a string value and a list of children. First write a function that removes every node whose value contains a given substring, together with its…
Last asked Sep 2026
+2
Insert plus, times and parentheses to reach a targetCodingYou are given an equation whose left side is a sequence of non-negative integers with no operators between them, and whose right side is a target. For example: 2 3 4 = 20.
Simplify an arithmetic expression treeCodingYou get the root of an expression tree. Every internal node holds a binary operator (+, - or ) and has exactly two children; every leaf holds an integer constant or a variable…
Format a forest of nested commentsCodingYou get a list of comments in no particular order. Each comment has an id, the id of the comment it replies to (or none for a top-level comment), and its text.
Last asked Aug 2026
Print each tree node's level and whether it is balancedCodingYou get a binary tree stored as a zero-based level-order array: the children of index i are at 2i + 1 and 2i + 2, and None marks a missing node. For every node, report its level…
Last asked Aug 2026
Nested list weight sum, parsed from a stringCodingA nested list holds integers and other lists. Return the sum of every integer multiplied by its depth, where the outermost list is depth 1.
Last asked Aug 2026
+1
Minimum root-to-leaf path sumCodingGiven the root of a binary tree whose nodes hold integers (values may be negative), find the root-to-leaf path with the smallest sum. A leaf is a node with no children.
Last asked Aug 2026
Serialize and deserialize an N-ary treeCodingIn a rooted N-ary tree each node has any number of children, kept in a fixed order. Design a string format for such trees and implement both directions: serialize turns a tree…
Last asked Jul 2026
Accessible expand-and-collapse tree in ReactCodingBuild a React component that renders nested data as a tree. Branches can be expanded and collapsed to any depth, and each branch keeps its own open or closed state while the user…
Last asked Jul 2026
Regular expression matching with dot and starCodingDecide whether a whole string matches a pattern. The pattern has lowercase letters, . which matches any single character, and which matches zero or more copies of the element…
Last asked Jul 2026
+1
Build a quadtree over a square gridCodingA quadtree splits a square region of the plane into four quadrants, recursively: every node is either a leaf or has exactly four children. Build one yourself, in two versions.
Last asked Jun 2026
+1
Deep equality of two recordsCodingWrite a function that decides whether two records are deeply equal. A record is a nested value built from maps, lists and scalars, like parsed JSON.
Last asked Jun 2026
Lowest common ancestor in a BST and in a binary treeCodingGiven the root of a tree and two values that occur in it, return the value of their lowest common ancestor: the deepest node that has both in its subtree (a node counts as its…
Last asked Jun 2026
Kth largest perfect binary subtreeCodingIn a binary tree, a subtree (a node and all its descendants) is perfect when every internal node has two children and all leaves are on the same level, so it has 2^h - 1 nodes…
Last asked Jun 2026
Every ordered sum of 1s and 2s that makes nCodingGiven a non-negative integer n, list every ordered sequence of 1s and 2s whose sum is n. Order matters, so [1, 2] and [2, 1] are different sequences.
Last asked Jun 2026
Implement a JSON parserCodingWrite a parser that turns a JSON string into native values: objects become dictionaries, arrays become lists, and strings, numbers, true, false and null become the matching…
Last asked Jun 2026
Nested todo list with subtasksCodingBuild an in-memory todo list where any task can hold subtasks, nested to any depth. Users add tasks, complete them and print the list with its hierarchy.
Last asked Jun 2026
+1
Diameter of a binary treeCodingReturn the number of edges on the longest path between any two nodes of a binary tree. The path doesn't have to pass through the root. Solve it in one pass over the tree. Unless…
Last asked May 2026
Merge two named treesCodingEach tree node is a dictionary with three keys: name (a string), value (an integer) and children (an ordered list of nodes). Given two such trees t1 and t2, build a new merged…
Last asked May 2026
Knockout tournament by rank, then build the bracketCodingPlayers enter a single-elimination tournament in a given starting order. Each player has a rank, and a smaller rank is a better player who always wins. In every round, neighbours…
Last asked May 2026
Validate a parsed config against field descriptorsCodingA configuration file has already been parsed from YAML or JSON into nested dicts, lists and primitive values. A set of descriptors says what a valid config looks like: for each…
Last asked Apr 2026
Flatten a nested list iteratorCodingA nested list holds integers and other nested lists, to any depth. Produce its integers in left-to-right, depth-first order. First return them all as one flat list. Then provide…
Last asked Apr 2026
Implement pow(x, n) with fast exponentiationCodingCompute x raised to an integer power n, which may be negative, using O(log n) multiplications instead of multiplying n times. Unless you agree on a different interface with the…
Last asked Apr 2026
Is every 3+ letter piece of a string a dictionary word?CodingYou get a lowercase string s and a dictionary of valid English words. Check whether every piece of s of length 3 or more is acceptable, first as an exact word and then, in the…
Last asked Mar 2026
Tower of Hanoi movesCodingn disks of different sizes are stacked on peg A, largest at the bottom. Pegs B and C are empty. Move one disk at a time and never put a larger disk on a smaller one. Return the…
Last asked Mar 2026
Generate all permutations of distinct integersCodingGiven a list of distinct integers, return every possible ordering of it. Unless you agree on a different interface with the interviewer, assume: - permutations(nums: listint) -…
Last asked Mar 2026
Flatten and rebuild nested Python containersCodingWrite two functions. flatten takes an arbitrarily nested mix of lists, tuples and dicts whose leaves are integers and returns the integers as one flat list, in traversal order…
Last asked Mar 2026
Serialize an expression tree with the fewest parenthesesCodingGiven a binary expression tree whose leaves are numbers or variables and whose internal nodes are the operators +, -, and /, print it as an infix expression with only the…
Last asked Feb 2026
Nested list weight sumCodingA nested list holds integers and other nested lists, to any depth. Return the sum of every integer multiplied by its depth. Integers directly in the outer list have depth 1, those…
Last asked Feb 2026
Decode a string with nested repeat countsCodingAn encoded string uses k... to mean the bracketed part repeated k times, and brackets may nest. Letters outside brackets appear once. Return the decoded string. Unless you agree…
Last asked Feb 2026
Symmetric tree: is a binary tree its own mirrorCodingGiven the root of a binary tree, return whether the tree is a mirror image of itself around its centre. Unless you agree on a different interface with the interviewer, assume: -…
Last asked Feb 2026
Maximum path sum in an N-ary treeCodingEach node of an N-ary tree holds an integer, which may be negative, and has any number of children. A path is a sequence of nodes joined by parent–child edges that visits each…
Last asked Jan 2026
Winner of a stack-merging gameCodingTwo players play a game on a row of stacks of coins. On a turn, a player picks two adjacent stacks whose combined size is at most limit and merges them into one stack in the same…
Last asked Jan 2026
All subsets of a list with duplicatesCodingReturn every distinct subset of an integer list that may contain duplicate values. Two subsets are the same if they contain the same values with the same multiplicities, and each…
Last asked Jan 2026
Build a binary tree from a parenthesized stringCodingA string encodes a binary tree: an integer (possibly negative) followed by zero, one or two subtrees, each in parentheses and encoded the same way. The first pair of parentheses…
Last asked Jan 2026
Lowest common ancestor in an N-ary treeCodingGiven the root of a rooted N-ary tree (each node has any number of children) and two distinct nodes p and q in it, return their lowest common ancestor: the deepest node that has…
Last asked Dec 2025
Look up a value in a nested object by pathCodingGiven a nested object made of maps and lists inside each other, and a path string such as "a.b.0.c", return the value at that path. Each dot-separated part is a key when the…
Last asked Oct 2025
Print a directory tree with indentationCodingYou get the root of a file system tree. Each node is a directory, which can have children, or a file, which has none. Print the whole tree starting from the root, one entry per…
Last asked Oct 2025
Fill a second tree with subtree sums of the firstCodingYou get the roots of two complete binary trees with exactly the same shape. Change the values of the second tree so that each node holds the sum of all values in the subtree of…
Last asked Sep 2025
Permutations of a list with duplicatesCodingGiven a list of integers that may contain repeated values, return every distinct ordering of it, with no ordering repeated in the output. Unless you agree on a different interface…
Last asked Sep 2025
Deep clone an objectCodingWrite a deep clone function for nested JavaScript values without using JSON serialization or a library. Changing anything in the copy must never change the original. Unless you…
Turn dotted keys into a nested dictionaryCodingA model checkpoint lists its parameters under flat dotted names such as layer1.attention.qproj.weight, layer1.attention.kproj.weight and layer1.mlp.fc1.weight. Write a Python…
Last asked Aug 2025
Target sum: count sign assignments that reach a targetCodingGiven an array of non-negative integers and a target T, put a + or - in front of every number. Count how many sign assignments make the expression equal T. Two assignments are…
Construct binary tree from inorder and postorder traversalCodingGiven the inorder and postorder traversals of a binary tree whose values are all distinct, rebuild the tree and return its root. Unless you agree on a different interface with the…
Last asked Aug 2025
Collapsible JSON viewer in ReactCodingIn an hour of React, build a component that takes a JSON string and shows it as a pretty-printed, read-only tree. Every nested object and array gets a toggle (such as a caret)…
Last asked Jul 2025
Template formatter with plural blocksCodingImplement formattemplate(text: str, keys: liststr, values: liststr) - str. keysi maps to valuesi; all values are strings. text can contain two kinds of expressions in braces: 1…
Last asked Jun 2024
Merge two n-ary trees by child positionCodingImplement mergetrees(root1, root2). It takes the roots of two n-ary trees and returns the root of a new tree that merges them. Each node has an integer val and an ordered list…
Integer to English words, built up by rangeCodingWrite a function that spells out an integer in English words. The interviewer adds the ranges in parts, and later parts should reuse earlier ones, so design for extension from the…
Merge neighbor sums from many binary trees into the lastCodingYou are given a list trees of binary trees (each given by its root, possibly empty). The neighbor sum of a node is its own value plus the values of its left and right children…
+2
Compress an n-ary tree by promoting childrenCodingEach node of an n-ary tree holds a unique integer value and an ordered list of children. You are given the root and a list compressednodes of values. Implement compress(root…