brain
tamnd's digital brain — notes, problems, research
42695 notes
The problem asks us to count how many contiguous subarrays contain exactly k odd numbers. We are given an integer array
We are given two integers, l and r. For every number n inside this interval, we build another number called its reflection. The reflection is created digit by digit. Every decimal digit d becomes 9 - d.
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.
We are given several unsigned integer datatypes, each defined by its bit length. A datatype with a bits can store every integer from 0 up to 2^a - 1. We want to know whether there exists some integer x and two datatypes with sizes a[i] < a[j] such that: 1.
The problem asks us to coordinate four separate threads so they collectively print the correct Fizz Buzz sequence in order from 1 to n. Unlike the classic single threaded Fizz Buzz problem, this version introduces concurrency.
The problem models the Android lock screen as a 3 x 3 grid containing digits 1 through 9. A valid unlock pattern is a sequence of distinct dots that follows a special movement rule. The first rule is straightforward: each dot can only be used once in a pattern.
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".
The problem asks us to find a subsequence of a given integer array nums such that the sum of that subsequence is as close as possible to a given integer goal.
The problem asks us to find the smallest positive integer divisor for a given array nums such that when each element of
The problem asks us to design a circular double-ended queue, also called a deque. A deque is a data structure that allows insertion and deletion from both the front and the rear.
The problem asks us to balance a string composed of exactly four types of characters: 'Q', 'W', 'E', and 'R'. A string is balanced when each character occurs exactly n / 4 times, where n is the length of the string.
The problem gives us two binary search trees, root1 and root2, along with an integer target. We must determine whether there exists one node from the first tree and one node from the second tree such that their values add up exactly to target.
The problem gives us two arrays, nums1 and nums2, both of the same length. At every index i, we are allowed to either keep the values as they are, or swap nums1[i] with nums2[i]. Our goal is to make both arrays strictly increasing while performing the minimum number of swaps.
This problem asks us to determine whether a given positive integer num is a perfect number. A perfect number is defined as a number whose sum of positive divisors, excluding the number itself, equals the number.
This problem asks us to find the lowest common ancestor, abbreviated as LCA, of all the deepest leaf nodes in a binary tree. A leaf node is any node with no children. The depth of the root is 0, and every level downward increases the depth by 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 find the length of the longest contiguous subarray in an integer array nums such that the absolut
This problem asks us to find the largest possible island size in a binary grid after changing at most one 0 into 1.
Unusual activity has been detected from your device. Try again later. (36c3723c-3fa3-4b63-a514-20d2635d5e47)
We have two arrays representing the order of students in a line. Array a is the desired arrangement, and array b is the current arrangement. In one operation we may swap two neighboring students. We must output any sequence of adjacent swaps that transforms b into a.
This problem gives us two arrays, nums1 and nums2, where both arrays are already sorted in non-decreasing order. We are also given two integers, m and n, which tell us how many valid elements exist in each array. The important detail is that nums1 has extra space at the end.
This problem gives us the root of a binary tree, a specific target node inside that tree, and an integer k. Our task is to return all node values whose distance from the target node is exactly k. The important detail is the definition of distance.
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.
This problem asks us to maximize the total profit earned by assigning jobs to workers, under a specific rule: each worker can only perform jobs whose difficulty is less than or equal to their ability.
This problem asks us to build the lexicographically largest possible string by repeatedly choosing characters from the front of two given strings.
The problem asks us to implement a stack data structure while using only queue operations internally. A stack follows the Last-In-First-Out, or LIFO, principle. This means the most recently inserted element must be removed first.
Each lawn contains a distinct positive integer. Two lawns are considered connected if their numbers can appear together in some primitive Pythagorean triple.
In this problem, we are given two arrays, quality and wage, where each index represents a worker. The value quality[i] describes how much work or contribution the i-th worker provides, while wage[i] describes the minimum amount that worker is willing to accept.
We are simulating a simplified version of the party game "Boom" with multiple teams and cards. There are n teams, each with two players. Each player has an ability to explain words (a) and an ability to understand words (b).
We start with a strictly increasing array of problem complexities. The imbalance of the set is defined as the largest difference between two neighboring elements after sorting.
The problem gives us two lists of closed intervals. Each interval is represented as [start, end], meaning every value from start through end, inclusive, belongs to that interval.
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 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 have a grid containing chips. Every chip stores one direction, left, right, up, or down. When we start a move from some chip, the process behaves like this: The current chip looks in the direction of its arrow.
The problem asks us to compute a simple mathematical transformation on the digits of an integer. Given an integer n, we
The problem gives us two integer arrays, nums1 and nums2, and asks us to return their intersection. The intersection consists of all values that appear in both arrays. However, the result must contain only unique elements, even if a number appears many times in either array.
The problem gives us an undirected and connected graph with n nodes labeled from 0 to n - 1. The graph is represented as an adjacency list, where graph[i] contains all nodes directly connected to node i.
This problem asks us to determine how many structurally different Binary Search Trees, or BSTs, can be formed using the integers from 1 to n. A Binary Search Tree has an important property: - Every value in the left subtree is smaller than the root.
The problem is asking us to design a custom stack-like data structure that supports two operations: pushing values onto the stack and popping the most frequent element.
We are given three musical notes, and the task is to classify the chord they form as either major, minor, or "strange". Notes are represented in the twelve-tone chromatic scale: C, C, D, D, E, F, F, G, G, A, B, H, and the scale is cyclic, so after H comes C again.
We have exactly five people. Some pairs of people know each other, and the input lists all such acquaintance relations. The task is to determine whether there exists either: 1. Three people where every pair knows each other. 2. Three people where no pair knows each other.
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 gives us a string s that represents a license key. The string contains uppercase letters, lowercase letters, digits, and dashes. The existing dashes are only separators and do not necessarily represent the correct final grouping.
The problem is asking us to find two disjoint palindromic subsequences from a given string s such that the product of their lengths is maximized. A subsequence is derived by deleting zero or more characters from the original string while keeping the relative order intact.
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.
This problem asks us to modify the structure of an N-ary tree by moving one subtree under another node. Every node contains a unique value, and each node may have any number of children.
In this problem, we are given a list of log strings. Each log contains an identifier followed by one or more words separated by spaces. The first token is always the identifier, and everything after it represents the content of the log.
This problem requires designing a simulation for an exam room seating arrangement. We have n seats in a single row, labeled from 0 to n - 1. Students enter one by one, and each student chooses a seat such that the distance to the closest occupied seat is maximized.
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.
This problem gives us an array called heights, where each element represents the height of a building. The buildings are arranged in a straight line from left to right, and the ocean is located to the right side of the last building.
We are asked to construct a fully connected graph of _N_ tourist attractions, where each road has a distinct positive integer cost not exceeding 1000.
The problem gives us a two dimensional matrix of integers with m rows and n columns. We must modify the matrix in place so that whenever a cell contains 0, every element in that cell's entire row and entire column also becomes 0.
We have two armies, each containing n soldiers. The value of n is always even. The game lasts exactly three turns: 1. Valera attacks Arcady. 2. Arcady attacks Valera. 3. Valera attacks Arcady again.
The problem gives us an n x n binary matrix called grid. Each cell contains either 1 or 0. A value of 1 represents land, and a value of 0 represents water. Land cells that are connected vertically or horizontally form an island.
This problem asks us to interpret a Goal Parser command string. The string command consists of the characters "G", "()",
This problem asks us to determine the distance between two nodes in a binary tree, given their values p and q. The distance is defined as the number of edges in the shortest path connecting the two nodes.
The problem gives us an array called boxes, where each integer represents the color of a box. We may repeatedly remove groups of adjacent boxes that share the same color. If we remove a group containing k boxes, we earn k k points.
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.
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…
The problem asks us to design a class that processes stock prices one day at a time and, for every new price, returns the stock span for that day.
Each tooth belongs to exactly one row. When Valerie eats one crucian using a row, every tooth in that row loses one unit of viability. A row becomes unusable as soon as at least one tooth inside it would drop below zero.
The problem requires us to transform an array nums of even length n into a complementary array. An array is complementar
The problem asks us to repeatedly transform a number by summing its digits until only a single digit remains. The final single digit should then be returned. For example, if the input is 38, we first compute 3 + 8 = 11.
The problem gives us an array nums containing non-negative integers. We need to determine whether there exists an intege
This problem asks us to count the number of triples (i, j, k) from an integer array nums such that the bitwise AND of the three numbers at these indices equals zero. In other words, we want all combinations where nums[i] & nums[j] & nums[k] == 0.
The problem gives us two integer arrays, arr1 and arr2, both having the same length. We must compute the maximum possible value of the following expression across every pair of indices (i, j): The task is not asking for the indices themselves, only the largest achievable value.
The problem asks us to design an in-memory file system that simulates basic file system operations without interacting with the real filesystem.
This problem asks us to write a SQL function that returns the nth highest distinct salary from the Employee table. The table contains two columns: Column Meaning --- --- id Unique employee identifier salary Employee salary The key detail is that the salary must be distinct.
The problem describes a sequence of n bulbs, all initially turned off. We perform n rounds of operations on these bulbs. In the first round, every bulb is turned on. In the second round, every second bulb is toggled, meaning on bulbs become off and off bulbs become on.
The problem gives us a 2 x n grid where each cell contains some number of points. Two robots move across this grid one after another. Both robots start at the top-left corner (0, 0) and must reach the bottom-right corner (1, n - 1). The movement rules are very restrictive.
This problem asks us to multiply two matrices, but with an important detail: both matrices are sparse. A sparse matrix is a matrix where most entries are zero. The goal is to take advantage of this property so that we avoid unnecessary computation involving zero values.
The problem is asking us to find the next greater element for each element in nums1 within another array nums2. Formally, for each element in nums1, we need to locate its position in nums2 and then find the first element to its right in nums2 that is greater than itself.
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 us a database table named Cinema with two columns: Column Meaning --- --- seatid Unique identifier for a seat free Whether the seat is available, where 1 means free and 0 means occupied We need to find all seats that are part of at least one consecutive…
The problem is asking whether a given string s can be rearranged to form exactly k non-empty palindrome strings using al
The problem describes a voting based ranking system where every voter ranks all teams from best to worst. Each vote is r
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 given two integers, k and l. The task is to determine whether l can be written as an exact power of k. In other words, we need to check whether there exists a non-negative integer n such that: $l = k^n$ If such an n exists, we print "YES" and also print the importance…
In this problem, we are given n friends, where n is always even. Every friend ranks all other friends in order of preference. The earlier someone appears in a person's preference list, the more that person is preferred. We are also given a final pairing arrangement.
The problem gives us two arrays, aliceSizes and bobSizes, representing the candy boxes owned by Alice and Bob. Each element in the arrays is the number of candies in a particular box.
We start with a set of distinct lattice points on the plane. We may add more points, and the final set must satisfy a geometric condition for every pair of points. Take any two points.
This problem is asking us to determine the maximum number of contiguous chunks into which we can split an array such that sorting each chunk individually and concatenating them results in a fully sorted array.
Nick wants to list all numbers of a given length n in base b, where digits range from 0 to b-1, but numbers cannot start with 0. Each page in his notepad holds exactly c numbers. We are asked to compute how many numbers appear on the last page he fills.
This problem asks us to compute the overall acceptance rate of friend requests in a social network system. Two database tables are provided. The first table, FriendRequest, stores all friend requests that users sent to each other.
The problem gives us an array of positive integers called sticks, where each value represents the length of a stick. We are allowed to repeatedly connect any two sticks together.
We have several rectangles on the plane. Each rectangle represents a photo hanging on a wall. The rectangles may overlap, may share edges, may coincide completely, and may also be rotated arbitrarily.
The problem gives us a binary array called flowerbed, where: - 0 represents an empty plot - 1 represents a plot that already contains a flower We are also given an integer n, which represents how many new flowers we want to plant.
The problem gives us two binary search trees, root1 and root2. A binary search tree, commonly abbreviated as BST, has the important property that for every node: - All values in the left subtree are smaller than the node's value - All values in the right subtree are larger…
The problem asks us to design a class called SubrectangleQueries that operates on a two dimensional integer matrix, refe
We are given a string representing the genome of an organism, where each character is one of the first K capital letters. Adjacent genes contribute to the total “risk of disease” according to a given K × K matrix of non-negative integers.
The problem requires designing a data structure that can efficiently maintain and retrieve the first unique integer in a
The problem gives us the root of a Binary Search Tree, abbreviated as BST, and asks us to transform it into a Greater Sum Tree. In a Binary Search Tree, every node follows an important ordering rule: - All values in the left subtree are smaller than the current node.
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.
The problem asks us to count the number of substrings in a string s such that every unique character in the substring occurs exactly count times. A substring is a contiguous segment of the string, so we are only considering consecutive characters.
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.
This problem asks us to traverse a binary tree and identify every node that is considered "lonely". A node is lonely if
Here is a complete, detailed technical solution guide for LeetCode 1660 - Correct a Binary Tree, formatted exactly as re
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…
The problem asks us to design an authentication system that manages tokens with expiration times. Each token is valid for a fixed timeToLive seconds starting from the moment it is generated or renewed.
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.