brain
tamnd's digital brain — notes, problems, research
42659 notes
This problem asks us to determine how many times a given string word can be repeated consecutively while still appearing
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.
This problem asks us to design a small tracking system for an underground railway network. The system must support three
The problem asks us to find the largest connected component in a graph derived from an array of unique positive integers nums.
The problem gives us a list of points on a 2D coordinate plane. Each point is represented as [x, y], where x and y are integer coordinates. Our task is to determine the maximum number of points that lie on the same straight line.
We are given n marbles on a one-dimensional axis, each with a position x[i] and a pin cost c[i]. You can stick a pin in some marbles, paying the associated cost, and unpinned marbles will roll left until they hit the nearest pinned marble.
We have a group of soldiers, each with a rank between 1 and k. During one training session, soldiers are grouped by equal rank. From every group whose rank is still below k, exactly one soldier is promoted by one level.
Each student points to exactly one other student, the person they consider their best friend. We may create a pair (a, b) only if either a chose b or b chose a. Every student can belong to at most one pair.
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.
We are given a map of _n_ cities in Berland, where the shortest distances between all pairs are already known. Conceptually, this means the country is fully connected via some unknown set of roads, and the distance matrix is already the all-pairs shortest path result.
We are given a sequence of integers, and we are asked to extract the shortest subsequence that is _not ordered_. A sequence is considered ordered if it is either entirely non-decreasing or entirely non-increasing.
This problem asks us to determine the minimum initial health a knight needs in order to safely travel through a dungeon and rescue a princess.
This problem asks us to simulate a simple programming language with a single integer variable X that starts at 0. We are given a list of string operations, each of which either increments (++X or X++) or decrements (--X or X--) the value of X by 1.
A car starts at point A and moves along a straight road toward point B. The total distance is l meters, and the car always moves at a fixed speed v. Somewhere along the road, exactly d meters from the start, there is a traffic light.
The problem asks us to design a data structure that simulates an n x n Tic-Tac-Toe game between two players. We need to implement a class that supports two operations: - Initializing a game board of size n - Processing moves one at a time and immediately determining whether…
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.
The problem gives us an n x n matrix where both rows and columns are sorted in ascending order. This means two ordering guarantees exist simultaneously: - Every row is sorted from left to right. - Every column is sorted from top to bottom.
We have three transformation spells that convert one material into another. The first spell turns a grams of sand into b grams of lead. The second spell turns c grams of lead into d grams of gold. The third spell turns e grams of gold into f grams of sand.
The problem gives us an n x n binary matrix called grid. Each cell contains either 0 or 1. We are allowed to perform operations where we swap two adjacent rows. The goal is to transform the matrix into a valid configuration using the minimum number of adjacent row swaps.
The problem is asking us to generate the coordinates of cells in a 2D grid that we would visit if we started at a given cell (rStart, cStart) and walked in a clockwise spiral pattern.
This problem gives us the root of a binary tree where every node contains either 0 or 1. Each path from the root node to a leaf node represents a binary number, where the root contributes the most significant bit and each child adds another bit to the right.
This problem models a matching process between workers and bikes on a two dimensional grid. Each worker and each bike has a unique coordinate, and every worker must eventually receive exactly one bike.
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.
The problem defines an "ugly number" as any positive integer that is divisible by at least one of the three given integers a, b, or c.
In this problem, we are given an even number of people standing around a circle. Every person must participate in exactl
The problem gives us an integer array arr and asks us to compute the average value after removing the smallest 5% and th
This problem asks us to efficiently compute the dot product between two sparse vectors. A normal vector is simply an array of numbers. The dot product of two vectors is computed by multiplying corresponding elements and summing the results.
This problem asks us to modify a binary tree by removing every subtree that does not contain at least one node with value 1. A subtree consists of a node and all of its descendants. If an entire subtree contains only 0 values, then that subtree should be deleted from the tree.
The problem is asking us to identify a redundant edge in a graph that started as a tree. A tree is a connected graph with n nodes and exactly n-1 edges, meaning it has no cycles. The input graph has n nodes and n edges, so by definition, it contains exactly one cycle.
The problem gives us a string s containing only lowercase English letters. We repeatedly look for two adjacent characters that are equal, remove both of them, and continue this process until no such adjacent duplicate pair exists.
We are asked to find an integer point on a straight line described by the equation Ax + By + C = 0. The inputs are three integers, A, B, and C, which define the slope and position of the line.
Here’s a complete, detailed technical solution guide for LeetCode 787, following your formatting instructions exactly. The problem asks us to find the cheapest flight cost from a source city src to a destination city dst while taking at most k stops along the way.
The problem gives us a list of tasks, where each task is represented as [actual, minimum]. For every task: - minimum is the amount of energy we must currently have before we are allowed to start the task.
The problem is asking us to find the maximum difference between two elements in an array, with the condition that the smaller element appears before the larger element.
The problem asks us to find the k-th smallest number in lexicographical order among all integers from 1 to n. Lexicographical order means dictionary order, not numerical order.
The problem asks us to compute the sum of two integers without using the arithmetic operators + and -. Instead of relying on normal arithmetic, we must use bit manipulation to simulate how addition works at the binary level. The input consists of two integers, a and b.
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 an array called salary, where each element represents the salary of an employee. Every salary value
This problem asks us to implement a compressed string iterator. We are given a string where each character is immediately followed by a number representing how many times that character appears consecutively in the uncompressed version. For example, "a3b2" represents "aaabb".
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.
In this problem, we are given an array called costs, where each element represents the travel cost for one person to two different cities.
The garden is represented as an n × m grid. Each cell contains either 0 or 1. A 1 means there is a tree in that square, while 0 means the square is empty.
This problem asks us to determine whether a given binary tree satisfies the rules of a Binary Search Tree, commonly abbreviated as BST. A binary tree consists of nodes where each node contains a value and pointers to a left child and a right child.
The problem gives a date string in a human readable format such as "20th Oct 2052" and asks us to convert it into the st
We need to count stripe sequences built from four colors: black, red, white, and yellow. A sequence is valid if it satisfies several local restrictions. Equal adjacent colors are forbidden. White cannot touch yellow. Red cannot touch black.
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.
This problem asks us to determine how many non-negative integers x exist such that the factorial of x ends with exactly k trailing zeroes. The function f(x) counts trailing zeroes in x!. For example, f(3) = 0 because 3! = 6 has no trailing zeroes, and f(11) = 2 because 11!
This problem gives us the root of a Binary Search Tree, abbreviated as BST, and asks us to rearrange the tree into a very specific form.
The problem gives us a sorted array of lowercase English letters and a target character. Our task is to find the smallest character in the array that is strictly greater than the target character in lexicographical order.
This problem asks whether it is possible to divide n people into exactly two groups such that no pair of people who dislike each other end up in the same group.
We have an n × m chessboard. A billiard ball moves diagonally like a bishop, but unlike a bishop it reflects off the borders of the board. When it hits a vertical wall, the horizontal component of the direction flips. When it hits a horizontal wall, the vertical component flips.
We have a garden represented as a one-dimensional array of sections, each with a fixed height. Petya can create artificial rain above exactly one section, and water will flow to neighboring sections as long as their height is less than or equal to the section the water comes…
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.
The problem is asking us to identify all playback sessions during which no advertisements were shown. We are given two tables: Playback and Ads. The Playback table lists sessions for each customer, with the start and end times of each session.
This problem asks us to rearrange a list of non-negative integers so that, when concatenated together, they form the largest possible number. At first glance, this may look like a straightforward sorting problem where we simply sort the numbers in descending order.
We are given a list of integers where every number is either 1, 2, or 3. The goal is to transform the sequence so that all numbers are the same, and we want to do this using the smallest number of replacements possible.
The problem gives us three arrays of equal length: - startTime[i] represents when the i-th job starts - endTime[i] represents when the i-th job finishes - profit[i] represents the money earned if we complete that job Our goal is to select a subset of jobs that do not overlap…
The student is already riding a bus that moves along the x-axis from left to right. The bus stops at fixed positions (xi, 0) in increasing order. At any stop except the first one, the student may get off and run directly to the university located at (xu, yu).
This problem asks us to count how many contiguous subarrays of length k have an average value greater than or equal to a
The problem asks us to simulate a painter working on an 8×8 chessboard. Every square starts white, and the painter can perform only two operations: paint an entire row black or paint an entire column black. Painting the same square multiple times has no effect beyond the first.
The problem asks us to generate a string of length n such that each character in the string occurs an odd number of time
The problem gives us an integer array nums in which the largest value is guaranteed to be unique. Our task is to determine whether this largest number is at least twice as large as every other number in the array.
The problem gives two dates in the format YYYY-MM-DD and asks us to compute the absolute number of days between them. Each input string represents a valid calendar date. The year, month, and day are separated by hyphens.
Here’s a full, detailed technical solution guide for LeetCode 585 following your exact formatting rules: The problem presents an Insurance table containing policyholder information, including a unique policy ID (pid), investment values for 2015 (tiv2015) and 2016 (tiv2016)…
The problem asks us to count the number of valid teams of three soldiers from a line of n soldiers, where each soldier h
The problem gives us the head of a singly linked list and asks us to reorder the nodes in a very specific alternating pattern. A normal linked list looks like this: We must transform it into: The important detail is that we are not allowed to change node values.
The problem asks us to find employees with the highest salary in each department from a company database. The input consists of two relational tables: Employee and Department. The Employee table contains employee details, including id, name, salary, and departmentId.
The problem asks us to generate every strobogrammatic number of a given length n. A strobogrammatic number is a number that still appears valid after being rotated 180 degrees. Not every digit works under rotation.
Here’s a full, detailed technical solution guide for LeetCode 756 - Pyramid Transition Matrix, following your formatting rules precisely.
This problem asks us to construct a special ordering of all integers from 0 to 2^n - 1. The ordering must satisfy the properties of a circular Gray code sequence.
We want to cook soup using several ingredients that must appear in a fixed ratio. If the recipe says the proportions are a1, a2, ..., an, then the final soup must contain:
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.
The problem is asking us to identify the center node of a star graph. A star graph is a very specific type of graph with n nodes: there is one node called the center, and it is connected to all other n-1 nodes.
In this problem, a biker starts at altitude 0 and travels through a sequence of roads. The input array gain describes how the biker's altitude changes between consecutive points on the trip. If gain[i] is positive, the biker climbs upward between point i and point i + 1.
The problem asks us to build a basketball team with the maximum possible total score, while ensuring that the team does not contain any conflicts.
We are asked to analyze a two-player game with a single pile of n stones. The players alternate turns, starting with Serozha.
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 are asked to design a network of servers where each server is a node, and each connection between two servers is an undirected edge. There are n servers and we are allowed exactly m connections.
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 gives two inputs: a pattern string and a space-separated string of words. We need to determine whether the sequence of words follows the same structure as the sequence of characters in the pattern.
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.
This problem asks us to implement a read function using a restricted API called read4. The file itself is hidden from us, and the only way to access its contents is by repeatedly calling read4.
This problem asks us to find the smallest number greater than or equal to n that satisfies two properties simultaneously: 1. The number must be a palindrome. 2. The number must be prime. A palindrome is a number that reads the same forward and backward.
This guide is quite large and highly detailed under your required structure, especially with full worked examples, both
We are asked to simulate a turn-based game involving two players, Ciel and Hanako, who alternate taking coins from a common pile. The pile initially contains x 100-yen coins and y 10-yen coins. On each turn, the active player must remove exactly 220 yen.
We are given two positive integers, a and b. First we compute their normal sum c = a + b. Then we apply the same transformation to all three numbers: remove every digit 0 from their decimal representation. The question is whether the transformed equation still holds.
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.
Each student points to exactly one other student, the person they call whenever they hear news. This creates a directed functional graph, every node has out-degree exactly one.
The problem asks us to find the number of distinct non-empty substrings of a given string text that can be expressed as
We are asked to start with the number pair (1,1) and reach a pair where at least one of the numbers equals a given target n. At each step, we can add one number to the other to form a new pair. Concretely, if our current pair is (a, b), the next pair can be (a+b, b) or (a, a+b).
The problem gives us a string s containing only the characters 'a', 'b', and 'c'. We may repeatedly perform a deletion operation on the string.
We are given a rectangular map of size n × m, where each cell has a non-negative height. Peter wants to build cities of size a × b. To place a city, he must level the ground inside its rectangle by reducing all cells to the minimum height within that rectangle.
We are given the final standings of a table bowling tournament. Every participant has a unique name and an integer score. The task is not just to sort the players, but also to assign ranking labels in the style used in real tournaments.
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 compute the number of ways to completely tile a 2 x n board using two types of tiles: a domino (2 x 1) and a tromino shape.
The problem gives us two strings, s1 and s2, and asks us to make them equal by deleting characters from either string. Every deleted character contributes its ASCII value to the total cost. Our goal is to minimize this total deletion cost.
The task is to find the next time on a 24-hour digital clock that reads as a palindrome. The input is a string formatted as "HH:MM", representing hours and minutes in 24-hour notation.
This problem asks us to analyze a database table named Submissions and determine how many unique comments belong to each post.
We have a fixed starting point, the handbag, and up to 24 scattered objects on a 2D plane. Lena always starts at the handbag, walks around collecting at most two objects, returns to the handbag, then repeats until every object is stored back.
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.