brain
tamnd's digital brain — notes, problems, research
42648 notes
We are asked to organize a company party such that no group contains both a manager and their subordinate, directly or indirectly. The input describes each employee's immediate manager: a number from 1 to n, or -1 if they have no manager.
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.
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 have n fish in a lake. Every day, exactly one unordered pair of currently alive fish is chosen uniformly at random. When fish i meets fish j, fish i eats fish j with probability a[i][j], and fish j eats fish i with probability a[j][i] = 1 - a[i][j].
The problem asks us to calculate the maximum absolute sum of any contiguous subarray in a given integer array nums. A subarray is a sequence of consecutive elements, and its absolute sum is defined as the absolute value of the sum of all elements in that subarray.
The problem asks us to compute the n-th number in the Tribonacci sequence. The Tribonacci sequence is very similar to the Fibonacci sequence, except that instead of summing the previous two numbers, each value is formed by summing the previous three numbers.
The problem asks us to find the optimal location for a service center on a 2D map such that the total Euclidean distance
The problem gives us an integer array nums and an integer k. For every element in the array, we are allowed to modify it once by adding any integer value in the range [-k, k].
The problem is asking for the minimum number of steps required to reach the last index of an integer array, starting fro
This problem requires designing a specialized stack data structure, called CustomStack, that not only supports the usual
The problem asks us to find the minimum number of moves required to reach a specific position on an infinite number line starting from position 0. Each move i allows you to move exactly i steps, either to the left or the right.
This problem asks us to build a new array called target by following a sequence of insertion operations. We are given tw
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.
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 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.
The problem asks us to round an array of decimal prices to integers such that the sum of the rounded numbers equals a given target, while minimizing the total rounding error. Each price can be rounded either down (Floor) or up (Ceil).
The problem asks us to determine whether we can select disjoint subarrays from a given array nums such that each subarray matches exactly one of the subarrays in the groups array, in order.
This problem asks us to determine whether a rolling ball can stop exactly at a destination cell inside a maze. The maze is represented as a two-dimensional grid where: - 0 represents an empty space the ball can roll through - 1 represents a wall The important detail is that…
The problem gives us an integer array nums and asks us to move every 0 element to the end of the array while preserving the relative order of all non-zero elements. The phrase "relative order" is extremely important.
The problem asks us to compute the Hamming distance between two integers. The Hamming distance is defined as the number of bit positions where the two numbers differ in their binary representation. For example, consider x = 1 and y = 4.
The problem asks us to design a data structure that continuously tracks the kth largest element in a stream of integers. We are given an integer k and an initial list of numbers called nums. After initialization, new numbers are added one at a time using the add method.
The problem gives us a numeric string num and an integer k. Each operation allows us to swap two adjacent digits. We may
The problem gives us a target array and asks us to build it starting from an array of all zeros. The only operation allowed is selecting any contiguous subarray and incrementing every element in that subarray by exactly one.
The problem asks us to design a data structure that manages a fixed pool of phone numbers. Initially, every number from 0 to maxNumbers - 1 is available. The directory must support three operations efficiently. The get() operation should assign and return an available number.
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 asks us to determine whether a given string can be formed by repeating one of its substrings multiple times. In other words, we want to know if there exists some substring pattern such that concatenating that pattern repeatedly recreates the entire string exactly.
We are given three lines representing the three phrases of a poem. A valid haiku must contain exactly 5 vowel letters in the first phrase, 7 in the second, and 5 in the third. For this problem, syllables are simplified into vowel counts.
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 certain substrings of a given string s can be rearranged and partially modified to form a palindrome. A palindrome is a string that reads the same forward and backward.
The problem asks us to take a string s containing words separated by spaces and return a new string where the words appear in reverse order. A word is defined as any sequence of non-space characters, and words can be separated by multiple spaces.
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.
The problem asks us to detect cycles in a 2D grid of characters where all cells in the cycle must contain the same character. A cycle is defined as a path that starts and ends at the same cell and has a length of four or more.
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.
This problem asks us to determine the minimum number of cameras required to monitor all nodes in a binary tree. Each camera placed on a node can monitor its parent, itself, and its immediate children.
We are given an array of integers and a fixed window size k. For each contiguous subarray (segment) of length k, we need to find the largest element that appears exactly once within that segment. If no element appears exactly once, we output "Nothing".
The problem requires implementing a BSTIterator class that allows forward and backward traversal over the in-order sequence of a Binary Search Tree (BST). In-order traversal of a BST visits nodes in ascending order.
We have n seats and n professors. Professor 1 is the most senior, professor n is the least senior. Some pairs of seats impose ordering constraints. If (a, b) is given, then the professor sitting in seat a must be more senior than the professor sitting in seat b.
We are given a string written in the Borze encoding system. Every digit of a ternary number is represented by one of three patterns:
This problem asks us to find the in-order successor of a given node p inside a Binary Search Tree, abbreviated as BST. An in-order traversal of a BST visits nodes in sorted order: 1. Traverse the left subtree 2. Visit the current node 3.
This problem asks us to determine, for every user in the marketplace system, whether the brand of the second item they sold matches their favorite brand. The database contains three tables: - The Users table stores user information, including their favoritebrand.
The problem asks us to partition an array into the maximum possible number of contiguous chunks such that, after sorting each chunk independently and concatenating the results, the entire array becomes globally sorted. The key detail is that each chunk must remain contiguous.
The problem presents a grid where each cell represents a street segment with a specific orientation, denoted by a number
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 is asking us to find the minimum cost to connect two groups of points, where the first group has size1 point
We start with a rectangle drawn on grid paper. Only the border matters, not the interior. Players repeatedly draw a strictly smaller rectangle inside the previous one.
The problem gives us an m x n multiplication table where each cell contains the product of its row index and column index, using 1-based indexing. That means the value at position (i, j) is simply i j.
This problem asks us to implement a thread-safe bounded blocking queue, which is a data structure that stores elements in a first-in-first-out (FIFO) order, but with the added constraint that multiple threads may be concurrently accessing it.
The problem asks us to merge two singly linked lists in a very specific way. We are given list1 and list2, with sizes n
The problem asks us to determine the longest contiguous substring of s that can be transformed into the corresponding substring of t without exceeding a given budget, maxCost.
This problem asks us to maximize the total number of vacation days over k weeks while traveling between n cities under specific flight constraints. We start in city 0 on the Monday morning of week 0.
The problem gives us an encoded string s that represents a potentially enormous decoded string. The decoding process works incrementally from left to right. When we encounter a letter, we append it directly to the decoded tape.
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.
The problem requires parsing and evaluating a mathematical expression that includes integers, variables, addition, subtraction, multiplication, and parentheses, while also applying a substitution map for certain variables.
The problem is asking us to produce aggregated statistics on transactions, grouped by month and country, from the Transactions table.
The problem asks us to maximize the total score obtained by performing n operations on an array nums of size 2 n.
The problem gives us a sorted list containing every integer from 1 to n. We repeatedly eliminate numbers in alternating directions until only one number remains.
This problem describes a two-player impartial game played on a string consisting only of '+' and '-' characters. A valid move consists of selecting any pair of consecutive "++" characters and flipping them into "--". The players alternate turns.
The problem gives us an integer array nums and asks us to return every distinct subsequence that is non-decreasing and has length at least two. A subsequence is formed by deleting zero or more elements from the array without changing the relative order of the remaining elements.
This problem asks us to remove the minimum number of columns from a list of equal length strings so that the resulting array of strings becomes lexicographically sorted.
The problem asks us to find the shortest path from the top-left corner (0, 0) to the bottom-right corner (n-1, n-1) of a given n x n binary matrix grid. A cell with a value of 0 is passable, while a cell with a value of 1 is blocked.
This problem asks us to compute the minimum number of moves a knight needs to travel from the origin [0, 0] to a target position [x, y] on an infinite chessboard.
The problem asks us to query a database table Patients and return the records of patients who have Type I Diabetes. Each
The problem provides a Customer table with three columns: id, name, and refereeid. Each row represents a customer, their unique identifier (id), their name, and optionally the id of the customer who referred them.
The problem asks us to determine whether the elements of a given array can be rearranged so that they form an arithmetic
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 asks us to find the lowest common ancestor (LCA) of two given nodes, p and q, in a binary tree, under the c
This problem asks us to process a stream of non-negative integers and continuously maintain a compact representation of all numbers seen so far. Instead of storing every individual number separately, we want to group consecutive numbers into disjoint intervals.
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.
This problem asks us to compute the minimum number of days required to eat exactly n oranges, given three possible actions that can be performed each day. On any single day, we may choose one of the following operations: 1. Eat exactly one orange. 2.
We are asked to simulate a simplified Piet interpreter on a small rectangular grid. Each cell is a pixel with a color between 0 and 9, where 0 is black and other digits are colored blocks.
This problem involves a scenario with n passengers and n seats on an airplane. Each passenger has a designated seat, but the first passenger has lost their ticket and picks a seat randomly.
The problem asks us to interpret a string expression representing a set of words generated according to a specific grammar and return all distinct words sorted in lexicographical order. The expression can contain lowercase letters, curly braces {}, and commas ,.
We are asked to determine whether a positive integer $x$ is extraordinarily nice. By the problem's definition, a number is extraordinarily nice if it has exactly the same number of even divisors as odd divisors. The input is a single integer $x$ between 1 and 1000.
The problem asks us to find the length of the longest substring that appears at least twice in a given string s. A substring is a contiguous sequence of characters inside a string. The repeated substrings may overlap with each other, which is an important detail.
The Employees table stores information about employees inside a company. Each row represents one employee and contains four columns: | Column | Meaning | | --- | --- | | employeeid | Unique identifier for the employee | | name | Employee name | | reportsto | The manager this…
This problem models processes in an operating system as a tree structure. Every process has exactly one parent, except for the root process, which has no parent and is identified by ppid[i] = 0.
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.
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 is asking us to compute the distance value between two arrays arr1 and arr2 given a threshold d. Specificall
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.
The problem gives us a singly linked list where every node contains a unique integer value. We are also given an array nums, and every value in nums is guaranteed to appear somewhere in the linked list.
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).
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 find all repeated DNA subsequences of a fixed length, specifically length 10, inside a given DNA string. The input is a string s, where each character represents a DNA nucleotide.
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.
The problem gives us a binary number represented as a string s. Our task is to determine how many operations are require
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.
The problem defines a mysterious function func(arr, l, r) that computes the bitwise AND of all elements in the subarray
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.
The problem asks us to find the maximum possible score of a path from the top-left corner (0, 0) to the bottom-right corner (m-1, n-1) of a 2D grid. Each cell in the grid contains an integer value, and the score of a path is defined as the minimum value along that path.
The problem asks us to compute a clumsy factorial for a given positive integer n. A standard factorial multiplies all integers from n down to 1, but the clumsy factorial modifies the operations: instead of multiplying all numbers, it cycles through '', '/', '+', and '-' in…
The problem asks us to determine whether a given string s can become a palindrome after removing at most k characters. A palindrome is a string that reads the same forwards and backwards, and a k-palindrome is one that can be turned into a palindrome with at most k deletions.
This problem asks us to assign students to seats such that every student occupies exactly one seat and no two students share the same seat. Each student can move left or right on a number line, and every movement by one position costs exactly one move.
The problem asks whether Vasya, who typed a string of lowercase letters, effectively managed to say "hello". The goal is not to check if the typed string is exactly "hello", but whether we can remove some letters (possibly zero) to produce the sequence h, e, l, l, o in order.
Valera has a list of subjects he knows how to solve. Every subject takes a fixed amount of working time. Students come with requests: each request has a subject, an exam deadline, and a reward. If Valera finishes the solution strictly before the exam starts, he gets paid.
The problem gives us a sorted array nums and an integer maximumBit. For every query, we must choose a number k such that: - 0 <= k < 2^maximumBit - The value of: is as large as possible.
This problem takes place on an infinite two dimensional grid. You begin at coordinate (0, 0) and want to reach a destination called target. At the same time, several ghosts also move on the grid from their own starting positions.
We are given a lowercase string that may contain accidental repeated keystrokes. Whenever two equal characters become adjacent, both characters must be deleted. After removing one pair, new adjacent equal pairs may appear, and those must also be removed.
We have a tank that wants to move from point A to point B along the straight segment connecting them. The tank moves with constant speed $v$, which we must choose as small as possible. There are $n$ enemy tanks placed on the plane.
Each player owns a multiset of artifacts. Some artifacts are basic and can be purchased directly. Some are composite and can be crafted from several basic artifacts in fixed quantities. Whenever a player buys a basic artifact, it is added to their inventory.