brain

tamnd's digital brain — notes, problems, research

42715 notes

LeetCode 1189 - Maximum Number of Balloons

The problem asks us to determine the maximum number of times the word "balloon" can be formed using the characters from a given string text. Each character in text can be used at most once per occurrence of the word.

leetcodeeasyhash-tablestringcounting
LeetCode 1051 - Height Checker

The problem gives us an array called heights, where each value represents the height of a student standing in a line. The school wants the students arranged in non-decreasing order, meaning heights should appear from smallest to largest, allowing duplicates.

leetcodeeasyarraysortingcounting-sort
LeetCode 564 - Find the Closest Palindrome

The problem gives us a string n representing a positive integer, and asks us to find the numerically closest palindrome that is not equal to the original number itself. A palindrome is a number that reads the same forward and backward. Examples include 121, 999, and 1331.

leetcodehardmathstring
LeetCode 1582 - Special Positions in a Binary Matrix

Here is a complete, detailed technical solution guide for LeetCode 1582 - Special Positions in a Binary Matrix, followin

leetcodeeasyarraymatrix
LeetCode 2013 - Detect Squares

The problem presents a stream of points in a 2D plane and asks us to design a data structure that supports two operations efficiently: adding points and counting squares.

leetcodemediumarrayhash-tabledesigncountingdata-stream
LeetCode 594 - Longest Harmonious Subsequence

The problem asks us to find the length of the longest harmonious subsequence in an integer array. A harmonious array is defined as one where the difference between the maximum and minimum values is exactly 1.

leetcodeeasyarrayhash-tablesliding-windowsortingcounting
LeetCode 1073 - Adding Two Negabinary Numbers

The problem asks us to add two numbers that are represented in negabinary, which is base -2. Unlike standard binary (base 2), each bit in negabinary contributes a value multiplied by powers of -2.

leetcodemediumarraymath
CF 44H - Phone Number

We are given Masha's phone number as a string of digits. From this number, she generates another phone number digit by digit. The first digit of the new number can be any digit from 0 to 9.

codeforcescompetitive-programmingdp
CF 120I - Luck is in Numbers

The problem asks us to find the next "lucky" ticket number that is strictly greater than a given ticket. Each ticket is a string of digits with even length, denoted 2n.

codeforcescompetitive-programminggreedy
CF 17D - Notepad

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.

codeforcescompetitive-programmingnumber-theory
LeetCode 827 - Making A Large Island

This problem asks us to find the largest possible island size in a binary grid after changing at most one 0 into 1.

leetcodehardarraydepth-first-searchbreadth-first-searchunion-findmatrix
LeetCode 972 - Equal Rational Numbers

The problem asks us to determine whether two strings s and t, each representing a rational number in decimal notation, correspond to the same numerical value. These numbers can be expressed as integers, finite decimals, or decimals with repeating parts denoted by parentheses.

leetcodehardmathstring
LeetCode 1293 - Shortest Path in a Grid with Obstacles Elimination

This problem asks us to find the minimum number of steps required to move from the top-left corner of a grid to the bott

leetcodehardarraybreadth-first-searchmatrix
LeetCode 1608 - Special Array With X Elements Greater Than or Equal X

The problem gives us an array nums containing non-negative integers. We need to determine whether there exists an intege

leetcodeeasyarraybinary-searchsorting
CF 54E - Vacuum Сleaner

We are given the top view of a robotic vacuum cleaner as a convex polygon. The room corner is the usual 90 degree corner formed by two perpendicular walls. We may rotate the vacuum cleaner by any angle and then push it as far as possible into the corner.

codeforcescompetitive-programminggeometry
CF 81B - Sequence Formatting

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.

codeforcescompetitive-programmingimplementationstrings
LeetCode 1221 - Split a String in Balanced Strings

This problem gives us a string s that contains only the characters 'L' and 'R'. The string is guaranteed to already be balanced overall, meaning the total number of 'L' characters equals the total number of 'R' characters.

leetcodeeasystringgreedycounting
LeetCode 74 - Search a 2D Matrix

This problem gives us a two dimensional matrix with two very important ordering properties: 1. Each row is sorted from left to right in non-decreasing order. 2. The first element of every row is greater than the last element of the previous row.

leetcodemediumarraybinary-searchmatrix
LeetCode 2036 - Maximum Alternating Subarray Sum

The problem asks us to compute the maximum alternating subarray sum for a given integer array. A subarray is any contiguous sequence of elements from the array.

leetcodemediumarraydynamic-programming
LeetCode 397 - Integer Replacement

The problem gives us a positive integer n and asks for the minimum number of operations required to transform it into 1.

leetcodemediumdynamic-programminggreedybit-manipulationmemoization
LeetCode 402 - Remove K Digits

The problem gives us a numeric string num and an integer k. We must remove exactly k digits from the number so that the resulting integer is as small as possible. The key detail is that we are not allowed to reorder digits.

leetcodemediumstringstackgreedymonotonic-stack
LeetCode 2963 - Count the Number of Good Partitions

The problem asks us to count the number of ways we can partition a given array nums of positive integers into contiguous

leetcodehardarrayhash-tablemathcombinatorics
LeetCode 1817 - Finding the Users Active Minutes

This problem asks us to analyze a collection of user activity logs and determine how many users have a specific number of unique active minutes.

leetcodemediumarrayhash-table
LeetCode 437 - Path Sum III

The problem gives us the root of a binary tree and an integer targetSum. We need to count how many downward paths in the tree have values that add up exactly to targetSum. A path can begin at any node and end at any node, as long as it always moves downward from parent to child.

leetcodemediumtreedepth-first-searchbinary-tree
LeetCode 1361 - Validate Binary Tree Nodes

The problem gives us n nodes labeled from 0 to n - 1. For every node i, we are told which node is its left child and which node is its right child through the arrays leftChild and rightChild. If leftChild[i] = x, then node x is the left child of node i.

leetcodemediumtreedepth-first-searchbreadth-first-searchunion-findgraph-theorybinary-tree
CF 40E - Number Table

We are given a table representing the economy of Berland over n days and m months. Each cell in the table contains either 1 or -1, indicating a profit or a loss for that day of that month.

codeforcescompetitive-programmingcombinatorics
LeetCode 138 - Copy List with Random Pointer

This problem asks us to create a completely independent copy of a linked list where each node contains two pointers: - next, which points to the next node in the list - random, which can point to any node in the list or null The key requirement is that the copied list must be…

leetcodemediumhash-tablelinked-list
LeetCode 640 - Solve the Equation

The problem is asking us to solve a linear equation containing a single variable 'x' and integer coefficients, expressed as a string. The equation may include addition '+', subtraction '-', and the equality operator '='.

leetcodemediummathstringsimulation
CF 123D - String

We are given a string s. For every substring x of s, we look at all positions where x appears inside s. Suppose these occurrences start at positions: $$p1 < p2 < dots < pk$$ The function F(s, x) counts how many contiguous segments we can choose from this ordered list of…

codeforcescompetitive-programmingstring-suffix-structures
LeetCode 1157 - Online Majority Element In Subarray

The problem asks us to design a data structure that can efficiently answer majority element queries on subarrays of a given array.

leetcodehardarraybinary-searchdesignbinary-indexed-treesegment-tree
LeetCode 982 - Triples with Bitwise AND Equal To Zero

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.

leetcodehardarrayhash-tablebit-manipulation
CF 89E - Fire and Ice

Solomon stands on the fortress wall at position 0. To his right there may exist a chain of ice blocks occupying positions 1, 2, .... Initially there are no blocks at all. The battlefield is a line of length n. At battlefield position i, there may be a demon with strength a[i].

codeforcescompetitive-programminggreedy
CF 130A - Hexagonal numbers

We need to compute the $n$-th hexagonal number. The sequence is defined by the formula $$hn = 2n^2 - n$$ The input contains a single integer $n$, and the output is the value produced by this formula.

codeforcescompetitive-programming*specialimplementation
LeetCode 732 - My Calendar III

This problem asks us to design a calendar system that supports adding time intervals and reporting the highest number of overlapping events seen so far. Each booking is represented as a half open interval [startTime, endTime).

leetcodehardbinary-searchdesignsegment-treeprefix-sumordered-set
LeetCode 2007 - Find Original Array From Doubled Array

The problem gives us an array called changed, which was supposedly created from another array called original. The transformation process works like this: 1. Take every number in original. 2. Append its doubled value, meaning 2 x. 3. Shuffle all the numbers together.

leetcodemediumarrayhash-tablegreedysorting
LeetCode 1697 - Checking Existence of Edge Length Limited Paths

This problem gives us an undirected weighted graph with n nodes. Each edge connects two nodes and has a distance value associated with it.

leetcodehardarraytwo-pointersunion-findgraph-theorysorting
LeetCode 1468 - Calculate Salaries

This problem asks us to compute the post tax salary for every employee in the Salaries table. However, the tax rate is n

leetcodemediumdatabase
LeetCode 1505 - Minimum Possible Integer After at Most K Adjacent Swaps On Digits

The problem gives us a numeric string num and an integer k. Each operation allows us to swap two adjacent digits. We may

leetcodehardstringgreedybinary-indexed-treesegment-tree
LeetCode 1341 - Movie Rating

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.

leetcodemediumdatabase
LeetCode 1529 - Minimum Suffix Flips

This problem is asking us to transform an initial binary string s (all zeros) into a target binary string target using a

leetcodemediumstringgreedy
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
CF 129A - Cookies

We are given several bags of cookies, where each bag contains some number of cookies. Olga wants to steal exactly one bag. After removing that bag, the total number of cookies left behind must be even so the two sisters can split them equally.

codeforcescompetitive-programmingimplementation
LeetCode 346 - Moving Average from Data Stream

The problem asks us to design a data structure that continuously receives integers from a stream and returns the average of the most recent values within a fixed-size sliding window. A sliding window means that we only care about the latest size elements.

leetcodeeasyarraydesignqueuedata-stream
LeetCode 239 - Sliding Window Maximum

The problem gives us an integer array nums and a window size k. A sliding window of length k starts at the beginning of the array and moves one position to the right at a time. For every position of this window, we must determine the maximum value inside that window.

leetcodehardarrayqueuesliding-windowheap-(priority-queue)monotonic-queue
LeetCode 1296 - Divide Array in Sets of K Consecutive Numbers

The problem gives us an integer array nums and an integer k. We need to determine whether it is possible to divide all n

leetcodemediumarrayhash-tablegreedysorting
LeetCode 1401 - Circle and Rectangle Overlapping

The problem gives two geometric shapes: 1. A circle, defined by: - radius - center coordinates (xCenter, yCenter) 2. An axis-aligned rectangle, defined by: - bottom-left corner (x1, y1) - top-right corner (x2, y2) The goal is to determine whether the circle and rectangle overlap.

leetcodemediummathgeometry
CF 131D - Subway

We are given a subway system of n stations connected by exactly n passages, each passage connecting two distinct stations. The system forms a connected graph where each station can reach every other station.

codeforcescompetitive-programmingdfs-and-similargraphs
LeetCode 862 - Shortest Subarray with Sum at Least K

The problem asks us to find the length of the shortest contiguous subarray whose sum is at least k. We are given an integer array nums, which may contain both positive and negative numbers, and an integer k.

leetcodehardarraybinary-searchqueuesliding-windowheap-(priority-queue)prefix-summonotonic-queue
LeetCode 1434 - Number of Ways to Wear Different Hats to Each Other

This problem asks us to count how many valid ways exist to assign hats to people under two constraints: 1. Every person

leetcodehardarraydynamic-programmingbit-manipulationbitmask
LeetCode 1442 - Count Triplets That Can Form Two Arrays of Equal XOR

The problem asks us to find the number of triplets (i, j, k) in an array arr such that the XOR of elements from index i

leetcodemediumarrayhash-tablemathbit-manipulationprefix-sum
CF 7E - Defining Macros

We are given a set of C-style #define macros and an expression, and we are asked to determine whether the expression becomes "suspicious" after macro substitution.

codeforcescompetitive-programmingdpexpression-parsingimplementation
LeetCode 404 - Sum of Left Leaves

The problem gives us the root node of a binary tree and asks us to compute the sum of all left leaves in the tree. A binary tree node may have up to two children, a left child and a right child.

leetcodeeasytreedepth-first-searchbreadth-first-searchbinary-tree
LeetCode 148 - Sort List

The problem asks us to sort a singly linked list in ascending order and return the head of the sorted list. The input is the head node of a linked list. Each node contains an integer value and a pointer to the next node.

leetcodemediumlinked-listtwo-pointersdivide-and-conquersortingmerge-sort
LeetCode 1452 - People Whose List of Favorite Companies Is Not a Subset of Another List

The problem requires identifying all people in a group whose list of favorite companies is not a subset of any other per

leetcodemediumarrayhash-tablestring
LeetCode 1476 - Subrectangle Queries

The problem asks us to design a class called SubrectangleQueries that operates on a two dimensional integer matrix, refe

leetcodemediumarraydesignmatrix
CF 48F - Snow sellers

We are asked to plan snow purchases over n days from m companies, ensuring we buy exactly W cubic meters each day. Each company produces a fixed daily amount w[i], but the cost of all snow from that company decreases linearly: c[i] on day 1, c[i] - a[i] on day 2, and so on.

codeforcescompetitive-programminggreedysortings
CF 128B - String

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.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmshashingimplementationstring-suffix-structuresstrings
LeetCode 1335 - Minimum Difficulty of a Job Schedule

The problem gives us an array jobDifficulty, where each element represents the difficulty of a job. The jobs must be com

leetcodehardarraydynamic-programming
LeetCode 1020 - Number of Enclaves

The problem gives us a binary matrix called grid, where: - 0 represents water - 1 represents land We can move only in four directions, up, down, left, and right.

leetcodemediumarraydepth-first-searchbreadth-first-searchunion-findmatrix
LeetCode 1273 - Delete Tree Nodes

The problem provides a tree rooted at node 0, represented in two parallel arrays: parent and value. The parent[i] array

leetcodemediumarraytreedepth-first-searchbreadth-first-search
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 2020 - Number of Accounts That Did Not Stream

This problem asks us to analyze two database tables, Subscriptions and Streams, and determine how many accounts purchased a subscription during the year 2021 but never streamed any content during 2021. The Subscriptions table stores subscription intervals for each account.

leetcodemediumdatabase
LeetCode 1145 - Binary Tree Coloring Game

The problem is a two-player game played on a binary tree, where each player colors nodes starting from an initial chosen node. Player 1 picks a node x and colors it red, while Player 2 picks a different node y and colors it blue.

leetcodemediumtreedepth-first-searchbinary-tree
LeetCode 554 - Brick Wall

The problem gives us a wall made of multiple rows of bricks. Each row is represented as an array of integers, where each integer describes the width of a brick. Every brick has height 1, and all rows together form a rectangle with the same total width.

leetcodemediumarrayhash-table
LeetCode 341 - Flatten Nested List Iterator

This problem asks us to design an iterator that can traverse a deeply nested list structure as if it were a flat list of integers. The input is not a normal array.

leetcodemediumstacktreedepth-first-searchdesignqueueiterator
LeetCode 1539 - Kth Missing Positive Number

The problem gives us a strictly increasing array of positive integers, arr, and an integer k. The array does not necessa

leetcodeeasyarraybinary-search
CF 55E - Very simple problem

We are given a convex polygon defined by a list of points in clockwise order. For each query point in the plane, we need to count how many triangles formed by the polygon’s vertices contain that point strictly inside.

codeforcescompetitive-programminggeometrytwo-pointers
LeetCode 1726 - Tuple with Same Product

The problem asks us to count all tuples (a, b, c, d) from a given array of distinct positive integers such that the product of the first two elements equals the product of the second two elements, a b = c d, and all elements are distinct.

leetcodemediumarrayhash-tablecounting
LeetCode 1818 - Minimum Absolute Sum Difference

The problem gives two arrays of positive integers, nums1 and nums2, both of equal length n. The goal is to calculate the absolute sum difference between these arrays, which is the sum of the absolute differences at each index: |nums1[i] - nums2[i]|.

leetcodemediumarraybinary-searchsortingordered-set
LeetCode 389 - Find the Difference

This problem gives us two strings, s and t. The string t is created by taking all characters from s, shuffling them into a different order, and then inserting exactly one additional character somewhere in the string. Our task is to identify and return that extra character.

leetcodeeasyhash-tablestringbit-manipulationsorting
CF 82D - Two out of Three

We are asked to simulate a queue of customers, where each customer has a known service time. The cashier can serve two people simultaneously, and the time to serve two people at once is the maximum of their individual times.

codeforcescompetitive-programmingdp
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 1307 - Verbal Arithmetic Puzzle

The problem gives a collection of words on the left side of an equation and a single result word on the right side. Each distinct uppercase letter must be assigned a unique digit from 0 to 9.

leetcodehardarraymathstringbacktracking
LeetCode 521 - Longest Uncommon Subsequence I

The problem asks us to find the length of the longest uncommon subsequence between two strings a and b. To understand the problem clearly, we first need to understand what an uncommon subsequence means.

leetcodeeasystring
LeetCode 1331 - Rank Transform of an Array

The problem asks us to replace every number in the input array with its rank when the array is sorted in ascending order.

leetcodeeasyarrayhash-tablesorting
LeetCode 538 - Convert BST to Greater Tree

This problem asks us to transform a Binary Search Tree, abbreviated as BST, into a "Greater Tree". In the transformed tree, every node's value should become: - its original value - plus the sum of all values greater than it in the original BST The structure of the tree does…

leetcodemediumtreedepth-first-searchbinary-search-treebinary-tree
LeetCode 1286 - Iterator for Combination

The problem asks us to design a class CombinationIterator that generates all combinations of a given length from a strin

leetcodemediumstringbacktrackingdesigniterator
CF 120F - Spiders

We are given a collection of toy spiders. Each spider is a tree, represented by beads (nodes) connected with strings (edges). A spider with $k$ beads has $k-1$ strings connecting its beads so that all beads are connected and there are no cycles.

codeforcescompetitive-programmingdpgreedytrees
CF 30C - Shooting Gallery

We are asked to help King Copa maximize his expected number of hits in a shooting gallery. The gallery is represented as a 2D plane, and each target appears at a specific point exactly at a specific time and disappears immediately afterward.

codeforcescompetitive-programmingdpprobabilities
LeetCode 587 - Erect the Fence

This problem is asking us to find the convex hull of a set of points on a 2D plane. The input trees is a list of coordinates where each coordinate [xi, yi] represents the location of a tree in the garden.

leetcodehardarraymathgeometry
LeetCode 1696 - Jump Game VI

The problem gives us an integer array nums and a maximum jump distance k. We start at index 0, and from any position i,

leetcodemediumarraydynamic-programmingqueueheap-(priority-queue)monotonic-queue
LeetCode 1358 - Number of Substrings Containing All Three Characters

The problem asks us to count all substrings of a given string s that contain at least one occurrence of each character '

leetcodemediumhash-tablestringsliding-window
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 413 - Arithmetic Slices

The problem asks us to count how many contiguous subarrays of length at least three form an arithmetic sequence. An arithmetic sequence is one where the difference between every pair of adjacent elements is identical.

leetcodemediumarraydynamic-programmingsliding-window
LeetCode 1615 - Maximal Network Rank

The problem asks us to compute the maximal network rank for a set of cities connected by bidirectional roads. Each city can be thought of as a node in a graph, and each road as an undirected edge.

leetcodemediumgraph-theory
LeetCode 10 - Regular Expression Matching

LeetCode 10, Regular Expression Matching, asks us to determine whether an entire input string s matches a pattern p. The pattern supports two special regular expression characters: - .

leetcodehardstringdynamic-programmingrecursion
LeetCode 573 - Squirrel Simulation

This problem models a squirrel collecting nuts in a 2D garden grid. The garden has a fixed tree position, a starting squirrel position, and multiple nuts scattered around the grid.

leetcodemediumarraymath
LeetCode 632 - Smallest Range Covering Elements from K Lists

The problem gives us k sorted integer lists, and we must find the smallest inclusive range [a, b] such that the range contains at least one element from every list. Each list is already sorted in non-decreasing order, which is a very important property.

leetcodehardarrayhash-tablegreedysliding-windowsortingheap-(priority-queue)
CF 100I - Rotation

We are given a point $(x, y)$ on the 2D plane and an angle $k$ in degrees. The task is to rotate the point counter-clockwise around the origin by exactly $k$ degrees and print the coordinates of the new point.

codeforcescompetitive-programming*specialgeometrymath
LeetCode 376 - Wiggle Subsequence

The problem asks us to find the length of the longest subsequence in an array such that the differences between consecutive elements alternate between positive and negative.

leetcodemediumarraydynamic-programminggreedy
CF 106E - Space Rescuers

We are asked to place a space rescue station in three-dimensional space such that the maximum distance from it to any of the given planets is minimized. Each planet is represented by its coordinates $(x, y, z)$.

codeforcescompetitive-programminggeometryternary-search
LeetCode 231 - Power of Two

The problem asks us to determine whether a given integer n is a power of two. A number is considered a power of two if it can be written in the form: where x is a non-negative integer.

leetcodeeasymathbit-manipulationrecursion
LeetCode 315 - Count of Smaller Numbers After Self

The problem asks us to compute, for every element in the array, how many elements to its right are strictly smaller than it. Given an array nums, we must return another array counts of the same length.

leetcodehardarraybinary-searchdivide-and-conquerbinary-indexed-treesegment-treemerge-sortordered-set
LeetCode 234 - Palindrome Linked List

The problem gives us the head of a singly linked list and asks whether the sequence of values stored in the list forms a palindrome. A palindrome is a sequence that reads the same forward and backward.

leetcodeeasylinked-listtwo-pointersstackrecursion
LeetCode 159 - Longest Substring with At Most Two Distinct Characters

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.

leetcodemediumhash-tablestringsliding-window
LeetCode 1611 - Minimum One Bit Operations to Make Integers Zero

This problem asks us to transform a given integer n into 0 using a specialized set of bit-flipping operations. Each oper

leetcodehardmathdynamic-programmingbit-manipulationrecursionmemoization
CF 14E - Camels

We are counting sequences of heights that describe a polyline. The x-coordinates are fixed as 1, 2, ..., n, so the whole shape is determined only by the sequence y1, y2, ..., yn.

codeforcescompetitive-programmingdp
LeetCode 1595 - Minimum Cost to Connect Two Groups of Points

The problem is asking us to find the minimum cost to connect two groups of points, where the first group has size1 point

leetcodehardarraydynamic-programmingbit-manipulationmatrixbitmask
LeetCode 1603 - Design Parking System

This problem asks us to design a very small parking lot management system. The parking lot contains exactly three types

leetcodeeasydesignsimulationcounting
LeetCode 1377 - Frog Position After T Seconds

This problem describes a frog moving through an undirected tree. A tree is a connected graph with no cycles, which means

leetcodehardtreedepth-first-searchbreadth-first-searchgraph-theory