brain
tamnd's digital brain — notes, problems, research
42641 notes
This problem asks us to determine whether a given binary tree is height-balanced. A binary tree is considered height-balanced if, for every node in the tree, the height difference between its left and right subtrees is at most 1.
The problem asks us to determine the minimum number of frogs needed to produce a given sequence of croaks represented by
The problem gives us a valid time string in the format "HH:MM" and asks us to construct the next chronological time using only the digits already present in the original time. The important detail is that digits may be reused any number of times.
This problem asks us to delete a node from a singly linked list, but with an unusual restriction: we are not given access to the head of the list. Instead, we are only given a reference to the node that should be deleted.
We are asked to count the number of ways an arithmetic expression can be made unambiguous with parentheses so that, if all parentheses are removed, the expression is exactly the string given in the input.
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.
The problem asks us to generate a sales report that summarizes the total quantity of items sold for each category on eac
The problem asks us to count how many substrings of length k contain only unique characters. A substring is a contiguous portion of the string. For every possible substring of length k, we must determine whether all characters inside it are distinct.
Each year the university sends a team of exactly n students to the finals. Some of those students may already have participated once before, and the rest are newcomers.
The problem asks us to compute every possible bitwise OR value that can be formed from all non-empty contiguous subarrays of the given array arr, then return how many distinct values exist. A subarray is any contiguous slice of the array.
This problem asks us to design a simplified file system that supports two operations: 1. Creating a new path with an associated integer value. 2. Retrieving the value stored at a path. A path behaves similarly to a directory structure in a real operating system.
The problem is asking us to partition a string s into as many contiguous parts as possible such that no letter appears in more than one part. In other words, each character in the string should be confined to a single segment.
The problem provides a Delivery table that records food delivery orders. Each row represents a single order placed by a customer. Along with the order date, each customer also specifies a preferred delivery date.
The problem asks us to count the number of good meals that can be formed from a given list of food items. A good meal is defined as a pair of two different items whose combined deliciousness is a power of two.
This problem asks us to identify whether there is a "celebrity" among n people at a party. A celebrity has a very specific property: - Every other person knows the celebrity. - The celebrity knows nobody else. We are not given the entire relationship graph directly.
The problem provides two traversal orders of the same binary tree: - inorder, which follows the order: left subtree, root, right subtree - postorder, which follows the order: left subtree, right subtree, root We must reconstruct the original binary tree and return its root node.
The problem asks us to construct a permutation of the integers from 1 to n such that the array satisfies a special condition.
The problem gives us the root node of a binary tree and asks whether the tree is "uni-valued". A binary tree is considered uni-valued if every node in the tree contains exactly the same integer value.
We are given three original strings. A student's answer is considered correct if it can be formed by concatenating these three strings in any order, after ignoring two kinds of differences. The first difference is letter casing.
Every student independently chooses one of the bathroom rooms uniformly at random. A room may contain several wash basins, so students entering that room are split into several queues.
The problem is asking us to simulate a flood fill operation on a 2D grid that represents an image. Each cell in the grid contains an integer representing a pixel color. You are given a starting pixel (sr, sc) and a target color color.
The knights sit on a circle, equally spaced. Each position is marked either 1 for a knight in a good mood or 0 for a knight in a bad mood.
This problem asks us to determine which words in a given list can be typed using letters from only one row of an American keyboard. The input is an array of strings, words, where each string represents a word consisting only of English alphabet characters.
This problem asks us to determine which key on a keypad was pressed for the longest duration during a test sequence. We
The problem asks us to query a database table Patients and return the records of patients who have Type I Diabetes. Each
The traversal is by reference, not value.
The Death Star is a sphere of radius R. Its center starts at point A and moves forever in a straight line with constant velocity vector v. Every mine consists of two kinds of geometry. The first part is a sphere centered at O with radius r. The second part is a set of spikes.
This problem models a very large chessboard-like grid where certain cells contain active lamps. A lamp illuminates four directions simultaneously: - Its entire row - Its entire column - Its main diagonal, identified by row - col - Its anti-diagonal, identified by row + col For…
The problem asks us to reverse only the vowels in a string while leaving all non-vowel characters in their original positions.
The problem asks us to determine the minimum number of positive deci-binary numbers required to sum up to a given decima
The problem asks us to segment a given string s into all possible sentences where each word in the sentence exists in a given dictionary wordDict.
We are given a binary grid. Cells containing '1' form usable tiles, while '0' cells are blocked. We want the longest cycle made entirely from '1' cells. The cycle must behave like a simple closed curve on the grid.
The problem asks us to find the lexicographically largest permutation that is still smaller than the given array, using exactly one swap operation.
The problem asks us to count the number of good integers within a given range [1, n]. An integer is considered good if each of its digits, when rotated 180 degrees, forms another valid digit and the resulting number is different from the original.
The Skyline Problem asks us to compute the visible outer contour formed by a collection of rectangular buildings when viewed from far away. Each building is represented by three integers: a left x-coordinate, a right x-coordinate, and a height.
The problem gives us a set of allowed digits, stored as strings, and an integer n. We may construct any positive integer by repeatedly using digits from the given set. Each digit can be reused any number of times.
LeetCode 212, LeetCode Word Search II, asks us to find every word from a given dictionary that can be formed inside a 2D character grid. Each word must be built by moving one cell at a time horizontally or vertically.
The problem gives us the root of a binary tree and asks us to identify all duplicate subtrees inside it. A subtree is defined as any node together with all of its descendants.
The problem asks us to implement a circular queue, a fixed-size queue where the end wraps back to the start to efficiently reuse empty space.
We are asked to count how many distinct substrings of a given string t start with a string sbegin and end with another string send. The key detail is that substrings are considered different only by their content, not by their position in t.
The problem asks us to identify the majority element in a given array of integers nums. The majority element is defined as the number that appears more than half of the times in the array, i.e., more than ⌊n / 2⌋ times where n is the length of the array.
We are given several force vectors acting on a body in three-dimensional space. Each vector has three components: its effect along the x-axis, y-axis, and z-axis. A body is in equilibrium only if the total force acting on it is zero in every direction.
This problem asks us to determine how many different valid ways a numeric string can be decoded into letters using the mapping: - "1" → 'A' - "2" → 'B' - ... - "26" → 'Z' The input is a string s containing only digits.
This problem is asking us to calculate a retention metric from a table of player activities. Specifically, we need to determine the fraction of players who log in on the day immediately following their first login.
This problem asks us to analyze two database tables, Subscriptions and Streams, and determine how many accounts purchased a subscription during the year 2021 but never streamed any content during 2021. The Subscriptions table stores subscription intervals for each account.
The problem asks us to convert a binary matrix into a Quad-Tree representation. A Quad-Tree is a recursive tree structure where every internal node has exactly four children, each representing one quadrant of the current square region.
We are given three line segments on a 2D plane. We must decide whether these three segments can be interpreted as the shape of the capital letter A.
This problem asks us to reverse only a specific portion of a singly linked list, rather than reversing the entire list. We are given the head of a linked list and two integer positions, left and right, where left <= right.
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.
The problem provides a singly linked list and an integer k. The task is to swap the values of the kth node from the start with the kth node from the end of the list. The list is 1-indexed, meaning that the first node is position 1, not 0.
The problem gives us a grid called heights, where each cell contains an integer representing elevation. We start at the top-left corner (0, 0) and want to reach the bottom-right corner (rows - 1, columns - 1).
That’s a detailed reference guide with multiple required sections and full implementations. Before I start, please confi
We are given a string s. For every substring x of s, we look at all positions where x appears inside s. Suppose these occurrences start at positions: $$p1 < p2 < dots < pk$$ The function F(s, x) counts how many contiguous segments we can choose from this ordered list of…
The problem asks us to calculate the sum of beauty for all substrings of a given string s. The beauty of a substring is defined as the difference between the highest frequency and the lowest frequency of any character that occurs in that substring.
We are asked to process a sequence of queries, each defined by two integers, x and y. For each query, we need to count how many positive divisors of x do not divide any of the y numbers immediately preceding x in the sequence, that is, the numbers x-y, x-y+1, ..., x-1.
We are given the dimensions of an uploaded photo, height h and width w. We want to cut out a smaller rectangle from it. The cut rectangle must satisfy three conditions.
This problem asks us to transform a given integer n into 0 using a specialized set of bit-flipping operations. Each oper
The problem asks us to design our own HashSet implementation without using any built in hash table libraries such as Python's set or Go's built in map type as the primary solution idea. A HashSet is a data structure that stores unique values.
Valera has a list of subjects he knows how to solve. Every subject takes a fixed amount of working time. Students come with requests: each request has a subject, an exam deadline, and a reward. If Valera finishes the solution strictly before the exam starts, he gets paid.
This problem gives us a string s and an integer k. We are allowed to repeatedly perform one operation: - Choose one of the first k characters of the string. - Remove that character from its current position. - Append it to the end of the string.
The problem asks us to find the shortest superstring that contains all the given strings in the array words as substrings.
We are given a board of size n by m, with a spider on every cell. Each spider can move to any adjacent cell or stay in place, as long as it stays inside the board. All spiders move simultaneously, and multiple spiders can occupy the same cell after moving.
We have houses numbered from 1 to n. Every house must receive a color. For each color, if we add together all house indices painted with that color, the result must be a prime number.
This problem gives us an array called heights, where each element represents the height of a building. The buildings are arranged in a straight line from left to right, and the ocean is located to the right side of the last building.
The problem gives us an integer array arr and asks whether every distinct number appears a unique number of times. In other words, we first count how many times each value occurs in the array.
The problem gives us a sorted array called stations, where each value represents the position of an existing gas station on a one dimensional x-axis. We are also given an integer k, representing how many additional gas stations we are allowed to add.
The problem gives us a database table named RequestAccepted, where each row represents a successfully accepted friend request between two users. Every record contains a requesterid, an accepterid, and the date the request was accepted.
This problem describes a two-player perfect-information game played on a small grid. One player controls the mouse and the other controls the cat. Both players move optimally and alternate turns, with the mouse always moving first.
We are given the coordinates of three vertices of some regular polygon. The polygon itself is unknown: we do not know how many sides it has, where its center is, or which vertices the three points correspond to.
We are given the top view of a robotic vacuum cleaner as a convex polygon. The room corner is the usual 90 degree corner formed by two perpendicular walls. We may rotate the vacuum cleaner by any angle and then push it as far as possible into the corner.
This problem asks us to determine whether two sentences are considered similar based on a set of similarity relationships between words. Each sentence is represented as an array of strings, where each string is a single word.
The problem gives us an array called colors, where each position contains one of three possible values: 1, 2, or 3. Each value represents a color assigned to that index. We are also given a list of queries.
The problem asks us to transform a binary tree into a formatted 2D string matrix representation. Each node must appear in a specific row and column based on its position in the tree. The output is not simply a traversal order, it is a visual layout of the tree structure.
The problem asks us to convert a decimal number given as a string into its Hexspeak representation. Hexspeak is derived
We are given a rectangular grid representing a sheet of graph paper with _n_ rows and _m_ columns. Some of the squares are shaded, marked by *, and the rest are unshaded, marked by ..
The problem gives us a sentence where words are separated by single spaces, the very first character of the sentence is
This problem asks us to determine whether a given Tic-Tac-Toe board configuration could occur during a real game that follows all official rules. The input is a 3 x 3 board represented as an array of three strings.
The problem gives us a binary matrix M with dimensions height x width. Every cell in the matrix must contain either 0 or 1. There is one important restriction: Every square submatrix of size sideLength x sideLength may contain at most maxOnes cells equal to 1.
In this problem, we are given a binary tree where every node contains some number of coins. The total number of coins across the entire tree is exactly equal to the number of nodes in the tree.
In this problem, we are given two strings, jewels and stones. The string jewels represents all stone types that are considered jewels. Each character is a unique jewel type. For example, if jewels = "aA", then both lowercase 'a' and uppercase 'A' are jewel types.
We are given the results of an entire Formula One season. Each race lists drivers from first place to last place. The championship winner depends on one of two ranking systems.
The problem asks us to decompose a given string text into the largest possible number of contiguous substrings such that the sequence of substrings forms a palindromic pattern.
We are given two points in the plane, the ship's starting position and destination, together with a convex polygon representing an island. Moving through the sea costs 1 per unit distance. Moving through the interior of the island costs 2 per unit distance.
This problem asks us to connect all given points on a 2D plane with the minimum possible total cost. Each point is repre
This problem asks us to split a collection of steel rods into two groups such that both groups have exactly the same total height. Among all possible equal-height pairs, we want the maximum achievable height. Each rod can be used in one of three ways: 1.
The problem gives a string containing only six possible characters: (, ), {, }, [ and ]. Each opening bracket must eventually be matched with the correct closing bracket, and the order of matching matters.
This problem asks us to find a unique number in an array where every other number appears exactly three times. In simpler terms, if you imagine counting all the numbers in the array, every number except one will show up three times, and our task is to identify the number that…
The problem asks us to design a data structure that can efficiently answer multiple rectangular sum queries on a fixed 2D matrix.
We are given a weighted tree rooted at hall 1, where Gerald starts. The treasure is hidden uniformly at random in one of the other halls. Gerald only discovers the treasure when he first enters the correct hall.
The problem asks us to identify a redundant edge in a directed graph that originated as a rooted tree. A rooted tree has a single root with all other nodes having exactly one parent.
The problem describes a one-dimensional garden that stretches from position 0 to position n. At every integer position i, there is a tap that may water some interval around it.
This problem asks us to determine the first day each player logged into a game based on a table called Activity. Each row of this table contains a playerid, the deviceid used, the eventdate on which the player logged in, and the number of gamesplayed during that session.
We are given a string of lowercase letters, and the task is to find the length of the longest substring that occurs at least twice in the string. The repeated occurrences may overlap. The input is a single string of at most 100 characters.
We have a line of students, and for every adjacent pair we know only the relative order of their marks. If the relation character between positions i and i + 1 is: - L, then student i must receive strictly more toffees than student i + 1 - R, then student i + 1 must receive…
The problem asks us to take an integer num and find the maximum number we can create by swapping at most two digits. In other words, we can pick two positions in the number, swap their digits, and we want the resulting number to be as large as possible.
The problem gives us a list of integers representing asteroids moving through space in a straight line. Each integer contains two pieces of information: - The absolute value represents the asteroid's size. - The sign represents the direction: - Positive numbers move to the right.
The problem gives us a string s that contains only the characters 'a' and 'b'. In one operation, we are allowed to remov
This problem asks us to generate a monthly financial summary for each country using information from two database tables: Transactions and Chargebacks. The Transactions table stores incoming transactions.
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.
The problem gives us two integer arrays, nums1 and nums2, where every element is between 1 and 6. In one operation, we may choose any element from either array and change it to any value from 1 to 6.