brain

tamnd's digital brain — notes, problems, research

43815 notes

LeetCode 447 - Number of Boomerangs

The problem asks us to count the number of valid boomerangs among a set of distinct 2D points. A boomerang is defined as a tuple (i, j, k) where the distance between point i and point j is equal to the distance between point i and point k.

leetcodemediumarrayhash-tablemath
CF 133A - HQ9+

The task is to analyze a program written in the esoteric HQ9+ language and determine whether executing it will produce any visible output. The program is provided as a single string consisting of printable ASCII characters.

codeforcescompetitive-programmingimplementation
LeetCode 2026 - Low-Quality Problems

The problem gives us a database table named Problems. Each row represents a LeetCode problem and contains three columns:

leetcodeeasydatabase
LeetCode 1105 - Filling Bookcase Shelves

The problem asks us to arrange a sequence of books on a bookshelf with multiple shelves while minimizing the total height of the bookshelf. Each book is described by its thickness and height, and the books must be placed in the given order.

leetcodemediumarraydynamic-programming
LeetCode 1801 - Number of Orders in the Backlog

This problem simulates a simplified stock exchange order book. Each incoming order is either a buy order or a sell order, and each order contains a price and an amount. Orders are processed strictly in the order they appear in the input.

leetcodemediumarrayheap-(priority-queue)simulation
LeetCode 1480 - Running Sum of 1d Array

The problem asks us to compute the running sum, also called the prefix sum, of a one dimensional integer array. For ever

leetcodeeasyarrayprefix-sum
LeetCode 1539 - Kth Missing Positive Number

The problem gives us a strictly increasing array of positive integers, arr, and an integer k. The array does not necessa

leetcodeeasyarraybinary-search
LeetCode 615 - Average Salary: Departments VS Company

This problem asks us to compare the average salary of each department against the company's overall average salary for each month. We are given two tables: Salary and Employee.

leetcodeharddatabase
LeetCode 906 - Super Palindromes

This problem asks us to count how many numbers within a given inclusive range are "super-palindromes". A number is considered a super-palindrome if both of the following conditions are true: 1. The number itself is a palindrome. 2. The number is the square of another palindrome.

leetcodehardmathstringenumeration
LeetCode 742 - Closest Leaf in a Binary Tree

The problem asks us to find the closest leaf node to a given target node k in a binary tree. The input is the root of a binary tree where each node has a unique integer value. A leaf node is defined as any node without children.

leetcodemediumtreedepth-first-searchbreadth-first-searchbinary-tree
LeetCode 1483 - Kth Ancestor of a Tree Node

The problem gives us a rooted tree with n nodes labeled from 0 to n - 1. Instead of providing the tree as adjacency lists or edges, the input is represented using a parent array. For every node i, parent[i] tells us which node is its direct parent.

leetcodehardbinary-searchdynamic-programmingbit-manipulationtreedepth-first-searchbreadth-first-searchdesign
LeetCode 568 - Maximum Vacation Days

This problem asks us to maximize the total number of vacation days over k weeks while traveling between n cities under specific flight constraints. We start in city 0 on the Monday morning of week 0.

leetcodehardarraydynamic-programmingmatrix
LeetCode 294 - Flip Game II

This problem describes a two-player impartial game played on a string consisting only of '+' and '-' characters. A valid move consists of selecting any pair of consecutive "++" characters and flipping them into "--". The players alternate turns.

leetcodemediummathdynamic-programmingbacktrackingmemoizationgame-theory
LeetCode 660 - Remove 9

The problem defines a modified sequence of positive integers where every number containing the digit 9 is removed.

leetcodehardmath
CF 26C - Parquet

We are asked to tile a rectangular floor of size n × m using three types of parquet planks. The first type is a 1×2 horizontal plank, the second is a 2×1 vertical plank, and the third is a 2×2 square plank.

codeforcescompetitive-programmingcombinatoricsconstructive-algorithmsgreedyimplementation
CF 113C - Double Happiness

We are asked to count the numbers in a given interval $l, r$ that are simultaneously prime and expressible as the sum of two positive squares. In simpler terms, for each number in the interval, we need to check two independent properties.

codeforcescompetitive-programmingbrute-forcemathnumber-theory
CF 31B - Sysadmin Bob

We are given a single string that represents multiple email addresses concatenated together with no separators. Each email address has the form A@B, where A and B are non-empty strings consisting of lowercase Latin letters.

codeforcescompetitive-programminggreedyimplementationstrings
LeetCode 126 - Word Ladder II

This problem asks us to find all shortest transformation sequences from beginWord to endWord, where each transformation changes exactly one character and every intermediate word must exist in wordList. We can think of the problem as navigating through a graph.

leetcodehardhash-tablestringbacktrackingbreadth-first-search
CF 100G - Name the album

Aryo wants to choose a title for a new album from a list of candidate names. Some names have already been used in previous years. His decision rule has two layers. If a candidate name has never been used before, that is the best possible choice.

codeforcescompetitive-programming*specialdata-structuresimplementation
LeetCode 232 - Implement Queue using Stacks

The problem asks us to implement a queue using only stack operations. A queue follows the FIFO, First In First Out, principle. The first element inserted into the queue must be the first element removed.

leetcodeeasystackdesignqueue
CF 47B - Coins

We have three coins labeled A, B, and C. Every pair of coins has already been compared once using a balance scale, and each comparison tells us which coin is heavier.

codeforcescompetitive-programmingimplementation
LeetCode 1443 - Minimum Time to Collect All Apples in a Tree

The problem is asking for the minimum time required to collect all apples in a tree, where each edge traversal takes 1 s

leetcodemediumhash-tabletreedepth-first-searchbreadth-first-search
LeetCode 780 - Reaching Points

The problem asks whether it is possible to transform a starting point (sx, sy) to a target point (tx, ty) using a defined set of operations. Specifically, from a point (x, y), you can either move to (x, x + y) or (x + y, y).

leetcodehardmath
LeetCode 653 - Two Sum IV - Input is a BST

This problem gives us the root of a Binary Search Tree (BST) and an integer k. We must determine whether there are two distinct nodes in the tree whose values add up to k.

leetcodeeasyhash-tabletwo-pointerstreedepth-first-searchbreadth-first-searchbinary-search-treebinary-tree
LeetCode 1208 - Get Equal Substrings Within Budget

The problem asks us to determine the longest contiguous substring of s that can be transformed into the corresponding substring of t without exceeding a given budget, maxCost.

leetcodemediumstringbinary-searchsliding-windowprefix-sum
LeetCode 187 - Repeated DNA Sequences

This problem asks us to find all repeated DNA subsequences of a fixed length, specifically length 10, inside a given DNA string. The input is a string s, where each character represents a DNA nucleotide.

leetcodemediumhash-tablestringbit-manipulationsliding-windowrolling-hashhash-function
CF 135B - Rectangle and Square

We are given eight distinct points on the plane. The task is to split them into two disjoint groups of four points each. One group must form a square. The other group must form a rectangle.

codeforcescompetitive-programmingbrute-forcegeometrymath
LeetCode 731 - My Calendar II

The problem asks us to design a calendar system that supports booking time intervals while enforcing one important rule: no point in time may be covered by three events simultaneously. Each event is represented as a half open interval [startTime, endTime).

leetcodemediumarraybinary-searchdesignsegment-treeprefix-sumordered-set
LeetCode 997 - Find the Town Judge

The problem describes a town containing n people labeled from 1 to n. Among these people, there may exist a special person called the town judge. The judge must satisfy two strict conditions: 1. The judge trusts nobody. 2. Every other person trusts the judge.

leetcodeeasyarrayhash-tablegraph-theory
CF 107E - Darts

We have several rectangles on the plane. Each rectangle represents a photo hanging on a wall. The rectangles may overlap, may share edges, may coincide completely, and may also be rotated arbitrarily.

codeforcescompetitive-programminggeometryprobabilities
LeetCode 495 - Teemo Attacking

The problem asks us to calculate the total duration that Ashe is poisoned by Teemo's attacks. Each attack at a given second t causes Ashe to be poisoned for exactly duration seconds, and the poisoning time is inclusive, meaning that the poison effect lasts from time t to t +…

leetcodeeasyarraysimulation
LeetCode 1651 - Hopper Company Queries III

The problem requires computing a rolling 3-month average of ride distance and ride duration from ride data in a ride-hailing company database. We are given three tables: Drivers, Rides, and AcceptedRides.

leetcodeharddatabase
LeetCode 2007 - Find Original Array From Doubled Array

The problem gives us an array called changed, which was supposedly created from another array called original. The transformation process works like this: 1. Take every number in original. 2. Append its doubled value, meaning 2 x. 3. Shuffle all the numbers together.

leetcodemediumarrayhash-tablegreedysorting
LeetCode 1461 - Check If a String Contains All Binary Codes of Size K

The problem gives us a binary string s and an integer k. A binary string contains only the characters '0' and '1'. We mu

leetcodemediumhash-tablestringbit-manipulationrolling-hashhash-function
LeetCode 873 - Length of Longest Fibonacci Subsequence

The problem asks us to find the length of the longest subsequence in a strictly increasing array that forms a Fibonacci-like sequence. A Fibonacci-like sequence follows the rule: for every valid index in the sequence, and the sequence must contain at least three numbers.

leetcodemediumarrayhash-tabledynamic-programming
CF 23D - Tetragon

We are given three points in the plane. Each point is the midpoint of one side of an unknown strictly convex quadrilateral, and all four sides of that quadrilateral have equal length.

codeforcescompetitive-programminggeometrymath
LeetCode 691 - Stickers to Spell Word

Let's dive deep into a detailed technical solution guide for LeetCode 691, following your formatting rules exactly. The problem asks us to construct a target string using letters cut from an unlimited supply of given stickers, where each sticker is a lowercase word.

leetcodehardarrayhash-tablestringdynamic-programmingbacktrackingbit-manipulationmemoizationbitmask
CF 6C - Alice, Bob and Chocolate

We have a row of chocolate bars, and each bar takes a certain amount of time to eat. Alice starts from the left end and keeps moving right. Bob starts from the right end and keeps moving left.

codeforcescompetitive-programminggreedytwo-pointers
LeetCode 68 - Text Justification

This problem asks us to simulate how text is formatted in a text editor when using full justification. We are given an array of words and a target line width called maxWidth.

leetcodehardarraystringsimulation
LeetCode 912 - Sort an Array

The problem asks us to sort an integer array in ascending order without using any built in sorting functions. The result must contain the same elements as the input, but arranged from smallest to largest. The input is an array nums containing integers.

leetcodemediumarraydivide-and-conquersortingheap-(priority-queue)merge-sortbucket-sortradix-sortcounting-sort
CF 19A - World Football Cup

We are given the full results of a football tournament where every pair of teams plays exactly one match. For each match, we know how many goals each side scored. Using the tournament rules, we must determine which teams advance to the knockout stage.

codeforcescompetitive-programmingimplementation
LeetCode 837 - New 21 Game

In this problem, Alice repeatedly draws random numbers until her score reaches at least k. Every draw independently produces an integer between 1 and maxPts, inclusive, and each value is equally likely.

leetcodemediummathdynamic-programmingsliding-windowprobability-and-statistics
CF 73B - Need For Brake

We know the current championship standings before the final race. Every racer already has some number of points, and the last race distributes additional points to the top m finishers.

codeforcescompetitive-programmingbinary-searchgreedysortings
LeetCode 2031 - Count Subarrays With More Ones Than Zeros

This problem asks us to count all subarrays of a binary array nums that contain more 1s than 0s. In other words, for any contiguous slice of the array, if the number of 1s exceeds the number of 0s, it should be counted.

leetcodemediumarrayhash-tablebinary-searchdivide-and-conquerbinary-indexed-treesegment-treemerge-sortordered-set
LeetCode 1296 - Divide Array in Sets of K Consecutive Numbers

The problem gives us an integer array nums and an integer k. We need to determine whether it is possible to divide all n

leetcodemediumarrayhash-tablegreedysorting
LeetCode 1757 - Recyclable and Low Fat Products

This problem gives us a database table named Products. Each row represents a product and contains three columns: | Column | Meaning | | --- | --- | | productid | Unique identifier for the product | | lowfats | 'Y' if the product is low fat, otherwise 'N' | | recyclable | 'Y'…

leetcodeeasydatabase
CF 47E - Cannon

We have a scenario where a cannon at the origin shoots a number of balls with the same initial speed, each at a given angle. The goal is to determine where each ball lands after either hitting a vertical wall or reaching the ground.

codeforcescompetitive-programmingdata-structuresgeometrysortings
LeetCode 1585 - Check If String Is Transformable With Substring Sort Operations

This problem asks whether we can transform one digit string, s, into another digit string, t, using a special operation. In one operation, we choose any non-empty contiguous substring of s and sort that substring in ascending order.

leetcodehardstringgreedysorting
CF 91D - Grocer's Problem

We are given a permutation of jars. Jar i should finally stand at position i, but the current arrangement is shuffled. One operation allows us to choose any subset of at most five positions and permute the jars inside those positions arbitrarily.

codeforcescompetitive-programmingconstructive-algorithmsgraphsgreedy
LeetCode 991 - Broken Calculator

This problem gives us a calculator that starts with an integer startValue and allows only two operations: 1. Multiply the current number by 2 2. Subtract 1 Our goal is to transform startValue into target using the minimum number of operations.

leetcodemediummathgreedy
LeetCode 2037 - Minimum Number of Moves to Seat Everyone

This problem asks us to assign students to seats such that every student occupies exactly one seat and no two students share the same seat. Each student can move left or right on a number line, and every movement by one position costs exactly one move.

leetcodeeasyarraygreedysortingcounting-sort
CF 40C - Berland Square

We have two families of circles on the infinite plane.

codeforcescompetitive-programmingimplementationmath
CF 60E - Mushroom Gnomes

We are given a line of mushrooms, each with a weight, initially sorted in non-decreasing order. Every minute, new mushrooms grow between every pair of neighboring mushrooms, and the weight of each new mushroom equals the sum of the two neighboring mushrooms.

codeforcescompetitive-programmingmathmatrices
LeetCode 757 - Set Intersection Size At Least Two

The problem asks us to find the minimum size of a set of integers, nums, such that each given interval [starti, endi] contains at least two integers from nums.

leetcodehardarraygreedysorting
CF 41A - Translation

We are given two lowercase strings. The first string is a word in one language, and the second string is supposed to be its translation into another language where every word is written backwards.

codeforcescompetitive-programmingimplementationstrings
LeetCode 1572 - Matrix Diagonal Sum

The problem gives us a square matrix mat of size n x n. A square matrix means the number of rows and columns are the sam

leetcodeeasyarraymatrix
CF 113A - Grammar Lessons

We are given a single line containing several lowercase words separated by spaces. Every valid word in Petya's language belongs to exactly one grammatical category and exactly one gender, determined entirely by its suffix.

codeforcescompetitive-programmingimplementationstrings
LeetCode 351 - Android Unlock Patterns

The problem models the Android lock screen as a 3 x 3 grid containing digits 1 through 9. A valid unlock pattern is a sequence of distinct dots that follows a special movement rule. The first rule is straightforward: each dot can only be used once in a pattern.

leetcodemediumdynamic-programmingbacktrackingbit-manipulationbitmask
LeetCode 1453 - Maximum Number of Darts Inside of a Circular Dartboard

In this problem, we are given the coordinates of several darts thrown onto a 2D plane. Each dart is represented as a poi

leetcodehardarraymathgeometry
LeetCode 1793 - Maximum Score of a Good Subarray

In this problem, we are given an integer array nums and a specific index k. We must find a contiguous subarray that contains index k, and among all such subarrays, maximize the following score: The minimum element inside the chosen subarray determines the limiting value of the…

leetcodehardarraytwo-pointersbinary-searchstackmonotonic-stack
LeetCode 26 - Remove Duplicates from Sorted Array

The problem gives us a sorted integer array nums in non-decreasing order. Because the array is already sorted, any duplicate values will always appear next to each other.

leetcodeeasyarraytwo-pointers
LeetCode 297 - Serialize and Deserialize Binary Tree

The problem asks us to design two complementary operations for a binary tree: serialization and deserialization. Serialization converts a binary tree into a string representation that can be stored or transmitted.

leetcodehardstringtreedepth-first-searchbreadth-first-searchdesignbinary-tree
LeetCode 1059 - All Paths from Source Lead to Destination

This problem gives us a directed graph with n nodes labeled from 0 to n - 1. Each directed edge [a, b] means there is a one way path from node a to node b.

leetcodemediumgraph-theorytopological-sort
LeetCode 439 - Ternary Expression Parser

The problem gives us a string representing a nested ternary expression and asks us to evaluate it. A ternary expression follows the familiar format: The condition is always either 'T' or 'F'. If the condition is 'T', the expression evaluates to the value before the ':'.

leetcodemediumstringstackrecursion
LeetCode 859 - Buddy Strings

The problem asks whether it is possible to make two strings equal by performing exactly one swap operation on the first string s. A swap operation means choosing two different indices i and j in s and exchanging the characters at those positions.

leetcodeeasyhash-tablestring
LeetCode 487 - Max Consecutive Ones II

The problem gives us a binary array nums, where every element is either 0 or 1. We want to find the longest contiguous subarray containing only 1s after we are allowed to flip at most one 0 into a 1.

leetcodemediumarraydynamic-programmingsliding-window
LeetCode 754 - Reach a Number

The problem asks us to find the minimum number of moves required to reach a specific position on an infinite number line starting from position 0. Each move i allows you to move exactly i steps, either to the left or the right.

leetcodemediummathbinary-search
LeetCode 1510 - Stone Game IV

This problem is a two-player combinatorial game problem where Alice and Bob alternately remove stones from a single pile. On each turn, a player may remove any positive number of stones that is a perfect square (1, 4, 9, 16, etc.

leetcodehardmathdynamic-programminggame-theory
CF 3C - Tic-tac-toe

We are given a snapshot of a tic-tac-toe board, represented as a 3×3 grid. Each cell is either empty (.), contains a cross (X), or contains a nought (0). The first player always places crosses, and the second player places noughts.

codeforcescompetitive-programmingbrute-forcegamesimplementation
LeetCode 628 - Maximum Product of Three Numbers

The problem gives an integer array nums and asks us to select exactly three numbers whose product is as large as possible. We must return that maximum product value.

leetcodeeasyarraymathsorting
LeetCode 347 - Top K Frequent Elements

The problem asks us to return the k most frequently occurring elements from an integer array. We are given an array nums, which may contain duplicates, and an integer k. Our task is to identify which values appear most often and return exactly k of them.

leetcodemediumarrayhash-tabledivide-and-conquersortingheap-(priority-queue)bucket-sortcountingquickselect
LeetCode 536 - Construct Binary Tree from String

This problem asks us to reconstruct a binary tree from a specially formatted string representation. The input string contains integer values and parentheses. Every integer represents a tree node, and parentheses represent child subtrees.

leetcodemediumstringstacktreedepth-first-searchbinary-tree
LeetCode 1234 - Replace the Substring for Balanced String

The problem asks us to balance a string composed of exactly four types of characters: 'Q', 'W', 'E', and 'R'. A string is balanced when each character occurs exactly n / 4 times, where n is the length of the string.

leetcodemediumstringsliding-window
LeetCode 1795 - Rearrange Products Table

The Products table stores product prices across three different stores. Each row represents one product, identified by productid, and each store column contains the product's price in that specific store.

leetcodeeasydatabase
LeetCode 131 - Palindrome Partitioning

The problem gives us a string s and asks us to divide it into substrings such that every substring is a palindrome. A palindrome is a string that reads the same forward and backward. We must return all possible valid ways to partition the string.

leetcodemediumstringdynamic-programmingbacktracking
LeetCode 632 - Smallest Range Covering Elements from K Lists

The problem gives us k sorted integer lists, and we must find the smallest inclusive range [a, b] such that the range contains at least one element from every list. Each list is already sorted in non-decreasing order, which is a very important property.

leetcodehardarrayhash-tablegreedysliding-windowsortingheap-(priority-queue)
LeetCode 1426 - Counting Elements

The problem asks us to count the number of elements in an array arr for which the value plus one also exists in the array. In other words, for every element x in the array, we check whether x + 1 is also present. If it is, we include x in our count.

leetcodeeasyarrayhash-table
LeetCode 863 - All Nodes Distance K in Binary Tree

This problem gives us the root of a binary tree, a specific target node inside that tree, and an integer k. Our task is to return all node values whose distance from the target node is exactly k. The important detail is the definition of distance.

leetcodemediumhash-tabletreedepth-first-searchbreadth-first-searchbinary-tree
CF 131E - Yet Another Task with Queens

We are given positions of queens on a chessboard. A queen attacks in eight directions: left, right, up, down, and the four diagonals. A queen does not attack every queen in a direction, only the first one encountered along that ray.

codeforcescompetitive-programmingsortings
LeetCode 845 - Longest Mountain in Array

The problem asks us to find the length of the longest contiguous subarray that forms a valid mountain. A mountain is a sequence that strictly increases up to a peak, then strictly decreases afterward.

leetcodemediumarraytwo-pointersdynamic-programmingenumeration
LeetCode 1678 - Goal Parser Interpretation

This problem asks us to interpret a Goal Parser command string. The string command consists of the characters "G", "()",

leetcodeeasystring
CF 45F - Goats and Wolves

We have the classical river crossing setting, but with a precise safety rule that changes how transitions work.

codeforcescompetitive-programminggreedy
LeetCode 1196 - How Many Apples Can You Put into the Basket

This problem is asking us to determine how many apples we can fit into a basket with a maximum carrying capacity of 5000 units of weight. We are given an array weight where each element represents the weight of a single apple.

leetcodeeasyarraygreedysorting
LeetCode 1523 - Count Odd Numbers in an Interval Range

The problem gives two non-negative integers, low and high, representing the inclusive bounds of an interval. We need to

leetcodeeasymath
LeetCode 824 - Goat Latin

This problem asks us to transform a given sentence into a fictional language called Goat Latin, following a specific set of string manipulation rules. The input is a string called sentence, where words are separated by a single space.

leetcodeeasystring
LeetCode 816 - Ambiguous Coordinates

The problem gives us a compressed string representation of a 2D coordinate. Originally, the coordinate looked something like "(1, 3)" or "(2, 0.5)", but all commas, spaces, and decimal points were removed. Our task is to reconstruct every possible valid original coordinate pair.

leetcodemediumstringbacktrackingenumeration
LeetCode 182 - Duplicate Emails

The problem gives us a database table named Person with two columns: Column Description --- --- id A unique integer identifier for each row email The email address associated with that row The goal is to find all email addresses that appear more than once in the table.

leetcodeeasydatabase
LeetCode 344 - Reverse String

The problem asks us to reverse a string that is represented as an array of characters. Instead of returning a new reversed string, we must modify the original array directly.

leetcodeeasytwo-pointersstring
CF 14E - Camels

We are counting sequences of heights that describe a polyline. The x-coordinates are fixed as 1, 2, ..., n, so the whole shape is determined only by the sequence y1, y2, ..., yn.

codeforcescompetitive-programmingdp
CF 55D - Beautiful numbers

We are asked to count numbers in given ranges that Volodya would call beautiful. A number is beautiful if it is divisible by each of its nonzero digits. For example, 128 is beautiful because 128 is divisible by 1, 2, and 8.

codeforcescompetitive-programmingdpnumber-theory
LeetCode 557 - Reverse Words in a String III

The problem requires reversing the characters of each individual word in a string while maintaining the original order of the words and the spacing between them. In other words, the sentence structure remains the same, but each word is mirrored in place.

leetcodeeasytwo-pointersstring
LeetCode 219 - Contains Duplicate II

The problem asks us to determine whether an array contains two equal values whose indices are close to each other.

leetcodeeasyarrayhash-tablesliding-window
LeetCode 129 - Sum Root to Leaf Numbers

The problem gives us the root of a binary tree where every node contains a single digit from 0 to 9. Every path starting from the root and ending at a leaf node forms a number by concatenating the digits along that path.

leetcodemediumtreedepth-first-searchbinary-tree
LeetCode 412 - Fizz Buzz

The problem asks us to generate a list of strings for all integers from 1 to n. For each number, we apply a set of divisibility rules: - If the number is divisible by both 3 and 5, we append "FizzBuzz". - If the number is divisible only by 3, we append "Fizz".

leetcodeeasymathstringsimulation
CF 22D - Segments

We are given several closed intervals on the number line. A nail placed at an integer coordinate covers every segment that contains that coordinate, including endpoints.

codeforcescompetitive-programminggreedysortings
CF 67D - Optical Experiment

Each ray enters the box through one hole on the left side and exits through one hole on the right side. The order of holes on both sides matters.

codeforcescompetitive-programmingbinary-searchdata-structuresdp
LeetCode 1544 - Make The String Great

The problem asks us to process a string s consisting of lowercase and uppercase English letters, removing pairs of adjac

leetcodeeasystringstack
LeetCode 1740 - Find Distance in a Binary Tree

This problem asks us to determine the distance between two nodes in a binary tree, given their values p and q. The distance is defined as the number of edges in the shortest path connecting the two nodes.

leetcodemediumhash-tabletreedepth-first-searchbreadth-first-searchbinary-tree
LeetCode 283 - Move Zeroes

The problem gives us an integer array nums and asks us to move every 0 element to the end of the array while preserving the relative order of all non-zero elements. The phrase "relative order" is extremely important.

leetcodeeasyarraytwo-pointers
LeetCode 280 - Wiggle Sort

The problem asks us to rearrange an integer array so that it follows a specific alternating pattern called a wiggle sequence. The required relationship is: - nums[0] <= nums[1] - nums[1] = nums[2] - nums[2] <= nums[3] - nums[3] = nums[4] - and so on.

leetcodemediumarraygreedysorting