brain
tamnd's digital brain — notes, problems, research
42715 notes
The problem is asking whether it is possible to convert one string s into another string t using at most k moves, follow
The problem gives a string s and asks us to create the shortest possible palindrome by adding characters only at the beginning of the string. A palindrome is a string that reads the same forward and backward.
We are asked to process a user-entered sequence of page numbers for printing. The input is a single string of positive integers separated by commas, such as 1,2,3,1,1,2,6,6,2. Some numbers may repeat, possibly non-consecutively.
The problem gives us two inputs: an array of strings called words, and a target string s. Every occurrence of every word from words inside s must become bold by surrounding that substring with <b and </b tags.
This problem asks us to determine the maximum number of ice cream bars a boy can buy with a limited number of coins. The input consists of an array costs, where costs[i] represents the price of the i-th ice cream bar, and an integer coins representing the total coins available.
This problem asks us to find the minimum number of jumps required for a bug to move from position 0 to position x on a one dimensional number line. The bug follows several movement rules: - It may jump forward by exactly a units. - It may jump backward by exactly b units.
This problem gives us the head of a singly linked list and two integers, m and n. We must traverse the linked list while
The problem asks us to determine whether a given list of strings forms a valid word square. A word square is a special arrangement of words such that the kth row and the kth column contain the same sequence of letters for every valid index k.
This problem asks us to find the k values in a Binary Search Tree, or BST, whose values are numerically closest to a given floating point target. A BST has a very important property: - Every value in the left subtree is smaller than the current node.
This problem asks us to locate the first occurrence of one string inside another string. The string we are searching for is called needle, and the larger string we search inside is called haystack.
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.
The problem gives us a string s consisting only of lowercase English letters. We must find the index of the first character that appears exactly once in the entire string. If every character appears more than once, we return -1.
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.
The problem asks us to calculate the perimeter of an island represented in a 2D grid. Each cell in the grid is either land (1) or water (0). The island consists of one or more connected land cells, where connectivity is strictly horizontal or vertical.
We are given a set of cups, each containing some amount of juice, and we want to determine whether the volumes could result from the pages pouring juice from one cup to another exactly once, or not at all.
The problem gives us a binary matrix mat of size m x n, where every cell contains either 0 or 1. We need to find the length of the longest consecutive sequence of 1s that appears in any of four directions: 1. Horizontal, from left to right 2. Vertical, from top to bottom 3.
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 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.
This problem asks us to find the most recent order for every product that has been ordered at least once. We are given t
We are given an encrypted password represented as a binary string of length 80. The original password had exactly 8 decimal digits, and each digit was encoded into a block of 10 binary characters.
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 gives an array of unique integers called preorder. This array is supposed to represent the preorder traversal of a binary search tree, and we must determine whether such a BST could actually exist. In a preorder traversal, nodes are visited in this order: 1.
We have a collection of items, and every item belongs to exactly one of three equipment classes: weapon, armor, or orb. Each item has three base stats, attack, defense, and resistance, plus a capacity telling us how many residents it can hold. Residents also come in three types.
This problem asks us to find the smallest element in a sorted array that has been rotated some number of times. A sorted array in ascending order might originally look like this: After rotation, it could become: or remain unchanged: The important observation is that the array…
We are asked to simulate a turn-based game between two players, Simon and Antisimon, who each have a fixed integer, a and b respectively. There is a heap of n stones.
This problem asks us to design an iterator over a run-length encoded sequence instead of storing the full sequence explicitly.
The task is to compute a kind of "distance" between a user-entered address and a list of potential addresses, according to a specific error function. The user enters a string s of length k. Then there are n potential addresses, each a string of arbitrary length.
The problem gives us two inputs: - An integer array nums - A list of queries, where each query is [xi, mi] For every query, we must find the maximum possible value of: subject to the condition: If no number in nums satisfies the condition nums[j] <= mi, then the answer for…
The problem presents a string time formatted as hh:mm, where h and m are digits representing hours and minutes, respectively. Some digits may be hidden and are represented by a question mark ?. The goal is to replace the ?
We are given a set of small arrays and a sequence of indexes indicating how to concatenate them into one larger array. Once the large array is built in this way, the goal is to find the maximum sum of a contiguous subarray.
Edit The problem gives us a string s and asks for the minimum number of insertion operations required to transform the s
We are given a filesystem path as a string. In this operating system, multiple consecutive '/' characters are treated exactly the same as a single '/'. That means paths like ///home//user///docs and /home/user/docs refer to the same location.
The problem asks us to count how many contiguous subarrays contain exactly k odd numbers. We are given an integer array
The problem asks us to count all substrings in a string where every character inside the substring is identical. These are called homogenous substrings. A substring must be contiguous, meaning the characters must appear next to each other in the original string.
The problem asks us to transform a string s containing only characters 'X' and 'O' so that all characters become 'O'. A move consists of selecting three consecutive characters and converting them to 'O'. If a character is already 'O', it remains unchanged.
The problem provides a list of meeting intervals, where each interval is represented as [start, end]. Each pair describes the start time and end time of a meeting. The task is to determine whether a single person can attend every meeting without any scheduling conflicts.
The problem asks us to split a string into substrings such that every substring is a palindrome. Among all valid palindrome partitions, we must return the minimum number of cuts required. A cut divides the string into two parts.
The problem describes a supermarket that sells products identified by unique integer IDs. Each product has a corresponding price. Customers purchase products in certain amounts, generating a bill that is the sum of the prices multiplied by the amounts purchased.
The problem is asking us to query a database table called Cinema and return a filtered set of movies based on two conditions: the movie ID must be odd, and its description must not be "boring". The result must then be sorted in descending order by the movie's rating.
The problem asks us to find the smallest positive integer x such that the product of all of its digits equals the given integer num.
The problem asks us to count how many strings of length n satisfy three conditions simultaneously: 1. The string must be lexicographically greater than or equal to s1 2. The string must be lexicographically less than or equal to s2 3.
The problem asks us to count how many index triplets (i, j, k) satisfy two conditions: - The indices must follow the order i < j < k - The values at those indices must sum to the given target Formally, we want: The important detail is that we are counting tuples of indices…
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.
The problem presents an undirected graph with n nodes and three types of edges: Type 1 for Alice, Type 2 for Bob, and Ty
The problem gives us a string that contains encoded patterns of the form k[encodedstring]. The integer k tells us how many times the substring inside the brackets should be repeated. Our task is to fully decode the string and return the expanded result.
The problem is asking us to simulate a single-tab browser with a history mechanism. You start on a homepage, and from there, you can visit new URLs, backtrack a certain number of steps, or forward a certain number of steps.
We are asked to count all distinct real roots of quadratic equations of the form , where ranges from 1 to and ranges from 1 to . Each pair defines one quadratic. The output is the total number of distinct real roots across all these quadratics.
The problem gives us two strings, start and result, both consisting only of the characters 'L', 'R', and 'X'. We are allowed to transform the start string using only two kinds of moves: - Replace "XL" with "LX" - Replace "RX" with "XR" The goal is to determine whether it is…
The problem asks us to construct a maximum binary tree from a given integer array nums with unique elements. A maximum binary tree is a binary tree where each node is the maximum element of the subarray it represents.
We are given a string consisting of letters and digits, and we are asked to compute a special measure for every prefix called the _palindrome degree_.
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.
The problem gives us a sorted array of positive integers, nums, and a target integer n. We are allowed to insert additional numbers into the array, called patches.
This problem asks us to generate the shortest possible abbreviation for a given target word such that the abbreviation cannot also represent any word in the dictionary. An abbreviation replaces one or more non-adjacent substrings with their lengths.
This problem asks us to determine whether a car can successfully complete a series of passenger trips without ever exceeding its seating capacity.
The task is to decompose a given integer n into its prime factors and print them in non-decreasing order, with each prime repeated according to its multiplicity. Essentially, if a number is a product of primes like $n = 2^2 cdot 3^1 cdot 5^2$, the output should be 2 2 3 5 5.
The problem describes a set of cars driving toward the same destination, represented by the integer target. Each car starts at a unique position and moves at a constant speed. Cars cannot overtake each other.
The problem asks us to find the smallest positive integer that does not appear in an unsorted integer array. The key detail is that we only care about positive integers starting from 1.
The problem gives an array nums consisting of positive integers. We must find the longest prefix of the array such that, after removing exactly one element from that prefix, every remaining number appears the same number of times.
Petr is standing somewhere in a line containing n people. Positions are numbered from 1 at the front to n at the back. He knows two things about his position. At least a people are standing in front of him, and at most b people are standing behind him.
We are given the sequence of goals scored during a football match. Every line after the first contains the name of the team that scored one goal. The task is to determine which team scored more goals overall.
The problem provides an m x n binary matrix, grid, where each element is either 0 or 1. You are allowed to perform a move, which consists of selecting any row or column and flipping all its values - turning every 0 into a 1 and every 1 into a 0.
The problem gives us an integer array nums and an integer k. We are allowed to split the array into at most k contiguous, non-empty subarrays. For each subarray, we compute its average, then sum all of those averages together. Our goal is to maximize that total score.
We are given a small grid of lowercase letters. A cell survives only if its letter is unique both inside its row and inside its column. If the same character appears somewhere else in the same row, that cell is removed.
We need to construct n distinct positive integers with two simultaneous properties. First, every pair of numbers must share a common divisor larger than 1. In other words, for every pair (ai, aj), their gcd cannot equal 1. Second, the gcd of the entire set must equal 1.
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.
The problem asks us to determine the minimum number of deletion steps required to make two strings identical. We are given two input strings, word1 and word2, and in each step, we can delete exactly one character from either string.
The problem asks us to compute the sum of the minimum value of every possible contiguous subarray of a given array. For an array arr, every contiguous slice of the array is considered a subarray. For each subarray, we determine its minimum element.
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.
Here is a complete, detailed technical solution guide for LeetCode 1382 - Balance a Binary Search Tree, following all yo
The problem gives an array stones representing positions of stones on the X-axis, where each position is unique. The goal is to move the endpoint stones-the stones at the smallest and largest positions-so that eventually all stones occupy consecutive positions on the X-axis.
The problem asks us to count how many integers in the range [1, n] contain at least one repeated digit. A repeated digit means that some digit appears more than once in the number. For example, 11 has a repeated 1, 100 has repeated 0, and 121 has repeated 1.
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.
The problem gives us a binary string s, which means the string contains only the characters '0' and '1'. In one operation, we are allowed to flip a character, meaning we can change '0' into '1' or '1' into '0'.
The problem asks us to convert a given 32-bit integer num into its hexadecimal representation as a string. Hexadecimal, or base-16, uses digits 0-9 and letters a-f to represent values 0-15.
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.
Alice gives Bob a decimal number and asks him to rearrange its digits so that the resulting number is as small as possible, while still being a valid decimal number without leading zeroes.
This problem asks whether we can satisfy a set of customer requests using repeated integers from the array nums. Each customer wants a certain quantity of numbers, given by quantity[i]. The important restriction is that every number given to a single customer must be identical.
We are given a party scenario where Petya invited n friends, each of whom gave exactly one gift to another friend. The input lists, for each friend in order, the friend they gave a gift to.
The problem asks us to find all integers within a given range [low, high] whose digits are sequential, meaning that each
This problem asks us to determine whether a circular array contains a valid cycle under a specific movement rule. Each element in the array represents how far we move from the current index.
This problem requires determining how many candidates a company can hire as seniors and juniors under a fixed budget of $70000, following a strict priority: hire as many seniors as possible first, then use the remaining budget to hire juniors.
This problem asks us to count how many root to leaf paths in a binary tree are "pseudo-palindromic". A palindrome is a s
This problem extends the mechanics introduced in earlier Maze problems, but adds two important complications. First, we are no longer looking for a simple reachable or unreachable answer. Instead, we must find the shortest path by travel distance.
A maximum tree is a special binary tree where every node contains a value greater than all values inside its subtree.
We start with a row of n panels, all turned OFF. The target password is another configuration where exactly k specific positions must be ON and every other position must remain OFF. One operation chooses a segment of consecutive panels whose length belongs to the array a.
The problem asks us to count how many words in a given list are subsequences of a string s. A subsequence is formed by deleting zero or more characters from the string without changing the order of the remaining characters.
The problem provides a database table named Activity. Each row represents one login session for a player on a specific date.
The problem asks us to identify customers who meet a very specific purchasing pattern. We are given two tables: Customer
We have an array arranged in a circle. Every operation works on a segment between two indices, but the segment may wrap around the end of the array.
We start with an undirected graph that may be disconnected and may contain cycles. We are allowed to repeatedly merge two vertices into one. Merging decreases the number of vertices by one, while the number of edges stays unchanged.
We start with a vector A = (x1, y1) and want to transform it into another vector B = (x2, y2). Two operations are allowed. We may rotate the current vector by 90 degrees clockwise, and we may add vector C = (x3, y3) any number of times. The operations may be mixed in any order.
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.
The problem provides a database table named Employee that stores information about which departments employees belong to.
This problem asks us to find the largest axis-aligned plus sign made entirely of 1s in an n x n binary grid. Initially, every cell in the grid contains 1. However, some positions are marked as mines, meaning those cells contain 0.
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 asks us to design a data structure that supports efficient range sum queries on a fixed array. We are given an integer array nums, and after initialization, the array never changes.
This problem asks us to count how many subarrays have sums that fall within a given inclusive range [lower, upper]. A range sum S(i, j) represents the sum of all elements from index i through index j in the array.
The problem is asking us to take an existing m x n matrix and "reshape" it into a new matrix with r rows and c columns. Reshaping means rearranging the elements in the matrix in row-major order (left-to-right, top-to-bottom) without changing the order of the elements themselves.
This problem asks us to compute a complete league table from two database tables, Teams and Matches. The Teams table contains the identity of each team in the league. Each row represents one team and includes a unique teamid and the corresponding teamname.
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).