brain
tamnd's digital brain — notes, problems, research
42677 notes
We are given a list of n lessons, each with a start and end time, scheduled in a single room. Two lessons overlap if one starts before another ends. The goal is to find which single lesson can be removed so that the remaining lessons have no overlaps.
The problem asks us to design a data structure that can repeatedly return a random integer from the range [0, n - 1], while excluding all integers that appear in a blacklist. Every valid number must have exactly the same probability of being chosen.
We are given the positions of two chess pieces on a standard 8 × 8 board, one rook and one knight. Their starting positions are guaranteed to be safe, meaning the rook does not attack the knight and the knight does not attack the rook.
The problem asks us to compute the running sum, also called the prefix sum, of a one dimensional integer array. For ever
We are given exactly four line segments on the 2D plane. Every segment is axis-aligned, or may even degenerate into a single point.
In this problem, we are given a circular track divided into n sectors, numbered from 1 to n. A marathon runner moves around this track in increasing numerical order, and after sector n, the runner wraps back to sector 1.
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.
This problem asks us to determine whether a robot, starting at the origin (0, 0) on a 2D plane, returns to the origin after executing a sequence of moves. Each move is represented by a character in a string: 'R' moves right, 'L' moves left, 'U' moves up, and 'D' moves down.
This problem asks us to determine how many students are enrolled in each department, including departments that currently have no students. We are given two tables: Student and Department.
This problem asks us to generate random points uniformly inside a circle. The circle is defined by its radius and the coordinates of its center. Every call to randPoint() must return a point [x, y] such that the point lies either inside the circle or exactly on its boundary.
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 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 smallest contiguous substring inside string s that contains every character from string t, including duplicate occurrences. A substring must consist of consecutive characters. We are not allowed to reorder characters or skip positions.
The UserVisits table stores records of when users visited a retailer. Each row contains a userid and a visitdate. A user may appear multiple times because they can visit on many different days.
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.
The problem asks us to find the maximum number of times a string str2 can be obtained from another string str1 when both are repeated multiple times. Specifically, str1 is the string s1 repeated n1 times, and str2 is the string s2 repeated n2 times.
The problem gives an array of strings, and we must arrange them into a circular concatenation while preserving the original order of the strings. For every individual string, we are allowed to either keep it as-is or reverse it before joining it into the loop.
The problem asks us to design a data structure that determines whether a word's abbreviation is unique within a given dictionary.
Here’s a complete, detailed technical solution guide for LeetCode 2034 - Stock Price Fluctuation following your formatting and content requirements. The problem presents a stream of stock price records where each record consists of a timestamp and a price.
We have three cups arranged in a line, and a ball starts under one of them. The performer performs exactly three swaps. Each swap exchanges the positions of two cups. After all swaps finish, we must determine which cup contains the ball.
The problem describes a two-player game played on an array of stone piles. Each pile contains a positive number of stones, and the piles are arranged in a row. Alice and Bob alternate turns, with Alice always moving first.
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.
This problem gives us a special type of array called a mountain array. A mountain array strictly increases until it reaches a single peak element, then strictly decreases afterward. In other words, there exists some index i such that: - arr[0] < arr[1] < ...
We are asked to model the random movements of two friends inside a museum represented as an undirected connected graph with n rooms and m corridors. Each room has a probability of staying in place for a minute, and otherwise the person moves uniformly to a neighboring room.
We are given two lowercase strings. The first string is a word in one language, and the second string is supposed to be its translation into another language where every word is written backwards.
The problem asks us to design a reversible encoding system for a list of strings. We need two functions: - encode, which converts a list of strings into a single string - decode, which reconstructs the original list from that encoded string The important requirement is that…
This problem is asking us to identify all customers from a Customers table who have never placed an order according to the Orders table. In other words, we are looking for entries in Customers that do not have a corresponding customerId in the Orders table.
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 requires identifying all people in a group whose list of favorite companies is not a subset of any other per
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 an integer array nums and asks for the length of the shortest continuous subarray such that, if only that subarray is sorted in non-decreasing order, the entire array becomes sorted.
This problem asks us to find the minimum number of columns to delete from a set of equal-length strings so that each individual string becomes lexicographically sorted.
This problem asks us to find the maximum length of a contiguous subarray in a binary array where the number of 0s and 1s are equal. A contiguous subarray means the elements must appear consecutively in the original array. We are not allowed to rearrange elements or skip indices.
We are given a string s consisting of uppercase and lowercase Latin letters, and we are asked to analyze its substrings according to a specific property: a substring is "good" if the number of vowels it contains is at most twice the number of consonants.
This problem asks us to implement a read(buf, n) function using a restricted API called read4(buf4). The challenge is that we are not allowed to access the file directly, instead, we can only retrieve data in chunks of up to four characters at a time.
The problem provides an array of pairs, where each pair [xi, yi] indicates that xi is either an ancestor of yi or yi is an ancestor of xi in a rooted tree. The key challenge is to determine how many different rooted trees satisfy all given pairs.
The problem asks us to add two non-negative integers where each integer is given as a string instead of a numeric type. The goal is to return the resulting sum as another string. For example, if the inputs are "11" and "123", we should return "134".
The problem gives us the root node of a binary tree and asks whether the tree is "uni-valued". A binary tree is considered uni-valued if every node in the tree contains exactly the same integer value.
This problem asks us to generate every possible generalized abbreviation of a given word. A generalized abbreviation is created by replacing some characters in the string with their count, while preserving the order of the remaining characters.
This problem asks us to create a deep copy of an N-ary tree. An N-ary tree is a tree where each node can have zero or mo
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.
We have a single tram traveling along a line with n stops, starting empty at the first stop and ending empty at the last stop. At each stop, a certain number of passengers exit before any new passengers enter.
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.
This problem asks us to analyze banking transaction data and determine which users currently have a balance greater than 10000. We are given two database tables: The Users table stores account information.
This problem asks us to select a subset of words that can be constructed using a limited supply of letters, such that th
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 determine the minimum eating speed k for Koko such that she can finish all piles of bananas within a given number of hours h.
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.
The problem asks us to simulate a robot moving on an n x n grid, starting from a specified position startPos = [startrow, startcol].
Each historical event is represented by a time interval [a, b], where a is the starting year and b is the ending year. One event is considered contained inside another if it starts later and ends earlier.
The problem asks us to evaluate a Lisp-like expression represented as a string. The expression can contain integers, variables, and three special operations: let, add, and mult. An expression evaluates to a single integer value.
This problem models a social network as an undirected graph. Each person is represented by an integer ID from 0 to n - 1
The problem provides a database table named Employee that stores information about which departments employees belong to.
This problem asks us to classify nodes in a binary tree based on their role in the tree structure. The input is represen
We are given a string that represents the sequence of station flags seen while traveling from city A to city B. Peter woke up twice during the trip and wrote down two substrings he saw, in chronological order.
The problem is asking us to compute the distance value between two arrays arr1 and arr2 given a threshold d. Specificall
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 an array nums where each value represents the maximum distance you can jump forward from that position. You start at index 0, and your goal is to reach the final index using the minimum number of jumps possible.
This problem can be interpreted as a graph traversal challenge. Each room is a node in a graph labeled from 0 to n-1, and the keys inside a room represent directed edges to other nodes that can be unlocked.
We have three coins labeled A, B, and C. Every pair of coins has already been compared once using a balance scale, and each comparison tells us which coin is heavier.
We are given a rectangular plaza, the Theatre Square, with dimensions _n_ meters in length and _m_ meters in width. The city wants to pave the entire area with square flagstones of side _a_.
The problem asks whether there exists a pair of different indices (i, j) in the array such that two conditions are satisfied at the same time. The first condition is about index distance: This means the two elements must be relatively close together in the array.
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 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.
The problem asks us to partition a binary array arr into three non-empty contiguous segments such that each segment, when interpreted as a binary number (allowing leading zeros), is equal to the other two segments.
The problem asks us to find the lexicographically largest permutation that is still smaller than the given array, using exactly one swap operation.
The problem asks us to generate an n x n matrix and fill it with numbers from 1 to n^2 in spiral order. A spiral order traversal means we begin at the top-left corner and move in a clockwise pattern: 1. Move left to right across the top row 2.
The problem asks us to find the length of the longest consecutive sequence path in a binary tree, where a consecutive sequence path is defined as a path in which the values increase by exactly one from parent to child.
We are given a rectangular grid where each cell is either empty or marked with . Every cell represents a point located at the center of that cell. We need to count how many right triangles can be formed such that:
The problem gives us a numeric string s of even length and two operations that can be performed any number of times in a
Each input line describes the full path of one file inside a file system. A path looks like: The disk name is the root and is not considered a folder. Every component between the disk and the file is a folder. The last component is always a file.
The problem gives us two integer arrays, nums1 and nums2. We are allowed to draw lines between matching values in the two arrays, but with an important restriction: the lines cannot cross each other. A line can only connect nums1[i] with nums2[j] when the values are equal.
We start with four integers on the board. We also know the exact sequence of three operations that must be applied, where each operation is either addition or multiplication.
The problem asks us to determine, for each given puzzle string, how many words from a given list words are valid for that puzzle. A word is valid for a puzzle if it contains the first character of the puzzle and all characters of the word are also present in the puzzle.
The problem asks us to merge n piles of stones into a single pile under a very specific merging rule. Each pile is represented as an integer in the array stones, where stones[i] is the number of stones in the i-th pile.
The bank stores diamonds in a row of cells. After every minute, the security system checks the sums of every adjacent pair: $$a1 + a2, a2 + a3, dots, a{n-1} + an$$ If any of these sums changes compared to the previous check, the alarm triggers.
The problem asks us to find the position on a straight street that is illuminated by the largest number of street lamps, which is referred to as its brightness.
This problem asks us to construct heights for n buildings arranged in a straight line while satisfying several constraints. Each building has a non-negative integer height. Building 1 must always have height 0.
The problem gives your current position on a 2D Cartesian grid as (x, y) and a list of other points. Each point is represented as [ai, bi].
The problem is asking to find the maximum dot product of two non-empty subsequences of arrays nums1 and nums2 such that
The problem gives us a collection of stones placed on a 2D grid. Each stone occupies a unique coordinate (x, y). A stone can be removed only if there is at least one other stone that shares either the same row or the same column.
The problem gives us the root of a Binary Search Tree, abbreviated as BST, and a floating point target value. Our task is to return the integer value stored in the BST that is numerically closest to the target.
The problem asks us to build a complete Sudoku solver. We are given a partially filled 9 x 9 grid where each cell contains either a digit from '1' to '9' or the character '.', which represents an empty space.
This problem asks us to determine how many different valid ways a numeric string can be decoded into letters using the mapping: - "1" → 'A' - "2" → 'B' - ... - "26" → 'Z' The input is a string s containing only digits.
This problem asks us to find the mode(s) in a Binary Search Tree (BST). A mode is the value that appears most frequently in the tree. Since duplicates are allowed in this BST definition, a value may occur multiple times. The input is the root node of a BST.
The problem requires simulating the transformation of an array over consecutive days according to a simple local rule. Each day, every element of the array (except the first and last) is compared with its immediate neighbors.
The problem asks us to determine whether an array contains a continuous subarray whose sum is a multiple of k, while also satisfying an important constraint: the subarray must contain at least two elements.
The problem is asking us to filter and sort a list of restaurants based on multiple criteria. Each restaurant is represe
In this problem, we are given an integer array nums and a specific index k. We must find a contiguous subarray that contains index k, and among all such subarrays, maximize the following score: The minimum element inside the chosen subarray determines the limiting value of the…
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.
We have a 6 × 6 board containing the characters 0-9 and A-Z, each appearing exactly once. The target configuration is fixed: characters must appear in row-major order. The only allowed moves are cyclic shifts of complete rows or complete columns.
We are given up to 100 triangles on the plane. Each triangle represents a black spot on a white square. Triangles may overlap, intersect, or even completely cover one another. The task is to compute the perimeter of the union of all black regions.
The problem asks us to count all the negative numbers in a 2D matrix grid where each row and column is sorted in non-inc
We are given several short DNA fragments over the alphabet {A, C, G, T}. A longer DNA string is considered valid if every position of the string belongs to at least one occurrence of one of the given fragments. The fragments may overlap arbitrarily.
In this problem, we are given a circular bus route with n stops numbered from 0 to n - 1. The array distance describes the distance between neighboring stops. Specifically, distance[i] represents the distance from stop i to stop (i + 1) % n.
We have employees and directed supervisor offers between them. An offer (a, b, c) means employee a is willing to supervise employee b for cost c. Qualifications are strictly decreasing along every offer, so q[a] > q[b].
We know the current championship standings before the final race. Every racer already has some number of points, and the last race distributes additional points to the top m finishers.
This problem models communication in a social network where each user knows one or more languages. Two users can communicate directly if they share at least one common language.
The problem asks us to evaluate a boolean expression represented as a string. The expression can contain the literals 't' and 'f' for true and false, as well as three types of operators: logical NOT '!', logical AND '&', and logical OR ''. Each operator has a specific syntax: '!
We are given a string representing a hockey team name and a list of forbidden substrings. Our task is to modify the original string so that any letter that is part of a forbidden substring can be replaced with another letter of our choosing.