brain
tamnd's digital brain — notes, problems, research
43815 notes
The problem asks us to determine whether a given integer becomes a different valid number after being rotated by 180 degrees. Not every digit remains valid after rotation.
We have a tree where each vertex initially contains some number of beavers. The robot starts at a fixed vertex s. Every time it traverses an edge from u to v, it immediately eats exactly one beaver at v. If v already has zero beavers left, the move is impossible.
We are given a rectangular board filled with playing cards. The board size is at most $17 times 17$, but the total number of placed cards never exceeds 52 because the deck has only 52 regular cards plus two jokers. A valid 3×3 square must satisfy one of two properties: 1.
Vasya currently holds rank a in the army and wants to eventually reach rank b. Moving from rank i to rank i + 1 requires a fixed number of years, stored in the array d.
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.
We are given an undirected connected graph representing roads between junctions. The mayor wants to remove some roads so that the remaining graph becomes a tree, meaning it stays connected and contains exactly n - 1 edges.
This problem asks us to maximize the profit from stock trading under a strict constraint: we can perform at most k transactions, where each transaction consists of buying and then later selling one share of the stock.
The problem asks us to find the rectangular submatrix whose sum is as large as possible while still being less than or equal to a given integer k. A rectangle in a matrix is any contiguous block of cells formed by choosing a range of rows and a range of columns.
The problem gives us a database table named Activities with two columns: | Column | Meaning | | --- | --- | | selldate |
The problem asks us to modify a given palindromic string in such a way that it is no longer a palindrome while ensuring
The problem asks us to find the kth largest element in an unsorted integer array. The important detail is that we are looking for the element that would appear in the kth position if the array were sorted in descending order. We are not looking for the kth distinct value.
The problem asks us to design a mutable 2D range sum data structure. We are given a matrix of integers, and we must support two operations efficiently: 1. Update the value at a specific cell. 2. Compute the sum of all values inside a rectangular submatrix.
This problem asks us to build the smallest possible team that collectively covers every required skill. We are given two inputs: - reqskills, a list of unique required skills - people, where people[i] contains the skills possessed by person i A team is considered sufficient if…
This problem asks us to find the largest possible island size in a binary grid after changing at most one 0 into 1.
We are asked to simulate a warehouse with a grid-like shelving system. Each shelf has m sections, and there are n shelves stacked from top to bottom. Every section can hold at most one box.
The problem asks us to find the number of ordered pairs of indices (i, j) in a list of digit strings nums such that concatenating nums[i] and nums[j] produces exactly the string target.
This problem asks us to identify the seller or sellers who generated the highest total sales revenue. We are given two database tables: Product and Sales. The Product table contains information about products, including their IDs, names, and unit prices.
This problem asks us to find all words that are considered "uncommon" between two sentences. Each sentence is made up of lowercase words separated by single spaces. A word is considered uncommon if it satisfies two conditions: 1. It appears exactly once in one sentence. 2.
We are given two dates in the format DD.MM.YY: one representing the day of the Codeforces World Finals and the other representing Bob's date of birth. Bob can rearrange the components of his birth date-the day, month, and year-but only as complete numbers, not individual digits.
This problem asks us to search for a target value inside a sorted array, but with an important limitation: we do not know the size of the array, and we cannot access the array directly. Instead of normal array indexing, we interact with the array through an ArrayReader interface.
The problem is asking to find the maximum dot product of two non-empty subsequences of arrays nums1 and nums2 such that
We are given a tree with _n_ nodes, described by _n-1_ edges. A tree is a connected acyclic graph, so there is exactly one path between any two vertices. Bob can delete any subset of edges, possibly none, and then he looks at the sizes of the resulting connected components.
The problem asks us to determine whether a given binary tree is a complete binary tree. A complete binary tree has a specific structural property: every level, except possibly the last, is completely filled, and in the last level, all nodes appear as far left as possible.
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.
We are given two uppercase strings, s and t. We may transform s using three operations: 1. Insert a character at any position. 2. Delete a character from any position. 3. Replace one character with another. Every operation costs exactly one move.
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 design a very small parking lot management system. The parking lot contains exactly three types
The problem is asking us to find the length of the longest good palindromic subsequence in a given string s. A good pali
The problem is asking us to determine the earliest time at which a group of n people all become mutually acquainted, given a sequence of friendship formation events with timestamps.
The problem describes a corrupted set of integers. Originally, the set contained every number from 1 through n exactly once. Because of an error, one number was duplicated, which means one other number disappeared.
We are asked to determine whether a set of non-zero integers forms a "friendly group," meaning every pair of numbers satisfies a divisibility relationship: one number divides the other.
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.
The problem presents three stones placed on distinct positions along a one-dimensional X-axis, represented by integers a, b, and c.
We are given a sequence of binary strings, all of equal length, and we need to split them into two subsequences in a way that minimizes the sum of the lengths of their compressed forms.
The problem gives us a 2D grid called picture, where each cell contains either: - 'B', representing a black pixel - 'W', representing a white pixel We need to count how many lonely black pixels exist in the matrix. A black pixel is considered lonely if: 1. It is black ('B') 2.
The problem asks us to reverse the order of words in a character array s in-place. Each word is a contiguous sequence of non-space characters, and words are separated by exactly one space.
We are asked to evaluate a string expression in a small function-based language. Every string literal is enclosed in quotes, and there are only four types of functions: concat, reverse, and substr in two forms. Each function operates only on strings or integers as indices.
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 asks us to randomly pick an integer point from a set of non-overlapping rectangles in 2D space. Each rectangle is defined by its bottom-left (ai, bi) and top-right (xi, yi) corners.
Jack starts at position 0 on a number line. His jumps have fixed lengths: the first jump must have length 1, the second jump length 2, the third jump length 3, and so on. For every jump he may choose either direction.
The problem asks us to determine whether an array contains three numbers that form a strictly increasing subsequence.
This problem asks us to rank integers according to a special metric called the "power value". The power value of a numbe
The problem asks us to count how many subtrees in a binary tree are "uni-value" subtrees. A uni-value subtree is a subtree in which every node has the same value. A subtree consists of a node together with all of its descendants.
We have an array of cow weights. For every query (a, b), we repeatedly take positions a, a + b, a + 2b, ... until the index exceeds n, and we must output the sum of all visited values.
The problem asks us to find the largest integer less than or equal to a given number n, such that its digits are monotone increasing. A number has monotone increasing digits when every digit is less than or equal to the digit that comes after it.
The task gives spreadsheet cell coordinates written in one of two formats, and for every coordinate we must convert it into the other format.
The problem gives us an absolute Unix-style file path and asks us to convert it into its canonical, simplified form. An absolute path always starts from the root directory, represented by /.
The problem gives us an integer array nums that may contain duplicate values. We must design a class that supports repeatedly selecting a random index for a given target value.
We are given a polynomial already factorized into linear terms: $$p(x) = (x + a1)(x + a2)dots(x + an)$$ The task is to expand this product and print the polynomial in the usual descending-power form: $$x^n + b1x^{n-1} + dots + bn$$ The tricky part is not the expansion itself.
The problem asks whether the characters of a given string can be rearranged to form a palindrome. A palindrome is a string that reads the same forward and backward. Examples include "racecar", "abba", and "a".
The problem is asking us to determine the minimum number of semesters required to complete n courses given a set of prerequisite relationships.
The problem gives us an array called piles, where each element represents the number of coins in a pile. The length of the array is always divisible by 3, meaning there are exactly 3n piles for some integer n. In every round, three piles are selected.
We are given a database table called Traffic that records different user activities on different dates. Each row contains a userid, an activity type, and an activitydate.
The problem asks us to determine whether an integer array nums can be split into four non-empty subarrays with equal sums by selecting three indices i, j, and k that satisfy strict ordering constraints: 0 < i, i + 1 < j, j + 1 < k < n - 1.
We are given a multiset of numbers and asked whether it is possible to arrange them in a circle so that every pair of adjacent numbers differs by exactly one. Conceptually, this means each number is a vertex on a cycle, and the absolute difference between neighbors must be 1.
The problem gives an integer array nums and asks us to build a subsequence whose sum is strictly greater than the sum of
The problem asks us to determine the minimum number of operations required to transform a given password into a "strong" password according to three rules. A strong password must satisfy all of the following conditions: 1.
This problem describes a hierarchical relationship between geographic regions. Each list in regions represents a parent-child relationship where the first element is the parent region and every remaining element in the list is directly contained within that parent.
The problem asks us to count the number of 3 x 3 magic squares inside a larger grid. A magic square is defined as a square where all numbers are distinct integers from 1 to 9 and the sum of each row, column, and the two diagonals is the same.
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.
The problem gives us a database table named Orders with two columns: Column Meaning --- --- ordernumber Unique identifier for an order customernumber Identifier for the customer who placed the order Each row represents a single order placed by a customer.
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 problem asks us to transform a table of student names and their continents into a pivoted report, where each continent becomes a column and the student names appear alphabetically under their respective continents.
The problem gives us a sorted integer array nums in strictly increasing order and asks us to convert it into a height-balanced binary search tree (BST). A binary search tree is a binary tree where: - Every node in the left subtree contains values smaller than the current node.
We are asked to count the number of valid ski bases after each road is added to an initially empty graph. The graph consists of junctions as vertices and roads as edges.
We are given a country with cities connected by roads such that the road network forms a tree: there is exactly one simple path between any two cities. Each road has equal length in terms of counting the number of edges.
The problem gives us a string representing a mathematical expression containing integers, addition, subtraction, parentheses, and spaces. Our task is to evaluate the expression and return the final integer result. The expression is guaranteed to be valid.
This problem gives us a database table named Tree, where each row represents a node in a tree structure. Every node has a unique identifier id and a pid column that stores the identifier of its parent node.
We are given a circular arrangement of hills around a capital. Each hill has a height and a watchman who can send signals via fire. The core question is: how many pairs of watchmen can see each other’s signals?
The problem gives us a numeric string num and an integer target. We must insert binary operators, specifically '+', '-', and '', between the digits of the string so that the resulting mathematical expression evaluates exactly to target.
In this problem, we are given a string text that must be displayed on a single line inside a screen with width w and hei
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.
We are asked to navigate a graph of cities connected by bidirectional roads, with a twist: certain sequences of three consecutive cities are forbidden due to superstition. Formally, there are n nodes and m edges, all unweighted, representing cities and roads.
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.
Each student group attends exactly two lessons. For a group, the classroom used in the first lesson must not exceed the classroom used in the second lesson.
We start with a distinct boxes and b distinct items. Since boxes may stay empty and every item independently chooses one of the boxes, the number of possible placements is simply:
That is a long, structured reference document. To make sure I target the exact problem correctly, please confirm the Lee
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.
The problem asks us to find every element in an integer array that appears more than ⌊ n/3 ⌋ times, where n is the length of the array. The floor notation means we round down to the nearest integer.
This problem asks us to return every cell in a matrix, ordered by its Manhattan distance from a given center cell.
The problem gives us an integer array nums and an integer k. For every element in the array, we must choose exactly one of two operations: - add k - subtract k After modifying every element, we calculate the score of the array, which is defined as: Our goal is to minimize this…
We need to compute the remainder when $a^b$ is divided by $c$. The input gives three integers, one per line. The first value is the base, the second is the exponent, and the third is the modulus. The direct interpretation is straightforward.
The problem asks us to transform a given integer array nums into a continuous array with the minimum number of operations.
We process students one by one. Each student either has a fixed house, represented by one of the letters G, H, R, S, or has ambiguous ancestry, represented by ?. A fixed student always goes into that house. A ? student behaves differently.
The problem asks us to extend the functionality of a standard iterator with an additional peek operation. A standard iterator provides two operations: next(), which returns the next element in the sequence and advances the pointer, and hasNext(), which tells whether there are…
The problem asks us to determine the number of similarity groups within a list of strings. Two strings are defined as similar if they are either identical or if we can swap exactly two letters in one string to make it equal to the other.
We have a rooted tree with root at city 1. Every city initially contains exactly one military division. Division i starts in city i and has priority a[i], where a smaller value means higher priority. Each edge has a capacity.
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.
This problem asks us to compute the transpose of a given two dimensional matrix. A transpose operation flips a matrix across its main diagonal.
The traversal is by reference, not value.
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.
The problem asks us to convert a positive integer into its Roman numeral representation. Roman numerals use combinations of specific symbols to represent values, and the rules for combining those symbols are strict.
The problem gives us a non-empty array of digits that together represent a large integer. Each element in the array is a single decimal digit, and the digits are stored in left-to-right order from the most significant digit to the least significant digit.
The problem describes a two-player game played on an integer array. Players alternate turns, and during each turn a player may only take a number from one of the two ends of the array. The chosen value is added to that player's score, and the element is removed from the array.
The problem gives us a sentence s and an integer k. A sentence is guaranteed to contain words separated by exactly one space, with no extra spaces at the beginning or end. Our task is to return a new sentence that contains only the first k words from the original sentence.
This is a SQL database problem where we need to identify the employees who belong to the top three unique salaries within each department.
We are given six words and must arrange them into a very specific crossword shape. The shape looks like a rectangular infinity symbol. There are three horizontal words and three vertical words, and they intersect at fixed positions.
The problem gives us a string that represents the preorder serialization of a binary tree. Each value is separated by commas. A normal integer represents a real tree node, while the character '' represents a null pointer.
Here’s a complete, detailed technical solution guide for LeetCode 1537 - Get the Maximum Score following your requested
This problem asks us to find the k strongest values in an array according to a custom definition of "strength". The firs