Coding Exercise Posts - page 39 of 43

Recent posts

Elephant Tree

less than 1 minute read

Given a binary tree root, return the same tree except every node’s value is replaced by its original value plus all of the sums of its left and right subtrees.

Dice Throw

less than 1 minute read

Given integers n, faces, and total, return the number of ways it is possible to throw n dice with faces faces each to get total.

Diagonal Tree Traversal

less than 1 minute read

Given a binary tree root, return the sum of each of the diagonals in the tree starting from the top to bottom right.

Detect Voter Fraud

less than 1 minute read

Given a two dimensional list of integers votes, where each list has two elements [candidate_id, voter_id], report whether any voter has voted more than once.

Detect the Only Duplicate in a List

less than 1 minute read

You are given a list nums of length n + 1 picked from the range 1, 2, ..., n. By the pigeonhole principle, there must be a duplicate. Find and return it. The...

Delete Even Leaves

less than 1 minute read

Given a binary tree root, repeatedly delete all leaves that have even values. That is, if after deletions, a node becomes a leaf with an even value, it too s...

Cutting Binary Search Tree

less than 1 minute read

Given a binary search tree root, an integer lo, and another an integer hi, remove all nodes that are not between [lo, hi] inclusive.

Counting Maximal Value Roots in Binary Tree

less than 1 minute read

Given a binary tree root, count and return the number of nodes where its value is greater than or equal to the values of all of its descendants.

Count Next Element

less than 1 minute read

Given a list of integers nums, return the number of elements x there are such that x + 1 exists as well.

Count BST Nodes in a Range

less than 1 minute read

Given a binary search tree root, and integers lo and hi, return the count of all nodes in root whose values are between [lo, hi] (inclusive).

Contained Interval

1 minute read

You are given a two-dimensional list of integers intervals where each element is an inclusive interval [start, end]. Return whether there’s an interval which...