brain
tamnd's digital brain — notes, problems, research
43815 notes
The problem asks us to coordinate four separate threads so they collectively print the correct Fizz Buzz sequence in order from 1 to n. Unlike the classic single threaded Fizz Buzz problem, this version introduces concurrency.
This problem asks us to compare two software version numbers represented as strings. Each version consists of one or more numeric revisions separated by dots (.). For example, "1.2.10" contains three revisions: 1, 2, and 10.
The problem asks us to count how many nodes exist in a complete binary tree. A complete binary tree has a very specific structure. Every level except possibly the last one is completely filled, and the nodes on the final level appear as far left as possible.
The problem asks us to find the Lowest Common Ancestor, usually abbreviated as LCA, of two nodes in a binary tree. A binary tree consists of nodes where each node may have a left child and a right child.
This problem gives us a list of people where each person is represented as a pair [h, k]. The value h represents the person's height. The value k represents how many people standing in front of this person must have a height greater than or equal to h.
This problem asks us to calculate the total storage volume occupied by products inside each warehouse. We are given two database tables: The Warehouse table tells us which products are stored in each warehouse and how many units of each product exist there.
The problem asks us to find the leftmost value in the last row of a binary tree. A binary tree is a hierarchical data structure where each node has at most two children: a left child and a right child.
The problem asks for the maximum sum of a subarray in a circular array. In simpler terms, we are given a list of integers nums where the end of the list wraps around to the start.
The cableway sends one cablecar every minute, and the colors repeat in a fixed cycle: red - green - blue - red - ... Each cablecar can carry at most two students, and every ride takes exactly 30 minutes to reach the top. We are given three groups of students.
This problem asks us to determine how many times a given string word can be repeated consecutively while still appearing
The problem gives us a deck of unique integer cards and asks us to arrange the deck so that a very specific reveal process produces the cards in increasing order. The reveal process works like this: 1. Reveal the top card and remove it from the deck. 2.
The train has n wagons arranged in a line. The controller moves deterministically: every minute he walks one wagon in his current direction, and when he reaches either end he reverses direction. His path is completely fixed once we know the initial wagon and direction.
The problem asks us to count how many contiguous, non-empty subarrays have a maximum element that lies within the inclusive range [left, right]. A subarray is a continuous segment of the original array. For every possible subarray, we look at its maximum value.
The problem asks us to find the "luckiest" substring of a given string of digits. By luckiest, we mean a substring that consists only of the digits 4 and 7, occurs in the string as many times as possible, and is the lexicographically smallest if there are ties.
The problem gives us the results of some dice rolls and asks us to reconstruct the missing ones. We have a total of n + m rolls of a standard 6-sided die.
This problem asks us to find the maximum length of a contiguous subarray in a binary array where the number of 0s and 1s are equal. A contiguous subarray means the elements must appear consecutively in the original array. We are not allowed to rearrange elements or skip indices.
The problem asks us to design a calendar system that supports booking events without allowing overlapping intervals. Each event is represented as a half-open interval [startTime, endTime). This means the event includes startTime, but does not include endTime.
This problem asks us to repeatedly simulate a process involving stones with different weights. At every turn, we must select the two heaviest stones, smash them together, and update the collection based on the result.
The problem provides a database table named Sessions with two columns: | Column | Meaning | | --- | --- | | sessionid |
The problem asks for the length of the longest arithmetic subsequence in a given array arr such that the difference between consecutive elements equals a specified integer difference. A subsequence can skip elements but must preserve the original order.
The problem describes a subway system as an undirected graph where each vertex is a station and each edge represents a direct connection between two stations. Every edge is labeled with a color representing the subway line it belongs to.
We are given the scoreboard data for every participant in a Codeforces room. Each contestant has a handle, a number of successful hacks, a number of unsuccessful hacks, and the points earned from problems A through E.
We are asked to prepare a set of additional undirected edges, called wormholes, on top of an unknown tunnel system.
We are given a three-dimensional space containing $n$ fixed points, representing the centers of energy spheres. There are $m$ levels, and in each level the player starts at a plane passing through the origin.
The problem gives us a set of buckets where exactly one bucket contains poison. We need to determine which bucket is poisonous using the fewest number of pigs possible, under a strict time limit. Each pig can participate in multiple rounds of testing.
The problem asks us to determine whether a given string of digits can be partitioned into a valid additive sequence. An additive sequence is a sequence of numbers where: - There are at least three numbers.
The problem asks us to design a reversible encoding system for a list of strings. We need two functions: - encode, which converts a list of strings into a single string - decode, which reconstructs the original list from that encoded string The important requirement is that…
This problem asks us to maximize the total profit earned by assigning jobs to workers, under a specific rule: each worker can only perform jobs whose difficulty is less than or equal to their ability.
The problem requires determining the minimum amount of time to build all blocks using workers that can either build blocks or split into more workers. You are given a list blocks where blocks[i] indicates the time it takes for a worker to complete the i-th block.
We are given a map of Berland with several control points and circular fences. Each knight occupies a control point. Fences separate the kingdom into regions, and a knight must cross fences to move between control points.
The problem is asking us to determine, for each row in a table called Triangle, whether the three given line segments can form a valid triangle. Each row contains three integers x, y, and z representing the lengths of the segments.
We need to construct the smallest possible lucky number whose digits add up to a given value n. A lucky number may contain only digits 4 and 7. For example, 447 is valid because every digit is either 4 or 7, while 45 is invalid because digit 5 appears.
The problem gives us an integer array nums, where each value represents the maximum distance we are allowed to jump forward from that position. You always start at index 0.
The problem asks us to find the nth positive integer that is divisible by either a or b. A number is considered magical if at least one of the following is true: - It is divisible by a - It is divisible by b We are given three integers: - n, the position of the magical number…
The problem asks us to determine whether a given binary string s contains all binary representations of integers from 1 to n as substrings.
The problem gives us an alphanumeric string s that contains only lowercase English letters and digits. Our task is to re
The problem presents an array arr where all elements are equal except for one element that is strictly larger than the o
This problem provides a database table named Employee, where every row represents a single employee and the team they belong to.
The problem gives us two non-empty singly linked lists where each node stores a single digit of a non-negative integer. Unlike the classic "Add Two Numbers" problem, the digits are stored in forward order, meaning the most significant digit appears first.
We are given two strings, a and b, of equal length up to one million characters. The task is to find indices i and j in a such that if we perform a specific transformation, we get b.
This problem asks us to determine the length of the shortest transformation sequence between two words, beginWord and endWord, under a strict transformation rule.
We are given three positive integers representing the prices of three presents. There are three sisters, ranked by age: eldest, middle, and youngest.
This problem asks us to determine the minimum number of swaps needed to group all 1s in a binary array into one contiguous block. The block can appear anywhere in the array, as long as all 1s end up adjacent.
We are given a rectangular picture represented as an A × B grid of letters. The task is to determine how many ways we can cut this picture into smaller rectangular pieces such that each piece is unique up to rotations, and to identify the smallest possible piece size among…
We are given a single string containing printable ASCII characters. Some characters may be lowercase English letters, some may already be uppercase letters, and others may be symbols or digits.
The problem provides a database table named Products, where each row represents a price update for a product on a specific date.
The problem asks us to find all numbers within a given inclusive range [left, right] that satisfy the definition of a self-dividing number. A self-dividing number has two important properties: 1. Every digit inside the number must divide the number evenly. 2.
We are playing the classic Bulls and Cows game with four-digit numbers whose digits are all distinct. Leading zeroes are allowed, so 0123 is valid, but repeated digits such as 0012 or 1223 are not. Each previous guess comes with two values.
The problem defines a function f(s) for a non-empty string s. This function returns the frequency of the lexicographically smallest character in the string.
This problem asks us to prune a binary tree by removing insufficient nodes. A node is insufficient if every root-to-leaf path passing through it has a sum strictly less than the given limit. The input is the root of a binary tree and an integer limit.
The problem asks us to remove the minimum number of invalid parentheses from a string so that the remaining string becomes valid. The input string may contain lowercase English letters in addition to parentheses.
The problem gives us a sorted array of unique integers and asks us to summarize consecutive values into compact range strings. A range represents a continuous sequence of integers.
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.
The problem asks us to sort an integer array arr based on the number of 1 bits in the binary representation of each elem
This problem asks us to find the largest absolute difference between the values of two nodes in a binary tree, under one important condition: one node must be an ancestor of the other.
This problem asks us to add two polynomials represented as singly linked lists. Each node in the linked list represents a single term of a polynomial, with a coefficient and a power.
The problem gives us a list of query strings and a target camel case pattern. For each query, we must determine whether the query can be formed by inserting only lowercase English letters into the pattern.
The problem is a combinatorial game involving three piles of stones with counts a, b, and c. In each move, you are allowed to pick two different non-empty piles and remove one stone from each, earning 1 point per move. The game ends when fewer than two piles have stones left.
This problem is the two dimensional version of the classic "Trapping Rain Water" problem. Instead of a one dimensional array of heights, we are given an m x n grid where each cell represents the elevation of a block in a terrain.
The problem gives us an integer array nums, and we are allowed to perform at most three moves. In each move, we may sele
We have an grid. Some cells contain pies, and several pies may share the same cell.
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.
This problem asks us to maximize profit from stock trading under a special restriction called a cooldown period. We are given an integer array prices, where prices[i] represents the stock price on day i. On any day, we may choose to buy one share, sell one share, or do nothing.
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.
This problem asks us to evaluate a mathematical expression represented as a string. The expression may contain: - Non-negative integers - Addition (+) - Subtraction (-) - Multiplication () - Division (/) - Parentheses (( and )) The goal is to compute the final integer result…
The problem gives us a database table named Scores that contains two columns: id and score. Each row represents the score achieved in a game.
The problem asks us to identify customers who meet a very specific purchasing pattern. We are given two tables: Customer
The problem asks us to take a string containing only digits and determine every possible way to insert exactly three dots so that the resulting string becomes a valid IPv4 address. A valid IP address has four numeric segments separated by dots.
The problem asks us to count how many integers in the range 0 <= x < 10^n contain no repeated digits. For example, when n = 2, the valid range is: This means we consider every number from 0 to 99. Among these numbers, we only count those whose digits are all unique.
Jack repeats a cyclic sequence consisting of three possible actions. L means a left-foot step, R means a right-foot step, and X means standing still for one beat. The sergeant expects the infinite alternating pattern:
The problem gives us a binary matrix of size m x n, where every cell contains either 0 or 1. We must count how many squa
The problem asks us to design an in-memory file system that simulates basic file system operations without interacting with the real filesystem.
This problem asks us to compare two binary trees based only on their leaf nodes. A leaf node is a node that has no left child and no right child.
The problem is asking us to determine the number of provinces in a network of cities. Each city can be connected directly to other cities, and indirectly through chains of connections.
In this problem, we are given a binary matrix where each cell contains either 0 or 1. A value of 1 represents land, while 0 represents water. An island is formed by connecting adjacent land cells in the four cardinal directions: up, down, left, and right.
We need to evaluate a sum over an interval [l, r]. For every integer x in that range, we compute next(x), where next(x) means the smallest lucky number greater than or equal to x. A lucky number is a positive integer whose decimal digits are only 4 and 7.
The problem gives us an initially zero-filled array of size length. We are also given a list of update operations, where each update has the form: This means we must add inc to every element in the inclusive range from startIdx to endIdx.
We are given an integer array and must classify it into one of three categories.
The problem is asking us to determine, for each user in a social media application, how many followers they have. The input is a table called Followers with two columns: userid and followerid. Each row represents a relationship where followerid follows userid.
The problem gives an integer array nums and an integer k. We must divide the array into exactly k non-empty contiguous subarrays. Among those subarrays, each one has its own sum, and the goal is to minimize the largest subarray sum.
The problem gives a list of envelopes, where each envelope is represented as a pair [w, h]. The value w is the width and h is the height. An envelope can fit inside another envelope only if both dimensions are strictly smaller.
This problem asks us to determine the minimum number of swaps needed to make two strings, s1 and s2, equal. Both strings are of the same length and consist only of the characters "x" and "y".
The problem asks us to find the minimum Hamming distance between two arrays, source and target, after performing any number of swaps on source at positions allowed by allowedSwaps. The Hamming distance is defined as the number of indices i for which source[i] != target[i].
This problem asks us to count quadruples of indices (i, j, a, b) where substrings from two given strings are equal and the difference j - a is minimized. Specifically, i and j define a substring in firstString, while a and b define a substring in secondString.
The problem asks us to decide whether a positive integer $n$ can be represented as a sum of distinct integers, where each integer is either 1 or a prime number. If such a representation exists, we need to produce one that is lexicographically largest.
This problem asks us to coordinate multiple concurrent threads so that they form water molecules correctly. A water molecule contains exactly two hydrogen atoms and one oxygen atom, so the synchronization logic must ensure that threads proceed only in groups of three…
Marina can pick any subset of flowers from the field. Each flower has a certain number of petals, and she will pluck all petals from all chosen flowers one by one. The phrases alternate between "Loves" and "Doesn't love", starting from "Loves" on the first petal.
The problem asks us to examine the binary representation of a positive integer n and determine the largest distance between two adjacent 1 bits. A binary number is made up of 0s and 1s.
This problem asks us to determine the weather type for each country during November 2019, based on the average weatherst
The problem gives a list of restaurant orders. Each order contains three pieces of information: - Customer name - Table number - Food item An order looks like this: The goal is to build a display table that summarizes how many times each food item was ordered at every table.
The problem gives us a string called text and two target words, first and second. We must find every occurrence where the words appear consecutively in the exact order: For every such occurrence, we return the value of third.
The problem gives us a database table named Queries. Each row represents the outcome of running a particular query against a database.
We are given a string of digits representing a car number. The number is considered beautiful if at least k positions contain the same digit. We may change any digit into another digit, and changing digit a into digit b costs The task has two objectives.
This problem describes a square room with perfectly reflective walls. The room has side length p, and there are three receptors placed at three corners of the square: - Receptor 0 is at the southeast corner - Receptor 1 is at the northeast corner - Receptor 2 is at the…
The problem asks us to return every path from the root of a binary tree to each leaf node. A root-to-leaf path is formed by starting at the root node and continuously moving downward through child nodes until reaching a node that has no children.
The problem asks us to count how many valid strings of length n can be formed using only the five lowercase vowels: - 'a' - 'e' - 'i' - 'o' - 'u' However, the strings are not arbitrary. Each vowel has strict rules about which vowels may appear immediately after it.
The problem asks us to find the minimum number of Fibonacci numbers whose sum equals a given integer k. Fibonacci number
This problem gives us a database table named Queue that represents people waiting to board a bus. Each row contains a person's ID, name, weight, and boarding order. The turn column determines the exact sequence in which people attempt to board the bus.
We are trying to reconstruct a hidden binary string of length n. Every guess Vasya made is another binary string of the same length, together with a number saying how many positions matched the real code exactly.
The problem asks us to count how many separate word-like groups exist inside a string. In this problem, a "segment" is defined as a continuous sequence of characters that are not spaces.