brain
tamnd's digital brain — notes, problems, research
42677 notes
The problem asks us to find the k-th missing number in a sorted, strictly increasing array of unique integers. Given nums and an integer k, we need to identify the number that is missing from the sequence formed by consecutive integers starting from nums[0].
In this problem, we are given a binary array called bits. The array represents a sequence of encoded characters using the following rules: - A one-bit character is represented by a single 0 - A two-bit character is represented by either 10 or 11 The array is guaranteed to end…
The problem asks us to find the length of the longest awesome substring in a given string s consisting of digits. A subs
This problem asks us to count quadruples of indices (i, j, a, b) where substrings from two given strings are equal and the difference j - a is minimized. Specifically, i and j define a substring in firstString, while a and b define a substring in secondString.
This problem asks us to generate the shortest possible string that guarantees a safe will unlock at some point while typing it. The safe password has exactly n digits, and each digit can be any value from 0 to k - 1. The safe does not validate the entire entered sequence at once.
The problem asks us to generate strings of length n using only the characters 'a', 'b', and 'c', with one important rest
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 works with three relational database tables: Movies, Users, and MovieRating. The goal is to produce a result containing exactly two rows. The first row should contain the name of the user who rated the greatest number of movies.
The problem asks us to rearrange the rows of a Genders table in a specific repeating order while maintaining internal so
We are asked to compute the minimum travel time for a car moving along a straight road from Berland to Bercouver. The road has length _l_, and at a distance _d_ from the start there is a speed sign that limits the car's instantaneous speed to _w_.
The office floor is represented as an n × m grid. Each cell is either free, written as 0, or blocked by furniture, written as 1. We want to place one rectangular table whose sides stay aligned with the grid. Every cell covered by the rectangle must be free.
We have three points on a plane: the cinema, the house, and the shop.
The problem asks us to count how many nodes exist in a complete binary tree. A complete binary tree has a very specific structure. Every level except possibly the last one is completely filled, and the nodes on the final level appear as far left as possible.
The problem gives us a string consisting only of digits, and asks us to split it into a sequence of integers that behaves like a Fibonacci sequence. A Fibonacci-like sequence follows three important rules: 1.
This problem asks us to simulate the operation of a Centennial Wheel and determine the minimum number of rotations requi
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 have an n × n grid of non-negative integers. Starting from the top-left corner, we may move only right or down until we reach the bottom-right corner. Along a chosen path, we multiply every visited value together.
The problem asks us to transform a given integer array nums into a strictly increasing array using the minimum number of operations. An operation consists of incrementing any element of the array by 1.
This problem asks us to implement a Skiplist from scratch, a probabilistic data structure that allows efficient search, insertion, and deletion operations.
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 problem asks us to determine which strings in words1 satisfy all character requirements imposed by every string in words2. A string b is considered a subset of another string a if every character in b appears in a at least as many times as it appears in b.
This problem gives us a row of seats represented by the array row, where each value is the ID of the person currently sitting in that seat. The row contains 2n people, meaning there are exactly n couples.
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.
This problem asks us to determine whether a given integer n is an exact power of four. In other words, we need to check whether there exists some integer x such that: Examples of powers of four are: The input consists of a single integer n, and the expected output is a boolean…
This problem gives us a string s and an integer k. We are allowed to repeatedly perform one operation: - Choose one of the first k characters of the string. - Remove that character from its current position. - Append it to the end of the string.
The problem gives us a valid time string in the format "HH:MM" and asks us to construct the next chronological time using only the digits already present in the original time. The important detail is that digits may be reused any number of times.
The problem asks us to determine the minimum total cost of cutting a wooden stick into pieces at specified positions. Th
The problem asks us to reverse only the English letters in a string while keeping all non-letter characters fixed in their original positions. In other words, letters move, but symbols, digits, and punctuation marks stay exactly where they started.
This problem gives us an undirected weighted graph with n nodes labeled from 1 to n. Every edge connects two nodes and has a positive weight. The graph is guaranteed to be connected, meaning there is always at least one path between any pair of nodes.
The problem asks us to compute the maximum width among all levels of a binary tree. The important detail is that the width is not simply the number of non-null nodes at a level.
The problem asks us to rearrange an array so that it follows a strict alternating pattern: - nums[0] < nums[1] - nums[1] nums[2] - nums[2] < nums[3] - and so on. This pattern is called a wiggle sequence because the values repeatedly go up and down.
This problem gives us an array of unique strings called dict, where every string has the same length. We must determine whether there exists at least one pair of strings that differ by exactly one character at the same position.
This problem asks us to determine how many students are doing homework at a specific point in time, given arrays represe
The problem presents a grid where each cell represents a street segment with a specific orientation, denoted by a number
We are given several sets of integers, each with an associated cost. We may choose any collection of these sets, including the empty collection. Let the number of chosen sets be $k$, and let the union of all chosen sets contain $u$ distinct integers.
The problem asks us to generate every unique way to express a number n as a product of integers greater than 1 and less than n. A factor combination is a list of integers whose product equals n. The order inside a combination does not matter.
The problem asks us to sort an integer array in ascending order without using any built in sorting functions. The result must contain the same elements as the input, but arranged from smallest to largest. The input is an array nums containing integers.
We are given a connected undirected graph representing a road network. Every junction is a vertex, every road is an edge, and there is at most one edge between any pair of vertices.
We are given a binary string representing Vasya's observations over several days. A character '1' means a signal was received on that day, while '0' means no signal appeared.
The problem gives us an array of non-negative integers and a starting index. From any position i, we are allowed to jump
In this problem, we are given two strings, jewels and stones. The string jewels represents all stone types that are considered jewels. Each character is a unique jewel type. For example, if jewels = "aA", then both lowercase 'a' and uppercase 'A' are jewel types.
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 perform an inorder traversal on a binary tree and return the values of the visited nodes in the correct order. A binary tree is a hierarchical data structure where each node can have at most two children, a left child and a right child.
The problem gives us an array of strings where every string has exactly the same length. If we place all strings vertically, character by character, the strings form a rectangular grid.
The problem requires designing a data structure that can efficiently maintain and retrieve the first unique integer in a
The problem asks us to find the substring of a given string s that is lexicographically largest among all possible substrings. A substring is any contiguous portion of the string.
The problem gives us an array called colors, where each position contains one of three possible values: 1, 2, or 3. Each value represents a color assigned to that index. We are also given a list of queries.
The problem asks us to remove a given interval toBeRemoved from a list of non-overlapping, sorted intervals intervals. E
The problem gives us a source string s and a list of candidate words called dictionary. We must determine which dictionary word can be formed by deleting characters from s without changing the relative order of the remaining characters.
The problem describes a path traced on a two-dimensional grid. We begin at the origin (0, 0) and move according to the values in the distance array.
We are given a filesystem path as a string. In this operating system, multiple consecutive '/' characters are treated exactly the same as a single '/'. That means paths like ///home//user///docs and /home/user/docs refer to the same location.
The problem asks us to design a logging system that controls how frequently identical messages can be printed. Each message is associated with a timestamp, and the same message is only allowed to be printed once every 10 seconds.
The problem gives us a single word consisting of uppercase and lowercase Latin letters. This word may have been typed with the Caps Lock key unintentionally engaged. We are asked to correct such accidental capitalization.
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 gives us an integer num, and we are allowed to perform a digit replacement operation twice, independently. I
The problem asks us to identify transactions that are potentially invalid based on two rules. First, any transaction with an amount greater than $1000 is invalid.
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 whether two strings, word1 and word2, are "close" according to two allowed operations. Operation 1 allows swapping any two existing characters in the string, which means the relative order of characters is flexible.
We have a circular route with n post offices, each with a gas station. Each station i has a[i] liters of gasoline available, and the distance from station i to i+1 is b[i] kilometers, wrapping around at the end.
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.
We have a rectangular grid of trees. A fire starts simultaneously from several cells, and every minute it spreads to neighboring cells that share a side. The task is to find any cell whose burning time is as large as possible, meaning it catches fire later than every other tree.
The problem gives us an array of distinct integers called nums, and asks us to generate every possible permutation of those numbers. A permutation is an arrangement of elements in a specific order.
The problem gives us a two-dimensional grid of integers called matrix. Each position in the grid contains a value, and we are asked to find the length of the longest strictly increasing path.
The Task Scheduler problem asks us to determine the minimum number of CPU intervals required to complete a list of tasks with a cooling constraint. Each task is represented by an uppercase letter A-Z. The CPU can execute one task per interval or remain idle.
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.
This problem asks us to compute several descriptive statistics-minimum, maximum, mean, median, and mode-from a very large sample of integers ranging from 0 to 255.
The problem asks us to construct a permutation of the integers from 1 to n such that the array satisfies a special condition.
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.
The problem requires calculating sums of specific subsets of an integer array nums based on queries. Each query [xi, yi] specifies a starting index xi and a step yi. The sum for this query includes all elements nums[j] such that j starts at xi and increases in steps of yi (i.e.
This problem asks us to design a reusable data structure that can efficiently answer repeated shortest-distance queries between words in a fixed list of strings. We are given an array of words, wordsDict, during initialization.
The problem asks us to find the length of the longest contiguous substring in a string s that contains at most two distinct characters. A substring is a continuous sequence of characters inside the original string.
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.
This problem asks us to generate monthly statistics for the year 2020 using information from three database tables: Driv
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…
The problem asks us to compute the complement of a positive integer by flipping every bit in its binary representation. A binary complement means changing every 1 bit into 0, and every 0 bit into 1. For example, the integer 5 is represented in binary as 101.
The problem asks us to design a data structure that can efficiently answer multiple rectangular sum queries on a fixed 2D matrix.
The problem requires us to implement a multithreaded class ZeroEvenOdd that coordinates three separate threads to print numbers in a specific sequence. Thread A prints 0s, Thread B prints even numbers, and Thread C prints odd numbers.
This problem gives us a database table named Point that contains integer coordinates on the X-axis. Each row represents one point, and the column x is unique because it is the primary key. The task is to compute the smallest absolute distance between any two points in the table.
We are asked to maintain a dynamic set of positive integers under three operations: adding a number, deleting a number, and computing the sum of medians of every consecutive group of five elements after sorting the set.
This problem asks us to split a string into the largest possible number of substrings such that every substring is uniqu
The problem asks us to group strings based on a special equivalence property. Specifically, two strings are special-equivalent if you can swap characters at even indices among themselves and characters at odd indices among themselves any number of times to make the two strings…
The problem gives us an array called salary, where each element represents the salary of an employee. Every salary value
The problem asks us to count all possible non-empty sequences that can be formed from a set of letter tiles, where each tile has a single uppercase letter. The input is a string tiles representing the letters available on the tiles.
We have a large circle, the plate, with radius R. Inside it there is another circle, the Golden Honduras, with radius r. The Honduras circle is tangent to the plate from the inside, so its center is exactly R - r units away from the plate center.
This guide is quite large and highly detailed under your required structure, especially with full worked examples, both
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 asks us to maximize the number of “happy” customer groups by choosing the best possible ordering of the groups. The donut shop produces donuts in batches of exactly batchSize. A fresh batch starts only when the previous batch has been completely consumed.
Edit This problem gives us a permutation array arr containing integers from 1 to n, where n is the size of the binary st
The problem provides a database table named Sessions with two columns: | Column | Meaning | | --- | --- | | sessionid |
In this problem, we are given an integer n, and we must determine whether it is an Armstrong number. An Armstrong number is defined as follows: - Let k be the number of digits in n. - Take every digit in the number. - Raise each digit to the power k.
The problem gives us a string containing digits and the '' character. This string encodes lowercase English letters usin
We have bus stops placed on a line from 0 to n. Gerald starts at stop 0 and wants to reach stop n. Each bus is described by an interval [s, t]. Gerald may board that bus at any stop from s through t - 1, but once he rides it, he must stay on until stop t.
This problem asks us to reorder a singly linked list so that all nodes located at odd indices appear first, followed by all nodes located at even indices. The important detail is that the grouping is based on the node's position in the list, not the node's value.
The problem asks us to extract all consecutive records from a Stadium table where the people count is at least 100, and the consecutive streak has a length of three or more. Each row has a unique id and a corresponding visitdate.
The problem asks us to find the minimum Hamming distance between two arrays, source and target, after performing any number of swaps on source at positions allowed by allowedSwaps. The Hamming distance is defined as the number of indices i for which source[i] != target[i].
In this problem, we are given a binary array called seats. Each position in the array represents a seat in a row: - 1 means the seat is occupied. - 0 means the seat is empty.
This problem asks us to compute the post tax salary for every employee in the Salaries table. However, the tax rate is n
The problem asks us to find the k-th smallest fraction that can be formed by dividing one element of a sorted array arr by another element later in the array. The array arr is strictly increasing, starts with 1, and all elements after the first are prime numbers.
This problem asks us to determine the minimum ship capacity required to transport all packages within a fixed number of days. We are given an array called weights, where weights[i] represents the weight of the i-th package on a conveyor belt.
The problem gives us two arrays of strings, word1 and word2. Each array represents a single larger string formed by conc