brain
tamnd's digital brain — notes, problems, research
42715 notes
The problem asks us to determine the maximum number of times the word "balloon" can be formed using the characters from a given string text. Each character in text can be used at most once per occurrence of the word.
The problem gives us an array called heights, where each value represents the height of a student standing in a line. The school wants the students arranged in non-decreasing order, meaning heights should appear from smallest to largest, allowing duplicates.
The problem gives us a string n representing a positive integer, and asks us to find the numerically closest palindrome that is not equal to the original number itself. A palindrome is a number that reads the same forward and backward. Examples include 121, 999, and 1331.
Here is a complete, detailed technical solution guide for LeetCode 1582 - Special Positions in a Binary Matrix, followin
The problem presents a stream of points in a 2D plane and asks us to design a data structure that supports two operations efficiently: adding points and counting squares.
The problem asks us to find the length of the longest harmonious subsequence in an integer array. A harmonious array is defined as one where the difference between the maximum and minimum values is exactly 1.
The problem asks us to add two numbers that are represented in negabinary, which is base -2. Unlike standard binary (base 2), each bit in negabinary contributes a value multiplied by powers of -2.
We are given Masha's phone number as a string of digits. From this number, she generates another phone number digit by digit. The first digit of the new number can be any digit from 0 to 9.
The problem asks us to find the next "lucky" ticket number that is strictly greater than a given ticket. Each ticket is a string of digits with even length, denoted 2n.
Nick wants to list all numbers of a given length n in base b, where digits range from 0 to b-1, but numbers cannot start with 0. Each page in his notepad holds exactly c numbers. We are asked to compute how many numbers appear on the last page he fills.
This problem asks us to find the largest possible island size in a binary grid after changing at most one 0 into 1.
The problem asks us to determine whether two strings s and t, each representing a rational number in decimal notation, correspond to the same numerical value. These numbers can be expressed as integers, finite decimals, or decimals with repeating parts denoted by parentheses.
This problem asks us to find the minimum number of steps required to move from the top-left corner of a grid to the bott
The problem gives us an array nums containing non-negative integers. We need to determine whether there exists an intege
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.
We are given a messy textual representation of a sequence. The string may contain positive integers, commas, spaces, and the special token .... Spaces may appear in the wrong places or appear multiple times. The task is purely formatting.
This problem gives us a string s that contains only the characters 'L' and 'R'. The string is guaranteed to already be balanced overall, meaning the total number of 'L' characters equals the total number of 'R' characters.
This problem gives us a two dimensional matrix with two very important ordering properties: 1. Each row is sorted from left to right in non-decreasing order. 2. The first element of every row is greater than the last element of the previous row.
The problem asks us to compute the maximum alternating subarray sum for a given integer array. A subarray is any contiguous sequence of elements from the array.
The problem gives us a positive integer n and asks for the minimum number of operations required to transform it into 1.
The problem gives us a numeric string num and an integer k. We must remove exactly k digits from the number so that the resulting integer is as small as possible. The key detail is that we are not allowed to reorder digits.
The problem asks us to count the number of ways we can partition a given array nums of positive integers into contiguous
This problem asks us to analyze a collection of user activity logs and determine how many users have a specific number of unique active minutes.
The problem gives us the root of a binary tree and an integer targetSum. We need to count how many downward paths in the tree have values that add up exactly to targetSum. A path can begin at any node and end at any node, as long as it always moves downward from parent to child.
The problem gives us n nodes labeled from 0 to n - 1. For every node i, we are told which node is its left child and which node is its right child through the arrays leftChild and rightChild. If leftChild[i] = x, then node x is the left child of node i.
We are given a table representing the economy of Berland over n days and m months. Each cell in the table contains either 1 or -1, indicating a profit or a loss for that day of that month.
This problem asks us to create a completely independent copy of a linked list where each node contains two pointers: - next, which points to the next node in the list - random, which can point to any node in the list or null The key requirement is that the copied list must be…
The problem is asking us to solve a linear equation containing a single variable 'x' and integer coefficients, expressed as a string. The equation may include addition '+', subtraction '-', and the equality operator '='.
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 design a data structure that can efficiently answer majority element queries on subarrays of a given array.
This problem asks us to count the number of triples (i, j, k) from an integer array nums such that the bitwise AND of the three numbers at these indices equals zero. In other words, we want all combinations where nums[i] & nums[j] & nums[k] == 0.
Solomon stands on the fortress wall at position 0. To his right there may exist a chain of ice blocks occupying positions 1, 2, .... Initially there are no blocks at all. The battlefield is a line of length n. At battlefield position i, there may be a demon with strength a[i].
We need to compute the $n$-th hexagonal number. The sequence is defined by the formula $$hn = 2n^2 - n$$ The input contains a single integer $n$, and the output is the value produced by this formula.
This problem asks us to design a calendar system that supports adding time intervals and reporting the highest number of overlapping events seen so far. Each booking is represented as a half open interval [startTime, endTime).
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.
This problem gives us an undirected weighted graph with n nodes. Each edge connects two nodes and has a distance value associated with it.
This problem asks us to compute the post tax salary for every employee in the Salaries table. However, the tax rate is n
The problem gives us a numeric string num and an integer k. Each operation allows us to swap two adjacent digits. We may
This problem works with three relational database tables: Movies, Users, and MovieRating. The goal is to produce a result containing exactly two rows. The first row should contain the name of the user who rated the greatest number of movies.
This problem is asking us to transform an initial binary string s (all zeros) into a target binary string target using a
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 several bags of cookies, where each bag contains some number of cookies. Olga wants to steal exactly one bag. After removing that bag, the total number of cookies left behind must be even so the two sisters can split them equally.
The problem asks us to design a data structure that continuously receives integers from a stream and returns the average of the most recent values within a fixed-size sliding window. A sliding window means that we only care about the latest size elements.
The problem gives us an integer array nums and a window size k. A sliding window of length k starts at the beginning of the array and moves one position to the right at a time. For every position of this window, we must determine the maximum value inside that window.
The problem gives us an integer array nums and an integer k. We need to determine whether it is possible to divide all n
The problem gives two geometric shapes: 1. A circle, defined by: - radius - center coordinates (xCenter, yCenter) 2. An axis-aligned rectangle, defined by: - bottom-left corner (x1, y1) - top-right corner (x2, y2) The goal is to determine whether the circle and rectangle overlap.
We are given a subway system of n stations connected by exactly n passages, each passage connecting two distinct stations. The system forms a connected graph where each station can reach every other station.
The problem asks us to find the length of the shortest contiguous subarray whose sum is at least k. We are given an integer array nums, which may contain both positive and negative numbers, and an integer k.
This problem asks us to count how many valid ways exist to assign hats to people under two constraints: 1. Every person
The problem asks us to find the number of triplets (i, j, k) in an array arr such that the XOR of elements from index i
We are given a set of C-style #define macros and an expression, and we are asked to determine whether the expression becomes "suspicious" after macro substitution.
The problem gives us the root node of a binary tree and asks us to compute the sum of all left leaves in the tree. A binary tree node may have up to two children, a left child and a right child.
The problem asks us to sort a singly linked list in ascending order and return the head of the sorted list. The input is the head node of a linked list. Each node contains an integer value and a pointer to the next node.
The problem requires identifying all people in a group whose list of favorite companies is not a subset of any other per
The problem asks us to design a class called SubrectangleQueries that operates on a two dimensional integer matrix, refe
We are asked to plan snow purchases over n days from m companies, ensuring we buy exactly W cubic meters each day. Each company produces a fixed daily amount w[i], but the cost of all snow from that company decreases linearly: c[i] on day 1, c[i] - a[i] on day 2, and so on.
We are given a string of lowercase letters and an integer k. The task is to generate all possible substrings of the string, sort them lexicographically, and return the k-th substring in that order.
The problem gives us an array jobDifficulty, where each element represents the difficulty of a job. The jobs must be com
The problem gives us a binary matrix called grid, where: - 0 represents water - 1 represents land We can move only in four directions, up, down, left, and right.
The problem provides a tree rooted at node 0, represented in two parallel arrays: parent and value. The parent[i] array
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 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 is a two-player game played on a binary tree, where each player colors nodes starting from an initial chosen node. Player 1 picks a node x and colors it red, while Player 2 picks a different node y and colors it blue.
The problem gives us a wall made of multiple rows of bricks. Each row is represented as an array of integers, where each integer describes the width of a brick. Every brick has height 1, and all rows together form a rectangle with the same total width.
This problem asks us to design an iterator that can traverse a deeply nested list structure as if it were a flat list of integers. The input is not a normal array.
The problem gives us a strictly increasing array of positive integers, arr, and an integer k. The array does not necessa
We are given a convex polygon defined by a list of points in clockwise order. For each query point in the plane, we need to count how many triangles formed by the polygon’s vertices contain that point strictly inside.
The problem asks us to count all tuples (a, b, c, d) from a given array of distinct positive integers such that the product of the first two elements equals the product of the second two elements, a b = c d, and all elements are distinct.
The problem gives two arrays of positive integers, nums1 and nums2, both of equal length n. The goal is to calculate the absolute sum difference between these arrays, which is the sum of the absolute differences at each index: |nums1[i] - nums2[i]|.
This problem gives us two strings, s and t. The string t is created by taking all characters from s, shuffling them into a different order, and then inserting exactly one additional character somewhere in the string. Our task is to identify and return that extra character.
We are asked to simulate a queue of customers, where each customer has a known service time. The cashier can serve two people simultaneously, and the time to serve two people at once is the maximum of their individual times.
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 gives a collection of words on the left side of an equation and a single result word on the right side. Each distinct uppercase letter must be assigned a unique digit from 0 to 9.
The problem asks us to find the length of the longest uncommon subsequence between two strings a and b. To understand the problem clearly, we first need to understand what an uncommon subsequence means.
The problem asks us to replace every number in the input array with its rank when the array is sorted in ascending order.
This problem asks us to transform a Binary Search Tree, abbreviated as BST, into a "Greater Tree". In the transformed tree, every node's value should become: - its original value - plus the sum of all values greater than it in the original BST The structure of the tree does…
The problem asks us to design a class CombinationIterator that generates all combinations of a given length from a strin
We are given a collection of toy spiders. Each spider is a tree, represented by beads (nodes) connected with strings (edges). A spider with $k$ beads has $k-1$ strings connecting its beads so that all beads are connected and there are no cycles.
We are asked to help King Copa maximize his expected number of hits in a shooting gallery. The gallery is represented as a 2D plane, and each target appears at a specific point exactly at a specific time and disappears immediately afterward.
This problem is asking us to find the convex hull of a set of points on a 2D plane. The input trees is a list of coordinates where each coordinate [xi, yi] represents the location of a tree in the garden.
The problem gives us an integer array nums and a maximum jump distance k. We start at index 0, and from any position i,
The problem asks us to count all substrings of a given string s that contain at least one occurrence of each character '
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.
The problem asks us to count how many contiguous subarrays of length at least three form an arithmetic sequence. An arithmetic sequence is one where the difference between every pair of adjacent elements is identical.
The problem asks us to compute the maximal network rank for a set of cities connected by bidirectional roads. Each city can be thought of as a node in a graph, and each road as an undirected edge.
LeetCode 10, Regular Expression Matching, asks us to determine whether an entire input string s matches a pattern p. The pattern supports two special regular expression characters: - .
This problem models a squirrel collecting nuts in a 2D garden grid. The garden has a fixed tree position, a starting squirrel position, and multiple nuts scattered around the grid.
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.
We are given a point $(x, y)$ on the 2D plane and an angle $k$ in degrees. The task is to rotate the point counter-clockwise around the origin by exactly $k$ degrees and print the coordinates of the new point.
The problem asks us to find the length of the longest subsequence in an array such that the differences between consecutive elements alternate between positive and negative.
We are asked to place a space rescue station in three-dimensional space such that the maximum distance from it to any of the given planets is minimized. Each planet is represented by its coordinates $(x, y, z)$.
The problem asks us to determine whether a given integer n is a power of two. A number is considered a power of two if it can be written in the form: where x is a non-negative integer.
The problem asks us to compute, for every element in the array, how many elements to its right are strictly smaller than it. Given an array nums, we must return another array counts of the same length.
The problem gives us the head of a singly linked list and asks whether the sequence of values stored in the list forms a palindrome. A palindrome is a sequence that reads the same forward and backward.
The problem asks us to find the length of the longest contiguous substring in a string s that contains at most two distinct characters. A substring is a continuous sequence of characters inside the original string.
This problem asks us to transform a given integer n into 0 using a specialized set of bit-flipping operations. Each oper
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.
The problem is asking us to find the minimum cost to connect two groups of points, where the first group has size1 point
This problem asks us to design a very small parking lot management system. The parking lot contains exactly three types
This problem describes a frog moving through an undirected tree. A tree is a connected graph with no cycles, which means