brain

tamnd's digital brain — notes, problems, research

42715 notes

LeetCode 653 - Two Sum IV - Input is a BST

This problem gives us the root of a Binary Search Tree (BST) and an integer k. We must determine whether there are two distinct nodes in the tree whose values add up to k.

leetcodeeasyhash-tabletwo-pointerstreedepth-first-searchbreadth-first-searchbinary-search-treebinary-tree
CF 66C - Petya and File System

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.

codeforcescompetitive-programmingdata-structuresimplementation
CF 97C - Winning Strategy

Each year the university sends a team of exactly n students to the finals. Some of those students may already have participated once before, and the rest are newcomers.

codeforcescompetitive-programmingbinary-searchgraphsmathshortest-paths
CF 100G - Name the album

Aryo wants to choose a title for a new album from a list of candidate names. Some names have already been used in previous years. His decision rule has two layers. If a candidate name has never been used before, that is the best possible choice.

codeforcescompetitive-programming*specialdata-structuresimplementation
LeetCode 42 - Trapping Rain Water

The problem gives an array called height, where each element represents the height of a vertical bar in an elevation map. Every bar has width 1. After rainfall, water may become trapped between taller bars. The task is to compute the total amount of water that can be trapped.

leetcodehardarraytwo-pointersdynamic-programmingstackmonotonic-stack
LeetCode 435 - Non-overlapping Intervals

The problem gives an array of intervals where each interval is represented as [start, end]. Each interval describes a continuous range on a number line. The task is to remove the minimum number of intervals so that the remaining intervals no longer overlap.

leetcodemediumarraydynamic-programminggreedysorting
CF 73D - FreeDiv

We are given an undirected graph where cities are vertices and roads are edges. Each connected component of the graph is called a province. Vasya may additionally build tunnels between cities, but tunnels have two restrictions.

codeforcescompetitive-programmingdfs-and-similargraphsgreedy
LeetCode 879 - Profitable Schemes

This problem asks us to count how many subsets of crimes satisfy two constraints simultaneously: 1. The total number of members used is at most n 2.

leetcodehardarraydynamic-programming
CF 114A - Cifera

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…

codeforcescompetitive-programmingmath
LeetCode 877 - Stone Game

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.

leetcodemediumarraymathdynamic-programminggame-theory
CF 64C - Table

We are given an $n times m$ table filled with consecutive integers starting from 1. The filling is done row by row, left to right.

codeforcescompetitive-programming*specialgreedyimplementationmath
LeetCode 662 - Maximum Width of Binary Tree

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.

leetcodemediumtreedepth-first-searchbreadth-first-searchbinary-tree
CF 21A - Jabber ID

We need to validate whether a string follows the exact syntax of a Jabber ID.

codeforcescompetitive-programmingimplementationstrings
LeetCode 1607 - Sellers With No Sales

This problem asks us to identify all sellers who did not make any sales during the year 2020. We are given three databas

leetcodeeasydatabase
LeetCode 120 - Triangle

The problem gives us a triangular array of integers and asks us to compute the minimum path sum from the top row to the bottom row. The input is a two-dimensional array called triangle, where: - The first row contains exactly one number.

leetcodemediumarraydynamic-programming
LeetCode 369 - Plus One Linked List

The problem requires us to add one to a non-negative integer that is represented as a singly-linked list. Each node in the list contains a single digit, and the head of the list corresponds to the most significant digit.

leetcodemediumlinked-listmath
LeetCode 1792 - Maximum Average Pass Ratio

The problem gives us several classes, where each class is represented as [passi, totali]. The value passi tells us how many students currently pass the exam, while totali tells us the total number of students in that class.

leetcodemediumarraygreedyheap-(priority-queue)
LeetCode 1635 - Hopper Company Queries I

This problem asks us to generate monthly statistics for the year 2020 using information from three database tables: Driv

leetcodeharddatabase
CF 122A - Lucky Division

We are asked to determine whether a given number is almost lucky. A number is almost lucky if it is divisible by at least one lucky number. Lucky numbers are positive integers composed entirely of the digits 4 and 7, like 4, 7, 44, 47, 74, and so on.

codeforcescompetitive-programmingbrute-forcenumber-theory
LeetCode 1754 - Largest Merge Of Two Strings

This problem asks us to build the lexicographically largest possible string by repeatedly choosing characters from the front of two given strings.

leetcodemediumtwo-pointersstringgreedy
LeetCode 497 - Random Point in Non-overlapping Rectangles

The problem asks us to randomly pick an integer point from a set of non-overlapping rectangles in 2D space. Each rectangle is defined by its bottom-left (ai, bi) and top-right (xi, yi) corners.

leetcodemediumarraymathbinary-searchreservoir-samplingprefix-sumordered-setrandomized
CF 56B - Spoilt Permutation

We start from the sorted permutation 1 2 3 ... n. Someone chooses exactly one contiguous segment and reverses it. We are given the final permutation and must determine whether it could have been produced by exactly one such reversal. The task is not to sort the array.

codeforcescompetitive-programmingimplementation
LeetCode 935 - Knight Dialer

The problem asks us to count how many distinct phone numbers of length n can be generated by moving a chess knight across a numeric keypad. The keypad layout looks like this: A knight moves in an L-shape. From any current digit, it can jump only to specific other digits.

leetcodemediumdynamic-programming
LeetCode 1198 - Find Smallest Common Element in All Rows

The problem asks us to find the smallest element that appears in every row of a given m x n matrix mat, where each row is sorted in strictly increasing order. In other words, we need an element that is common to all rows and is the minimum among all such elements.

leetcodemediumarrayhash-tablebinary-searchmatrixcounting
CF 128E - Birthday

We are asked to determine the maximum number of banana pieces Maria can produce from a birthday cake decorated with n non-overlapping circular banana pieces using exactly k straight-line cuts. Each circle has a center coordinate (x, y) and a radius r.

codeforcescompetitive-programminggeometrymath
LeetCode 1502 - Can Make Arithmetic Progression From Sequence

The problem asks us to determine whether the elements of a given array can be rearranged so that they form an arithmetic

leetcodeeasyarraysorting
LeetCode 684 - Redundant Connection

The problem is asking us to identify a redundant edge in a graph that started as a tree. A tree is a connected graph with n nodes and exactly n-1 edges, meaning it has no cycles. The input graph has n nodes and n edges, so by definition, it contains exactly one cycle.

leetcodemediumdepth-first-searchbreadth-first-searchunion-findgraph-theory
LeetCode 82 - Remove Duplicates from Sorted List II

This problem asks us to process a sorted singly linked list and remove every value that appears more than once. The important distinction is that we are not keeping one copy of duplicated values. Instead, every node containing a duplicated value must be removed entirely.

leetcodemediumlinked-listtwo-pointers
LeetCode 2037 - Minimum Number of Moves to Seat Everyone

This problem asks us to assign students to seats such that every student occupies exactly one seat and no two students share the same seat. Each student can move left or right on a number line, and every movement by one position costs exactly one move.

leetcodeeasyarraygreedysortingcounting-sort
CF 116A - Tram

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.

codeforcescompetitive-programmingimplementation
LeetCode 227 - Basic Calculator II

The problem gives us a string representing a mathematical expression containing non-negative integers, spaces, and the four operators +, -, , and /. Our task is to evaluate the expression and return the resulting integer value.

leetcodemediummathstringstack
LeetCode 1557 - Minimum Number of Vertices to Reach All Nodes

The problem is asking us to identify the minimum set of vertices in a directed acyclic graph (DAG) such that starting from any of these vertices, all other nodes in the graph are reachable.

leetcodemediumgraph-theory
CF 85B - Embassy Queue

Each person visiting the embassy must pass through three consecutive stages. The first stage has k1 identical windows, each service taking t1 time. The second stage has k2 windows with service time t2, and the third stage has k3 windows with service time t3.

codeforcescompetitive-programmingdata-structuresgreedy
LeetCode 1390 - Four Divisors

The problem asks us to calculate the sum of divisors for numbers in a given integer array nums, but only for those numbe

leetcodemediumarraymath
CF 77E - Martian Food

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.

codeforcescompetitive-programminggeometry
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
LeetCode 1478 - Allocate Mailboxes

Here’s a complete, detailed technical solution guide for LeetCode 1478 following your requested format and requirements.

leetcodehardarraymathdynamic-programmingsorting
LeetCode 1666 - Change the Root of a Binary Tree

This problem asks us to reroot a binary tree at a given leaf node. Normally, a binary tree has a single root, and every node points downward to its children. In this problem, each node also contains a parent pointer, which allows traversal upward toward the root.

leetcodemediumtreedepth-first-searchbinary-tree
CF 26C - Parquet

We are asked to tile a rectangular floor of size n × m using three types of parquet planks. The first type is a 1×2 horizontal plank, the second is a 2×1 vertical plank, and the third is a 2×2 square plank.

codeforcescompetitive-programmingcombinatoricsconstructive-algorithmsgreedyimplementation
CF 101D - Castle

We are given a weighted tree rooted at hall 1, where Gerald starts. The treasure is hidden uniformly at random in one of the other halls. Gerald only discovers the treasure when he first enters the correct hall.

codeforcescompetitive-programmingdpgreedyprobabilitiessortingstrees
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 631 - Design Excel Sum Formula

The problem asks us to design a miniature spreadsheet system similar to Microsoft Excel. The spreadsheet contains cells arranged in rows and columns, where rows are numbered starting from 1 and columns are labeled using uppercase letters such as A, B, C, and so on.

leetcodehardarrayhash-tablestringgraph-theorydesigntopological-sortmatrix
LeetCode 371 - Sum of Two Integers

The problem asks us to compute the sum of two integers without using the arithmetic operators + and -. Instead of relying on normal arithmetic, we must use bit manipulation to simulate how addition works at the binary level. The input consists of two integers, a and b.

leetcodemediummathbit-manipulation
LeetCode 287 - Find the Duplicate Number

The problem gives us an integer array nums of length n + 1, where every value is guaranteed to be in the range [1, n]. Since there are n + 1 numbers but only n possible distinct values, at least one number must appear more than once. The task is to return that duplicate value.

leetcodemediumarraytwo-pointersbinary-searchbit-manipulation
CF 52B - Right Triangles

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:

codeforcescompetitive-programmingcombinatorics
LeetCode 1755 - Closest Subsequence Sum

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.

leetcodehardarraytwo-pointersdynamic-programmingbit-manipulationsortingbitmask
CF 98E - Help Shrek and Donkey

There are m + n + 1 distinct cards in total. Shrek initially knows his own m cards, Donkey knows his own n cards, and one card is hidden on the table. Nobody knows the hidden card directly. Players alternate turns, with Shrek moving first.

codeforcescompetitive-programmingdpgamesmathprobabilities
LeetCode 1554 - Strings Differ by One Character

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.

leetcodemediumhash-tablestringrolling-hashhash-function
LeetCode 1264 - Page Recommendations

This problem models a small social network with two database tables. The Friendship table stores friendship relationship

leetcodemediumdatabase
LeetCode 379 - Design Phone Directory

The problem asks us to design a data structure that manages a fixed pool of phone numbers. Initially, every number from 0 to maxNumbers - 1 is available. The directory must support three operations efficiently. The get() operation should assign and return an available number.

leetcodemediumarrayhash-tablelinked-listdesignqueue
LeetCode 290 - Word Pattern

The problem gives two inputs: a pattern string and a space-separated string of words. We need to determine whether the sequence of words follows the same structure as the sequence of characters in the pattern.

leetcodeeasyhash-tablestring
CF 70B - Text Messaging

We are given the maximum length of a single SMS message and one complete text consisting of sentences separated by spaces. A sentence always ends with one of ., ?, or !. Words contain only letters.

codeforcescompetitive-programmingexpression-parsinggreedystrings
LeetCode 1698 - Number of Distinct Substrings in a String

The problem asks for the total number of distinct substrings of a given string s. A substring is any contiguous sequence of characters from the string, including single-character substrings and the string itself.

leetcodemediumstringtrierolling-hashsuffix-arrayhash-function
LeetCode 229 - Majority Element II

The problem asks us to find every element in an integer array that appears more than ⌊ n/3 ⌋ times, where n is the length of the array. The floor notation means we round down to the nearest integer.

leetcodemediumarrayhash-tablesortingcounting
LeetCode 1395 - Count Number of Teams

The problem asks us to count the number of valid teams of three soldiers from a line of n soldiers, where each soldier h

leetcodemediumarraydynamic-programmingbinary-indexed-treesegment-tree
LeetCode 2033 - Minimum Operations to Make a Uni-Value Grid

The problem gives us a 2D integer matrix called grid and an integer x. In one operation, we may either add x to a cell or subtract x from a cell. Our goal is to make every value in the grid equal using the minimum number of operations.

leetcodemediumarraymathsortingmatrix
LeetCode 1160 - Find Words That Can Be Formed by Characters

This problem asks us to determine which words from a given list can be constructed using the characters available in another string, chars. A word is considered good if every character it needs exists in chars in sufficient quantity.

leetcodeeasyarrayhash-tablestringcounting
LeetCode 314 - Binary Tree Vertical Order Traversal

The problem asks us to group the nodes of a binary tree by their vertical columns and return those groups from left to right.

leetcodemediumhash-tabletreedepth-first-searchbreadth-first-searchsortingbinary-tree
CF 37A - Towers

We are given a set of wooden bars, each with a positive integer length. Vasya wants to build towers by stacking bars of the same length. Each tower must consist of bars that are identical in length, but different towers can have different lengths.

codeforcescompetitive-programmingsortings
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 115C - Plumber

We have an n × m grid. Every cell must contain one of four corner-shaped pipe pieces. Each piece connects exactly two adjacent sides of the cell.

codeforcescompetitive-programmingmath
LeetCode 1458 - Max Dot Product of Two Subsequences

The problem is asking to find the maximum dot product of two non-empty subsequences of arrays nums1 and nums2 such that

leetcodehardarraydynamic-programming
LeetCode 438 - Find All Anagrams in a String

The problem gives two strings, s and p, both containing only lowercase English letters. We need to find every starting index in s where a substring is an anagram of p.

leetcodemediumhash-tablestringsliding-window
LeetCode 1175 - Prime Arrangements

The problem asks us to count how many permutations of numbers from 1 to n satisfy a specific condition: all prime numbers must appear at prime-numbered indices (1-indexed).

leetcodeeasymath
LeetCode 1814 - Count Nice Pairs in an Array

The problem gives us an array of non-negative integers called nums. We need to count how many index pairs (i, j) satisfy the following conditions: - i < j - nums[i] + rev(nums[j]) == nums[j] + rev(nums[i]) Here, rev(x) means reversing the digits of the integer.

leetcodemediumarrayhash-tablemathcounting
LeetCode 1231 - Divide Chocolate

The problem asks us to divide a chocolate bar into k + 1 consecutive pieces such that we maximize the minimum total sweetness among those pieces. Each element in the input array sweetness represents the sweetness of a single chunk.

leetcodehardarraybinary-search
LeetCode 1129 - Shortest Path with Alternating Colors

The problem gives us a directed graph with n nodes labeled from 0 to n - 1. Every edge in the graph has a color, either red or blue.

leetcodemediumbreadth-first-searchgraph-theory
LeetCode 1765 - Map of Highest Peak

The problem presents a matrix isWater of size m x n where each cell is either water (1) or land (0). We are asked to assign heights to every cell in a way that satisfies three rules. First, all heights must be non-negative integers. Second, water cells must have a height of 0.

leetcodemediumarraybreadth-first-searchmatrix
LeetCode 1048 - Longest String Chain

That is a long, structured technical guide that will exceed a practical single-message limit if done comprehensively with all requested sections, detailed walkthroughs, Python and Go solutions, worked examples, full test suite, and edge case analysis.

leetcodemediumarrayhash-tabletwo-pointersstringdynamic-programmingsorting
LeetCode 298 - Binary Tree Longest Consecutive Sequence

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.

leetcodemediumtreedepth-first-searchbinary-tree
LeetCode 256 - Paint House

The problem gives us a row of houses, where each house must be painted using exactly one of three colors: red, blue, or green. The input is provided as a two-dimensional array named costs, where costs[i][j] represents the cost of painting the i-th house with the j-th color.

leetcodemediumarraydynamic-programming
LeetCode 1259 - Handshakes That Don't Cross

In this problem, we are given an even number of people standing around a circle. Every person must participate in exactl

leetcodehardmathdynamic-programming
LeetCode 723 - Candy Crush

This problem is essentially a simulation of the Candy Crush game, where we need to repeatedly crush candies in a grid until the board reaches a stable state. The input is an m x n matrix of integers representing different types of candies, and 0 represents empty cells.

leetcodemediumarraytwo-pointersmatrixsimulation
LeetCode 537 - Complex Number Multiplication

This problem asks us to multiply two complex numbers represented as strings and return the result in the same string format.

leetcodemediummathstringsimulation
LeetCode 18 - 4Sum

We are given an integer array nums and an integer target. The goal is to find every unique quadruplet of numbers in the array whose sum equals the target value. A quadruplet consists of four elements: where all four indices are distinct.

leetcodemediumarraytwo-pointerssorting
LeetCode 312 - Burst Balloons

The problem gives us an array nums, where each element represents a balloon containing a number. When we burst a balloon at index i, we gain coins equal to: The important detail is that the neighbors of a balloon change dynamically as balloons are removed.

leetcodehardarraydynamic-programming
LeetCode 1718 - Construct the Lexicographically Largest Valid Sequence

The problem asks us to construct a special integer sequence using numbers from 1 to n. The resulting sequence has length 2 n - 1 because: - The number 1 appears exactly once. - Every number from 2 to n appears exactly twice.

leetcodemediumarraybacktracking
LeetCode 886 - Possible Bipartition

This problem asks whether it is possible to divide n people into exactly two groups such that no pair of people who dislike each other end up in the same group.

leetcodemediumdepth-first-searchbreadth-first-searchunion-findgraph-theory
LeetCode 899 - Orderly Queue

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.

leetcodehardmathstringsorting
LeetCode 292 - Nim Game

The problem describes a two-player game involving a single heap of stones. There are n stones initially on the table, and players alternate turns removing stones. On each turn, a player may remove either 1, 2, or 3 stones. The player who removes the final stone wins the game.

leetcodeeasymathbrainteasergame-theory
LeetCode 611 - Valid Triangle Number

The problem asks us to determine how many triplets from a given integer array nums can form a valid triangle. In geometric terms, a triangle is valid if the sum of any two sides is greater than the third side.

leetcodemediumarraytwo-pointersbinary-searchgreedysorting
CF 113E - Sleeping

We are asked to count the number of times a digital clock shows a moment where at least k digits change simultaneously while Vasya is watching it. The clock is not necessarily 24-hour or 60-minute - it has h hours and m minutes, where both are arbitrary integers up to 10^9.

codeforcescompetitive-programmingcombinatoricsimplementationmath
LeetCode 2229 - Check if an Array Is Consecutive

The problem asks us to determine whether an integer array forms a perfect sequence of consecutive numbers without gaps o

leetcodeeasyarrayhash-tablesorting
LeetCode 390 - Elimination Game

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.

leetcodemediummathrecursion
LeetCode 453 - Minimum Moves to Equal Array Elements

The problem gives an integer array nums with n elements. In a single move, you are allowed to increment exactly n - 1 elements by 1. Your goal is to determine the minimum number of such moves required to make every element in the array equal.

leetcodemediumarraymath
LeetCode 1504 - Count Submatrices With All Ones

The problem gives us an m x n binary matrix where each cell contains either 0 or 1. We must count how many rectangular submatrices consist entirely of ones. A submatrix is any contiguous rectangular region inside the matrix.

leetcodemediumarraydynamic-programmingstackmatrixmonotonic-stack
LeetCode 602 - Friend Requests II: Who Has the Most Friends

The problem gives us a database table named RequestAccepted, where each row represents a successfully accepted friend request between two users. Every record contains a requesterid, an accepterid, and the date the request was accepted.

leetcodemediumdatabase
CF 65E - Harry Potter and Moving Staircases

We are given an undirected multigraph. Floors are vertices, staircases are edges. Harry starts at floor 1 and wants to visit every floor at least once. The graph is dynamic. Between Harry's walks, Ron and Hermione may modify staircases.

codeforcescompetitive-programmingdfs-and-similarimplementation
CF 82A - Double Cola

Five people stand in a queue in a fixed order: Sheldon, Leonard, Penny, Rajesh, Howard. Whenever the person at the front buys a cola, that person immediately creates a copy of themselves, and both copies go to the back of the queue. The queue keeps growing forever.

codeforcescompetitive-programmingimplementationmath
LeetCode 99 - Recover Binary Search Tree

The problem gives us the root of a binary search tree, but exactly two nodes in the tree have had their values swapped accidentally. Our task is to restore the tree so that it once again satisfies the binary search tree property, without modifying the tree structure itself.

leetcodemediumtreedepth-first-searchbinary-search-treebinary-tree
LeetCode 842 - Split Array into Fibonacci Sequence

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.

leetcodemediumstringbacktracking
LeetCode 420 - Strong Password Checker

The problem asks us to determine the minimum number of operations required to transform a given password into a "strong" password according to three rules. A strong password must satisfy all of the following conditions: 1.

leetcodehardstringgreedyheap-(priority-queue)
CF 6A - Triangle

We are given four stick lengths, and we must choose exactly three of them. Depending on the relationship between those three lengths, there are three possible outcomes.

codeforcescompetitive-programmingbrute-forcegeometry
LeetCode 419 - Battleships in a Board

This problem gives us a two dimensional grid where each cell contains either 'X' or '.'. An 'X' represents part of a battleship, while '.' represents empty water. The important rule is that battleships are always placed in straight lines.

leetcodemediumarraydepth-first-searchmatrix
CF 24B - F1 Champions

We are given the results of an entire Formula One season. Each race lists drivers from first place to last place. The championship winner depends on one of two ranking systems.

codeforcescompetitive-programmingimplementation
LeetCode 607 - Sales Person

This problem asks us to find the names of all salespeople who have never handled an order for the company named "RED". We are given three database tables: - SalesPerson contains information about each salesperson, including their unique salesid and name.

leetcodeeasydatabase
LeetCode 860 - Lemonade Change

This problem simulates a lemonade stand where each lemonade costs 5, 20 bill. The challenge is to provide exact change to every customer as they pay. The input is a list of integers bills, where each element represents the bill a customer gives.

leetcodeeasyarraygreedy
CF 60C - Mushroom Strife

We have an undirected graph where each vertex stores some positive integer, the number of mushrooms on that lawn. For every known edge, we are given two values: the gcd of the two endpoint values and the lcm of the two endpoint values.

codeforcescompetitive-programmingbrute-forcedfs-and-similar
CF 79C - Beaver

We are asked to find the longest contiguous substring of a string s that avoids certain "boring" substrings. In other words, given a string s and a small list of forbidden patterns b1, b2, ...

codeforcescompetitive-programmingdata-structuresdpgreedyhashingstringstwo-pointers
LeetCode 429 - N-ary Tree Level Order Traversal

The problem asks us to perform a level order traversal of an n-ary tree. In other words, we need to return the values of the tree nodes grouped by their depth. The root node represents level 0, its immediate children are level 1, their children are level 2, and so on.

leetcodemediumtreebreadth-first-search