brain

tamnd's digital brain — notes, problems, research

43815 notes

LeetCode 1195 - Fizz Buzz Multithreaded

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.

leetcodemediumconcurrency
LeetCode 165 - Compare Version Numbers

This problem asks us to compare two software version numbers represented as strings. Each version consists of one or more numeric revisions separated by dots (.). For example, "1.2.10" contains three revisions: 1, 2, and 10.

leetcodemediumtwo-pointersstring
LeetCode 222 - Count Complete Tree Nodes

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.

leetcodeeasybinary-searchbit-manipulationtreebinary-tree
LeetCode 236 - Lowest Common Ancestor of a Binary Tree

The problem asks us to find the Lowest Common Ancestor, usually abbreviated as LCA, of two nodes in a binary tree. A binary tree consists of nodes where each node may have a left child and a right child.

leetcodemediumtreedepth-first-searchbinary-tree
LeetCode 406 - Queue Reconstruction by Height

This problem gives us a list of people where each person is represented as a pair [h, k]. The value h represents the person's height. The value k represents how many people standing in front of this person must have a height greater than or equal to h.

leetcodemediumarraybinary-indexed-treesegment-treesorting
LeetCode 1571 - Warehouse Manager

This problem asks us to calculate the total storage volume occupied by products inside each warehouse. We are given two database tables: The Warehouse table tells us which products are stored in each warehouse and how many units of each product exist there.

leetcodeeasydatabase
LeetCode 513 - Find Bottom Left Tree Value

The problem asks us to find the leftmost value in the last row of a binary tree. A binary tree is a hierarchical data structure where each node has at most two children: a left child and a right child.

leetcodemediumtreedepth-first-searchbreadth-first-searchbinary-tree
LeetCode 918 - Maximum Sum Circular Subarray

The problem asks for the maximum sum of a subarray in a circular array. In simpler terms, we are given a list of integers nums where the end of the list wraps around to the start.

leetcodemediumarraydivide-and-conquerdynamic-programmingqueuemonotonic-queue
CF 90A - Cableway

The cableway sends one cablecar every minute, and the colors repeat in a fixed cycle: red - green - blue - red - ... Each cablecar can carry at most two students, and every ride takes exactly 30 minutes to reach the top. We are given three groups of students.

codeforcescompetitive-programminggreedymath
LeetCode 1668 - Maximum Repeating Substring

This problem asks us to determine how many times a given string word can be repeated consecutively while still appearing

leetcodeeasystringdynamic-programmingstring-matching
LeetCode 950 - Reveal Cards In Increasing Order

The problem gives us a deck of unique integer cards and asks us to arrange the deck so that a very specific reveal process produces the cards in increasing order. The reveal process works like this: 1. Reveal the top card and remove it from the deck. 2.

leetcodemediumarrayqueuesortingsimulation
CF 74B - Train

The train has n wagons arranged in a line. The controller moves deterministically: every minute he walks one wagon in his current direction, and when he reaches either end he reverses direction. His path is completely fixed once we know the initial wagon and direction.

codeforcescompetitive-programmingdpgamesgreedy
LeetCode 795 - Number of Subarrays with Bounded Maximum

The problem asks us to count how many contiguous, non-empty subarrays have a maximum element that lies within the inclusive range [left, right]. A subarray is a continuous segment of the original array. For every possible subarray, we look at its maximum value.

leetcodemediumarraytwo-pointers
CF 122B - Lucky Substring

The problem asks us to find the "luckiest" substring of a given string of digits. By luckiest, we mean a substring that consists only of the digits 4 and 7, occurs in the string as many times as possible, and is the lexicographically smallest if there are ties.

codeforcescompetitive-programmingbrute-forceimplementation
LeetCode 2028 - Find Missing Observations

The problem gives us the results of some dice rolls and asks us to reconstruct the missing ones. We have a total of n + m rolls of a standard 6-sided die.

leetcodemediumarraymathsimulation
LeetCode 525 - Contiguous Array

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.

leetcodemediumarrayhash-tableprefix-sum
LeetCode 729 - My Calendar I

The problem asks us to design a calendar system that supports booking events without allowing overlapping intervals. Each event is represented as a half-open interval [startTime, endTime). This means the event includes startTime, but does not include endTime.

leetcodemediumarraybinary-searchdesignsegment-treeordered-set
LeetCode 1046 - Last Stone Weight

This problem asks us to repeatedly simulate a process involving stones with different weights. At every turn, we must select the two heaviest stones, smash them together, and update the collection based on the result.

leetcodeeasyarrayheap-(priority-queue)
LeetCode 1435 - Create a Session Bar Chart

The problem provides a database table named Sessions with two columns: | Column | Meaning | | --- | --- | | sessionid |

leetcodeeasydatabase
LeetCode 1218 - Longest Arithmetic Subsequence of Given Difference

The problem asks for the length of the longest arithmetic subsequence in a given array arr such that the difference between consecutive elements equals a specified integer difference. A subsequence can skip elements but must preserve the original order.

leetcodemediumarrayhash-tabledynamic-programming
CF 1941G - Rudolf and Subway

The problem describes a subway system as an undirected graph where each vertex is a station and each edge represents a direct connection between two stations. Every edge is labeled with a color representing the subway line it belongs to.

codeforcescompetitive-programmingconstructive-algorithmsdfs-and-similargraphsshortest-paths
CF 74A - Room Leader

We are given the scoreboard data for every participant in a Codeforces room. Each contestant has a handle, a number of successful hacks, a number of unsuccessful hacks, and the points earned from problems A through E.

codeforcescompetitive-programmingimplementation
CF 42E - Baldman and the military

We are asked to prepare a set of additional undirected edges, called wormholes, on top of an unknown tunnel system.

codeforcescompetitive-programmingdfs-and-similargraphstrees
CF 119E - Alternative Reality

We are given a three-dimensional space containing $n$ fixed points, representing the centers of energy spheres. There are $m$ levels, and in each level the player starts at a plane passing through the origin.

codeforcescompetitive-programminggeometry
LeetCode 458 - Poor Pigs

The problem gives us a set of buckets where exactly one bucket contains poison. We need to determine which bucket is poisonous using the fewest number of pigs possible, under a strict time limit. Each pig can participate in multiple rounds of testing.

leetcodehardmathdynamic-programmingcombinatorics
LeetCode 306 - Additive Number

The problem asks us to determine whether a given string of digits can be partitioned into a valid additive sequence. An additive sequence is a sequence of numbers where: - There are at least three numbers.

leetcodemediumstringbacktracking
LeetCode 271 - Encode and Decode Strings

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…

leetcodemediumarraystringdesign
LeetCode 826 - Most Profit Assigning Work

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.

leetcodemediumarraytwo-pointersbinary-searchgreedysorting
LeetCode 1199 - Minimum Time to Build Blocks

The problem requires determining the minimum amount of time to build all blocks using workers that can either build blocks or split into more workers. You are given a list blocks where blocks[i] indicates the time it takes for a worker to complete the i-th block.

leetcodehardarraymathgreedyheap-(priority-queue)
CF 33D - Knights

We are given a map of Berland with several control points and circular fences. Each knight occupies a control point. Fences separate the kingdom into regions, and a knight must cross fences to move between control points.

codeforcescompetitive-programminggeometrygraphsshortest-pathssortings
LeetCode 610 - Triangle Judgement

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.

leetcodeeasydatabase
CF 109A - Lucky Sum of Digits

We need to construct the smallest possible lucky number whose digits add up to a given value n. A lucky number may contain only digits 4 and 7. For example, 447 is valid because every digit is either 4 or 7, while 45 is invalid because digit 5 appears.

codeforcescompetitive-programmingbrute-forceimplementation
LeetCode 55 - Jump Game

The problem gives us an integer array nums, where each value represents the maximum distance we are allowed to jump forward from that position. You always start at index 0.

leetcodemediumarraydynamic-programminggreedy
LeetCode 878 - Nth Magical Number

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…

leetcodehardmathbinary-search
LeetCode 1016 - Binary String With Substrings Representing 1 To N

The problem asks us to determine whether a given binary string s contains all binary representations of integers from 1 to n as substrings.

leetcodemediumhash-tablestringbit-manipulationsliding-window
LeetCode 1417 - Reformat The String

The problem gives us an alphanumeric string s that contains only lowercase English letters and digits. Our task is to re

leetcodeeasystring
LeetCode 1533 - Find the Index of the Large Integer

The problem presents an array arr where all elements are equal except for one element that is strictly larger than the o

leetcodemediumarraybinary-searchinteractive
LeetCode 1303 - Find the Team Size

This problem provides a database table named Employee, where every row represents a single employee and the team they belong to.

leetcodeeasydatabase
LeetCode 445 - Add Two Numbers II

The problem gives us two non-empty singly linked lists where each node stores a single digit of a non-negative integer. Unlike the classic "Add Two Numbers" problem, the digits are stored in forward order, meaning the most significant digit appears first.

leetcodemediumlinked-listmathstack
CF 119D - String Transformation

We are given two strings, a and b, of equal length up to one million characters. The task is to find indices i and j in a such that if we perform a specific transformation, we get b.

codeforcescompetitive-programminghashingstrings
LeetCode 127 - Word Ladder

This problem asks us to determine the length of the shortest transformation sequence between two words, beginWord and endWord, under a strict transformation rule.

leetcodehardhash-tablestringbreadth-first-search
CF 64D - Presents

We are given three positive integers representing the prices of three presents. There are three sisters, ranked by age: eldest, middle, and youngest.

codeforcescompetitive-programming*specialgreedy
LeetCode 1151 - Minimum Swaps to Group All 1's Together

This problem asks us to determine the minimum number of swaps needed to group all 1s in a binary array into one contiguous block. The block can appear anywhere in the array, as long as all 1s end up adjacent.

leetcodemediumarraysliding-window
CF 54B - Cutting Jigsaw Puzzle

We are given a rectangular picture represented as an A × B grid of letters. The task is to determine how many ways we can cut this picture into smaller rectangular pieces such that each piece is unique up to rotations, and to identify the smallest possible piece size among…

codeforcescompetitive-programminghashingimplementation
CF 130G - CAPS LOCK ON

We are given a single string containing printable ASCII characters. Some characters may be lowercase English letters, some may already be uppercase letters, and others may be symbols or digits.

codeforcescompetitive-programming*special
LeetCode 1164 - Product Price at a Given Date

The problem provides a database table named Products, where each row represents a price update for a product on a specific date.

leetcodemediumdatabase
LeetCode 728 - Self Dividing Numbers

The problem asks us to find all numbers within a given inclusive range [left, right] that satisfy the definition of a self-dividing number. A self-dividing number has two important properties: 1. Every digit inside the number must divide the number evenly. 2.

leetcodeeasymath
CF 63C - Bulls and Cows

We are playing the classic Bulls and Cows game with four-digit numbers whose digits are all distinct. Leading zeroes are allowed, so 0123 is valid, but repeated digits such as 0012 or 1223 are not. Each previous guess comes with two values.

codeforcescompetitive-programmingbrute-forceimplementation
LeetCode 1170 - Compare Strings by Frequency of the Smallest Character

The problem defines a function f(s) for a non-empty string s. This function returns the frequency of the lexicographically smallest character in the string.

leetcodemediumarrayhash-tablestringbinary-searchsorting
LeetCode 1080 - Insufficient Nodes in Root to Leaf Paths

This problem asks us to prune a binary tree by removing insufficient nodes. A node is insufficient if every root-to-leaf path passing through it has a sum strictly less than the given limit. The input is the root of a binary tree and an integer limit.

leetcodemediumtreedepth-first-searchbinary-tree
LeetCode 301 - Remove Invalid Parentheses

The problem asks us to remove the minimum number of invalid parentheses from a string so that the remaining string becomes valid. The input string may contain lowercase English letters in addition to parentheses.

leetcodehardstringbacktrackingbreadth-first-search
LeetCode 228 - Summary Ranges

The problem gives us a sorted array of unique integers and asks us to summarize consecutive values into compact range strings. A range represents a continuous sequence of integers.

leetcodeeasyarray
LeetCode 1147 - Longest Chunked Palindrome Decomposition

The problem asks us to decompose a given string text into the largest possible number of contiguous substrings such that the sequence of substrings forms a palindromic pattern.

leetcodehardtwo-pointersstringdynamic-programminggreedyrolling-hashhash-function
LeetCode 1356 - Sort Integers by The Number of 1 Bits

The problem asks us to sort an integer array arr based on the number of 1 bits in the binary representation of each elem

leetcodeeasyarraybit-manipulationsortingcounting
LeetCode 1026 - Maximum Difference Between Node and Ancestor

This problem asks us to find the largest absolute difference between the values of two nodes in a binary tree, under one important condition: one node must be an ancestor of the other.

leetcodemediumtreedepth-first-searchbinary-tree
LeetCode 1634 - Add Two Polynomials Represented as Linked Lists

This problem asks us to add two polynomials represented as singly linked lists. Each node in the linked list represents a single term of a polynomial, with a coefficient and a power.

leetcodemediumlinked-listmathtwo-pointers
LeetCode 1023 - Camelcase Matching

The problem gives us a list of query strings and a target camel case pattern. For each query, we must determine whether the query can be formed by inserting only lowercase English letters into the pattern.

leetcodemediumarraytwo-pointersstringtriestring-matching
LeetCode 1753 - Maximum Score From Removing Stones

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.

leetcodemediummathgreedyheap-(priority-queue)
LeetCode 407 - Trapping Rain Water II

This problem is the two dimensional version of the classic "Trapping Rain Water" problem. Instead of a one dimensional array of heights, we are given an m x n grid where each cell represents the elevation of a block in a terrain.

leetcodehardarraybreadth-first-searchheap-(priority-queue)matrix
LeetCode 1509 - Minimum Difference Between Largest and Smallest Value in Three Moves

The problem gives us an integer array nums, and we are allowed to perform at most three moves. In each move, we may sele

leetcodemediumarraygreedysorting
CF 55C - Pie or die

We have an grid. Some cells contain pies, and several pies may share the same cell.

codeforcescompetitive-programminggames
CF 111C - Petya and Spiders

We are given a board of size n by m, with a spider on every cell. Each spider can move to any adjacent cell or stay in place, as long as it stays inside the board. All spiders move simultaneously, and multiple spiders can occupy the same cell after moving.

codeforcescompetitive-programmingbitmasksdpdsu
LeetCode 309 - Best Time to Buy and Sell Stock with Cooldown

This problem asks us to maximize profit from stock trading under a special restriction called a cooldown period. We are given an integer array prices, where prices[i] represents the stock price on day i. On any day, we may choose to buy one share, sell one share, or do nothing.

leetcodemediumarraydynamic-programming
LeetCode 212 - Word Search II

LeetCode 212, LeetCode Word Search II, asks us to find every word from a given dictionary that can be formed inside a 2D character grid. Each word must be built by moving one cell at a time horizontally or vertically.

leetcodehardarraystringbacktrackingtriematrix
LeetCode 772 - Basic Calculator III

This problem asks us to evaluate a mathematical expression represented as a string. The expression may contain: - Non-negative integers - Addition (+) - Subtraction (-) - Multiplication () - Division (/) - Parentheses (( and )) The goal is to compute the final integer result…

leetcodehardmathstringstackrecursion
LeetCode 178 - Rank Scores

The problem gives us a database table named Scores that contains two columns: id and score. Each row represents the score achieved in a game.

leetcodemediumdatabase
LeetCode 1398 - Customers Who Bought Products A and B but Not C

The problem asks us to identify customers who meet a very specific purchasing pattern. We are given two tables: Customer

leetcodemediumdatabase
LeetCode 93 - Restore IP Addresses

The problem asks us to take a string containing only digits and determine every possible way to insert exactly three dots so that the resulting string becomes a valid IPv4 address. A valid IP address has four numeric segments separated by dots.

leetcodemediumstringbacktracking
LeetCode 357 - Count Numbers with Unique Digits

The problem asks us to count how many integers in the range 0 <= x < 10^n contain no repeated digits. For example, when n = 2, the valid range is: This means we consider every number from 0 to 99. Among these numbers, we only count those whose digits are all unique.

leetcodemediummathdynamic-programmingbacktracking
CF 11E - Forward, march!

Jack repeats a cyclic sequence consisting of three possible actions. L means a left-foot step, R means a right-foot step, and X means standing still for one beat. The sergeant expects the infinite alternating pattern:

codeforcescompetitive-programmingbinary-searchdpgreedy
LeetCode 1277 - Count Square Submatrices with All Ones

The problem gives us a binary matrix of size m x n, where every cell contains either 0 or 1. We must count how many squa

leetcodemediumarraydynamic-programmingmatrix
LeetCode 588 - Design In-Memory File System

The problem asks us to design an in-memory file system that simulates basic file system operations without interacting with the real filesystem.

leetcodehardhash-tablestringdesigntriesorting
LeetCode 872 - Leaf-Similar Trees

This problem asks us to compare two binary trees based only on their leaf nodes. A leaf node is a node that has no left child and no right child.

leetcodeeasytreedepth-first-searchbinary-tree
LeetCode 547 - Number of Provinces

The problem is asking us to determine the number of provinces in a network of cities. Each city can be connected directly to other cities, and indirectly through chains of connections.

leetcodemediumdepth-first-searchbreadth-first-searchunion-findgraph-theory
LeetCode 711 - Number of Distinct Islands II

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.

leetcodehardarrayhash-tabledepth-first-searchbreadth-first-searchunion-findsortingmatrixhash-function
CF 121A - Lucky Sum

We need to evaluate a sum over an interval [l, r]. For every integer x in that range, we compute next(x), where next(x) means the smallest lucky number greater than or equal to x. A lucky number is a positive integer whose decimal digits are only 4 and 7.

codeforcescompetitive-programmingimplementation
LeetCode 370 - Range Addition

The problem gives us an initially zero-filled array of size length. We are also given a list of update operations, where each update has the form: This means we must add inc to every element in the inclusive range from startIdx to endIdx.

leetcodemediumarrayprefix-sum
CF 51D - Geometrical problem

We are given an integer array and must classify it into one of three categories.

codeforcescompetitive-programmingimplementation
LeetCode 1729 - Find Followers Count

The problem is asking us to determine, for each user in a social media application, how many followers they have. The input is a table called Followers with two columns: userid and followerid. Each row represents a relationship where followerid follows userid.

leetcodeeasydatabase
LeetCode 410 - Split Array Largest Sum

The problem gives an integer array nums and an integer k. We must divide the array into exactly k non-empty contiguous subarrays. Among those subarrays, each one has its own sum, and the goal is to minimize the largest subarray sum.

leetcodehardarraybinary-searchdynamic-programminggreedyprefix-sum
LeetCode 354 - Russian Doll Envelopes

The problem gives a list of envelopes, where each envelope is represented as a pair [w, h]. The value w is the width and h is the height. An envelope can fit inside another envelope only if both dimensions are strictly smaller.

leetcodehardarraybinary-searchdynamic-programmingsorting
LeetCode 1247 - Minimum Swaps to Make Strings Equal

This problem asks us to determine the minimum number of swaps needed to make two strings, s1 and s2, equal. Both strings are of the same length and consist only of the characters "x" and "y".

leetcodemediummathstringgreedy
LeetCode 1722 - Minimize Hamming Distance After Swap Operations

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].

leetcodemediumarraydepth-first-searchunion-find
LeetCode 1794 - Count Pairs of Equal Substrings With Minimum Difference

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.

leetcodemediumhash-tablestringgreedy
CF 72A - Goshtasp, Vishtasp and Eidi

The problem asks us to decide whether a positive integer $n$ can be represented as a sum of distinct integers, where each integer is either 1 or a prime number. If such a representation exists, we need to produce one that is lexicographically largest.

codeforcescompetitive-programming*specialgreedymath
LeetCode 1117 - Building H2O

This problem asks us to coordinate multiple concurrent threads so that they form water molecules correctly. A water molecule contains exactly two hydrogen atoms and one oxygen atom, so the synchronization logic must ensure that threads proceed only in groups of three…

leetcodemediumconcurrency
CF 59B - Fortune Telling

Marina can pick any subset of flowers from the field. Each flower has a certain number of petals, and she will pluck all petals from all chosen flowers one by one. The phrases alternate between "Loves" and "Doesn't love", starting from "Loves" on the first petal.

codeforcescompetitive-programmingimplementationnumber-theory
LeetCode 868 - Binary Gap

The problem asks us to examine the binary representation of a positive integer n and determine the largest distance between two adjacent 1 bits. A binary number is made up of 0s and 1s.

leetcodeeasybit-manipulation
LeetCode 1294 - Weather Type in Each Country

This problem asks us to determine the weather type for each country during November 2019, based on the average weatherst

leetcodeeasydatabase
LeetCode 1418 - Display Table of Food Orders in a Restaurant

The problem gives a list of restaurant orders. Each order contains three pieces of information: - Customer name - Table number - Food item An order looks like this: The goal is to build a display table that summarizes how many times each food item was ordered at every table.

leetcodemediumarrayhash-tablestringsortingordered-set
LeetCode 1078 - Occurrences After Bigram

The problem gives us a string called text and two target words, first and second. We must find every occurrence where the words appear consecutively in the exact order: For every such occurrence, we return the value of third.

leetcodeeasystring
LeetCode 1211 - Queries Quality and Percentage

The problem gives us a database table named Queries. Each row represents the outcome of running a particular query against a database.

leetcodeeasydatabase
CF 118C - Fancy Number

We are given a string of digits representing a car number. The number is considered beautiful if at least k positions contain the same digit. We may change any digit into another digit, and changing digit a into digit b costs The task has two objectives.

codeforcescompetitive-programmingbrute-forcegreedysortingsstrings
LeetCode 858 - Mirror Reflection

This problem describes a square room with perfectly reflective walls. The room has side length p, and there are three receptors placed at three corners of the square: - Receptor 0 is at the southeast corner - Receptor 1 is at the northeast corner - Receptor 2 is at the…

leetcodemediummathgeometrynumber-theory
LeetCode 257 - Binary Tree Paths

The problem asks us to return every path from the root of a binary tree to each leaf node. A root-to-leaf path is formed by starting at the root node and continuously moving downward through child nodes until reaching a node that has no children.

leetcodeeasystringbacktrackingtreedepth-first-searchbinary-tree
LeetCode 1220 - Count Vowels Permutation

The problem asks us to count how many valid strings of length n can be formed using only the five lowercase vowels: - 'a' - 'e' - 'i' - 'o' - 'u' However, the strings are not arbitrary. Each vowel has strict rules about which vowels may appear immediately after it.

leetcodeharddynamic-programming
LeetCode 1414 - Find the Minimum Number of Fibonacci Numbers Whose Sum Is K

The problem asks us to find the minimum number of Fibonacci numbers whose sum equals a given integer k. Fibonacci number

leetcodemediummathgreedy
LeetCode 1204 - Last Person to Fit in the Bus

This problem gives us a database table named Queue that represents people waiting to board a bus. Each row contains a person's ID, name, weight, and boarding order. The turn column determines the exact sequence in which people attempt to board the bus.

leetcodemediumdatabase
CF 47D - Safe

We are trying to reconstruct a hidden binary string of length n. Every guess Vasya made is another binary string of the same length, together with a number saying how many positions matched the real code exactly.

codeforcescompetitive-programmingbrute-force
LeetCode 434 - Number of Segments in a String

The problem asks us to count how many separate word-like groups exist inside a string. In this problem, a "segment" is defined as a continuous sequence of characters that are not spaces.

leetcodeeasystring