brain

tamnd's digital brain — notes, problems, research

43815 notes

CF 124B - Permutations

We are given several strings of digits, all with the same length. We may choose one permutation of digit positions and apply it to every string. After rearranging the digits according to that shared permutation, each string becomes a new integer, possibly with leading zeroes.

codeforcescompetitive-programmingbrute-forcecombinatoricsimplementation
CF 31D - Chocolate

We are given a rectangular chocolate bar with integer width _W_ and height _H_. Bob breaks the chocolate multiple times along vertical or horizontal lines that go from one edge to the opposite edge of a piece.

codeforcescompetitive-programmingdfs-and-similarimplementation
CF 34D - Road Map

We are given a tree with n cities. Originally, city r1 is considered the capital, and for every other city we know its parent in the rooted tree. The value p[i] means that if we walk from the old capital toward city i, the last city before reaching i is p[i].

codeforcescompetitive-programmingdfs-and-similargraphs
LeetCode 1130 - Minimum Cost Tree From Leaf Values

The problem asks us to construct a binary tree from an input array arr of positive integers, where each integer represents a leaf node in an in-order traversal.

leetcodemediumarraydynamic-programmingstackgreedymonotonic-stack
LeetCode 150 - Evaluate Reverse Polish Notation

This problem asks us to evaluate an arithmetic expression written in Reverse Polish Notation, also called postfix notation. Instead of placing operators between operands as in standard infix notation, Reverse Polish Notation places operators after their operands.

leetcodemediumarraymathstack
LeetCode 1244 - Design A Leaderboard

This problem asks us to design a leaderboard system that supports three operations efficiently. Each player has a unique playerId and an associated score. The leaderboard begins empty, and players can be added dynamically as operations are performed.

leetcodemediumhash-tabledesignsorting
LeetCode 286 - Walls and Gates

The problem gives us a 2D grid called rooms, where each cell represents one of three possible states. A value of -1 represents a wall or obstacle that cannot be passed through. A value of 0 represents a gate.

leetcodemediumarraybreadth-first-searchmatrix
LeetCode 1660 - Correct a Binary Tree

Here is a complete, detailed technical solution guide for LeetCode 1660 - Correct a Binary Tree, formatted exactly as re

leetcodemediumhash-tabletreedepth-first-searchbreadth-first-searchbinary-tree
LeetCode 1653 - Minimum Deletions to Make String Balanced

The problem asks us to make a string containing only characters 'a' and 'b' balanced by deleting the minimum number of characters. A string is considered balanced if there are no occurrences where a 'b' comes before an 'a' in the string.

leetcodemediumstringdynamic-programmingstack
LeetCode 1179 - Reformat Department Table

The problem is asking us to take a table Department that records revenue per department per month in a vertical format and convert it into a horizontal format, often called a "pivot" table. In the input, each row contains a department id, a revenue value, and a month.

leetcodeeasydatabase
LeetCode 613 - Shortest Distance in a Line

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.

leetcodeeasydatabase
LeetCode 1338 - Reduce Array Size to The Half

Here is a complete, detailed technical solution guide for LeetCode 1338, following your requested formatting and structu

leetcodemediumarrayhash-tablegreedysortingheap-(priority-queue)
CF 43D - Journey

We have an n × m grid. The king starts at the top-left cell (1,1) and must end there as well. Every other cell must be visited exactly once. Normal movement is allowed only between side-adjacent cells, but we may additionally install directed teleporters.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsimplementation
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 743 - Network Delay Time

This problem models a directed weighted graph. Each node represents a computer in the network, and each directed edge represents the time required for a signal to travel from one node to another.

leetcodemediumdepth-first-searchbreadth-first-searchgraph-theoryheap-(priority-queue)shortest-path
LeetCode 541 - Reverse String II

The problem requires us to manipulate a string s in a structured way. Specifically, we need to reverse the first k characters for every consecutive block of 2k characters in the string. If a block has fewer than k characters, we reverse all of them.

leetcodeeasytwo-pointersstring
LeetCode 1799 - Maximize Score After N Operations

The problem asks us to maximize the total score obtained by performing n operations on an array nums of size 2 n.

leetcodehardarraymathdynamic-programmingbacktrackingbit-manipulationnumber-theorybitmask
LeetCode 512 - Game Play Analysis II

The problem provides a database table named Activity. Each row represents one login session for a player on a specific date.

leetcodeeasydatabase
LeetCode 514 - Freedom Trail

The problem models a circular dial, represented by the string ring, where each character is engraved at a position around the circle. Another string, key, represents the sequence of characters we must spell.

leetcodehardstringdynamic-programmingdepth-first-searchbreadth-first-search
LeetCode 761 - Special Binary String

The problem asks us to manipulate a special binary string to produce the lexicographically largest possible string.

leetcodehardstringdivide-and-conquersorting
CF 9A - Die Roll

We are asked to calculate the probability that Dot wins a simple dice game against Yakko and Wakko. Each character rolls a standard six-sided die. Dot wins if her roll is at least as large as the maximum of Yakko’s and Wakko’s rolls.

codeforcescompetitive-programmingmathprobabilities
LeetCode 455 - Assign Cookies

This problem asks us to maximize the number of children who can be satisfied with the available cookies. Each child has a greed factor, and each cookie has a size. A child becomes content only if they receive a cookie whose size is greater than or equal to their greed factor.

leetcodeeasyarraytwo-pointersgreedysorting
CF 70C - Lucky Tickets

Each ticket is described by two positive integers. The first is the series number a, the second is the ticket number inside that series b.

codeforcescompetitive-programmingbinary-searchdata-structuressortingstwo-pointers
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 34 - Find First and Last Position of Element in Sorted Array

The problem gives us a sorted integer array nums and a target value target. Our goal is to find the first position where the target appears and the last position where the target appears.

leetcodemediumarraybinary-search
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 1008 - Construct Binary Search Tree from Preorder Traversal

Let's dive deep and construct a thorough technical guide for LeetCode 1008, following your formatting rules. The problem asks us to construct a binary search tree (BST) from a given preorder traversal array.

leetcodemediumarraystacktreebinary-search-treemonotonic-stackbinary-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
CF 66B - Petya and Countryside

We have a garden represented as a one-dimensional array of sections, each with a fixed height. Petya can create artificial rain above exactly one section, and water will flow to neighboring sections as long as their height is less than or equal to the section the water comes…

codeforcescompetitive-programmingbrute-forceimplementation
LeetCode 791 - Custom Sort String

The problem gives us two strings, order and s. The string order defines a custom character ordering. Unlike normal alphabetical ordering, the characters in order specify exactly how characters should be prioritized relative to one another.

leetcodemediumhash-tablestringsorting
LeetCode 954 - Array of Doubled Pairs

The problem asks whether it is possible to reorder an even-length array arr of integers such that every element can be paired with another element that is exactly double its value.

leetcodemediumarrayhash-tablegreedysorting
LeetCode 1536 - Minimum Swaps to Arrange a Binary Grid

The problem gives us an n x n binary matrix called grid. Each cell contains either 0 or 1. We are allowed to perform operations where we swap two adjacent rows. The goal is to transform the matrix into a valid configuration using the minimum number of adjacent row swaps.

leetcodemediumarraygreedymatrix
CF 85A - Domino

We need to tile a 4 × n board using ordinary dominoes. Each domino covers exactly two neighboring cells, either horizontally or vertically. The tiling must satisfy an extra condition.

codeforcescompetitive-programmingconstructive-algorithmsimplementation
CF 11D - A Simple Task

We are asked to count the number of simple cycles in an undirected graph. A simple cycle is a closed loop where no vertex or edge is repeated.

codeforcescompetitive-programmingbitmasksdpgraphs
LeetCode 366 - Find Leaves of Binary Tree

The problem asks us to repeatedly remove all leaf nodes from a binary tree and record the values removed during each round. A leaf node is a node with no left or right child.

leetcodemediumtreedepth-first-searchbinary-tree
LeetCode 1344 - Angle Between Hands of a Clock

This problem asks us to compute the smaller angle formed between the hour hand and the minute hand on a standard 12-hour

leetcodemediummath
LeetCode 1525 - Number of Good Ways to Split a String

The problem asks us to count how many ways we can split a string into two non-empty parts such that both parts contain the same number of distinct characters. A split occurs between two adjacent characters.

leetcodemediumhash-tablestringdynamic-programmingbit-manipulation
CF 54A - Presents

We are asked to estimate the minimum number of presents the Hedgehog will receive over the next N days. He has two rules governing present reception: every holiday he receives a gift, and he cannot go more than K days without receiving one.

codeforcescompetitive-programmingimplementation
LeetCode 661 - Image Smoother

The problem is asking us to implement an image smoother, a filter that modifies each cell in a 2D grayscale image based on the average of itself and its surrounding cells in a 3 x 3 window.

leetcodeeasyarraymatrix
LeetCode 1009 - Complement of Base 10 Integer

This problem asks us to compute the complement of a base-10 integer by flipping every bit in its binary representation. For instance, if the input n is 5, its binary form is 101. Flipping each 0 to 1 and each 1 to 0 produces 010, which equals 2 in decimal.

leetcodeeasybit-manipulation
CF 74E - Shift It!

We have a 6 × 6 board containing the characters 0-9 and A-Z, each appearing exactly once. The target configuration is fixed: characters must appear in row-major order. The only allowed moves are cyclic shifts of complete rows or complete columns.

codeforcescompetitive-programmingconstructive-algorithms
LeetCode 418 - Sentence Screen Fitting

The problem gives us a screen with a fixed number of rows and cols, along with a sentence represented as an array of words. We need to determine how many complete times the sentence can be written on the screen while following strict formatting rules.

leetcodemediumarraystringdynamic-programming
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 169 - Majority Element

The problem asks us to identify the majority element in a given array of integers nums. The majority element is defined as the number that appears more than half of the times in the array, i.e., more than ⌊n / 2⌋ times where n is the length of the array.

leetcodeeasyarrayhash-tabledivide-and-conquersortingcounting
LeetCode 364 - Nested List Weight Sum II

The problem gives us a nested list structure where each element can either be: - A single integer - Another nested list containing additional integers or lists The goal is to compute a weighted sum of all integers, but unlike the standard "Nested List Weight Sum" problem, the…

leetcodemediumstackdepth-first-searchbreadth-first-search
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 200 - Number of Islands

The problem gives us a two dimensional grid where each cell contains either '1' or '0'. A cell containing '1' represents land, while a cell containing '0' represents water. An island is defined as a group of connected land cells.

leetcodemediumarraydepth-first-searchbreadth-first-searchunion-findmatrix
CF 20A - BerOS file system

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.

codeforcescompetitive-programmingimplementation
LeetCode 934 - Shortest Bridge

The problem gives us an n x n binary matrix called grid. Each cell contains either 1 or 0. A value of 1 represents land, and a value of 0 represents water. Land cells that are connected vertically or horizontally form an island.

leetcodemediumarraydepth-first-searchbreadth-first-searchmatrix
LeetCode 1223 - Dice Roll Simulation

The problem asks us to calculate the total number of valid sequences generated by rolling a six-sided die n times, with the added constraint that each face i cannot appear more than rollMax[i] consecutive times.

leetcodehardarraydynamic-programming
LeetCode 144 - Binary Tree Preorder Traversal

This problem asks us to return the preorder traversal of a binary tree. A binary tree consists of nodes where each node may have a left child and a right child. The input root represents the root node of that tree.

leetcodeeasystacktreedepth-first-searchbinary-tree
LeetCode 1475 - Final Prices With a Special Discount in a Shop

The problem presents a scenario where you are buying items in a shop, each with a given price stored in an array prices.

leetcodeeasyarraystackmonotonic-stack
LeetCode 1049 - Last Stone Weight II

The problem is essentially about simulating the process of repeatedly smashing stones together until at most one stone remains. Each stone has a positive integer weight.

leetcodemediumarraydynamic-programming
LeetCode 1783 - Grand Slam Titles

This problem asks us to compute how many Grand Slam tennis titles each player has won across all years recorded in the database. We are given two tables: The Players table contains information about tennis players.

leetcodemediumdatabase
CF 115B - Lawnmower

We are given a rectangular garden represented as an n×m grid. Each cell contains either grass, which does not require mowing, or weeds, which do. We start at the top-left corner of the garden, always on grass, and initially facing right.

codeforcescompetitive-programminggreedysortings
LeetCode 1535 - Find the Winner of an Array Game

The problem describes a competitive game played on an array of distinct integers. At every round, only the first two ele

leetcodemediumarraysimulation
CF 58B - Coins

We are given the value of the largest coin denomination, n. We must build a sequence of distinct coin values such that every larger coin is divisible by every smaller coin. Among all valid sequences, we want the one containing the maximum possible number of coins.

codeforcescompetitive-programminggreedy
LeetCode 1737 - Change Minimum Characters to Satisfy One of Three Conditions

The problem gives us two lowercase English strings, a and b. In a single operation, we may change any character in either string into any other lowercase English letter.

leetcodemediumhash-tablestringcountingprefix-sum
CF 9E - Interestring graph and Apples

We start with an undirected multigraph. Multiple edges are allowed, and loops are also allowed. We may add new edges, and the goal is to transform the graph into a very specific structure.

codeforcescompetitive-programmingdfs-and-similardsugraphs
LeetCode 995 - Minimum Number of K Consecutive Bit Flips

The problem gives us a binary array nums consisting of 0s and 1s and an integer k. The task is to transform the array so that all elements are 1s using the minimum number of operations called k-bit flips.

leetcodehardarraybit-manipulationqueuesliding-windowprefix-sum
CF 108B - Datatypes

We are given several unsigned integer datatypes, each defined by its bit length. A datatype with a bits can store every integer from 0 up to 2^a - 1. We want to know whether there exists some integer x and two datatypes with sizes a[i] < a[j] such that: 1.

codeforcescompetitive-programmingmathsortings
LeetCode 822 - Card Flipping Game

In this problem, we are given a collection of cards where each card has two numbers, one on the front and one on the back. Initially, every card is placed with its front side facing upward.

leetcodemediumarrayhash-table
LeetCode 1003 - Check If Word Is Valid After Substitutions

The problem asks us to determine whether a given string can be constructed by repeatedly inserting the substring "abc" into an initially empty string. The operation is very specific. At any point, we may take the current string and insert "abc" at any position.

leetcodemediumstringstack
CF 59D - Team Arrangement

We have 3n students ranked by personal performance. Higher-ranked students become captains earlier. When a captain forms a team, they choose two currently unassigned students according to their personal preference list.

codeforcescompetitive-programmingconstructive-algorithmsgreedyimplementation
CF 63B - Settlers' Training

We have a group of soldiers, each with a rank between 1 and k. During one training session, soldiers are grouped by equal rank. From every group whose rank is still below k, exactly one soldier is promoted by one level.

codeforcescompetitive-programmingimplementation
CF 131F - Present to Mom

We are given a black-and-white photo represented as a grid of size n × m where each cell is either '1' for a white pixel or '0' for a black pixel.

codeforcescompetitive-programmingbinary-searchtwo-pointers
LeetCode 1477 - Find Two Non-overlapping Sub-arrays Each With Target Sum

The problem asks us to find two different subarrays inside the given array such that: 1. Each subarray has a sum exactly

leetcodemediumarrayhash-tablebinary-searchdynamic-programmingsliding-window
LeetCode 529 - Minesweeper

This problem asks us to simulate one move in the classic Minesweeper game. We are given a two dimensional grid representing the current game board, along with the coordinates of a user click. Our task is to update the board according to the rules of Minesweeper.

leetcodemediumarraydepth-first-searchbreadth-first-searchmatrix
LeetCode 27 - Remove Element

The problem gives us an integer array nums and a target value val. Our task is to remove every occurrence of val from the array, but we must do it in-place. This means we are not supposed to create another array and return it. Instead, we modify the original array directly.

leetcodeeasyarraytwo-pointers
CF 76D - Plus and xor

We are given two non-negative integers, A and B. We need to construct two other non-negative integers, X and Y, such that: - their sum equals A - their bitwise xor equals B Among all valid pairs, we must output the one with the smallest possible X.

codeforcescompetitive-programmingdpgreedymath
LeetCode 841 - Keys and Rooms

This problem can be interpreted as a graph traversal challenge. Each room is a node in a graph labeled from 0 to n-1, and the keys inside a room represent directed edges to other nodes that can be unlocked.

leetcodemediumdepth-first-searchbreadth-first-searchgraph-theory
LeetCode 1821 - Find Customers With Positive Revenue this Year

The problem gives us a database table named Customers with three columns: | Column | Meaning | | --- | --- | | customerid | Unique identifier for a customer | | year | The year associated with the revenue | | revenue | Revenue value for that customer in that year | The…

leetcodeeasydatabase
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 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
CF 93B - End of Exams

We are asked to distribute milk from a set of bottles into cups such that each bottle contributes to at most two cups, and all cups end up with the same total volume. Specifically, we have n bottles, each containing w units of milk, and m friends who each receive one cup.

codeforcescompetitive-programminggreedy
CF 95D - Horse Races

We are given several intervals of integers. For every interval $[l, r]$, we must count how many numbers contain two lucky digits, either 4 or 7, whose positions differ by at most k. Positions are counted inside the decimal representation of the number.

codeforcescompetitive-programmingdpmath
LeetCode 1662 - Check If Two String Arrays are Equivalent

The problem gives us two arrays of strings, word1 and word2. Each array represents a single larger string formed by conc

leetcodeeasyarraystring
CF 40D - Interesting Sequence

The sequence starts with two fixed values:

codeforcescompetitive-programmingmath
LeetCode 1222 - Queens That Can Attack the King

In this problem, we are given the positions of several black queens and exactly one white king on a standard 8 x 8 chessboard. The board uses 0-indexed coordinates, meaning every position is represented as [row, column], where both values range from 0 to 7.

leetcodemediumarraymatrixsimulation
CF 61E - Enemy is weak

We are given an array of distinct integers representing the power of soldiers standing in a line. We need to count how many index triples (i, j, k) satisfy two conditions at the same time: - The positions are ordered as i < j < k - The values are strictly decreasing as a[i]…

codeforcescompetitive-programmingdata-structurestrees
LeetCode 823 - Binary Trees With Factors

The problem asks us to determine the number of distinct binary trees that can be constructed from a given array of unique integers, where each integer is strictly greater than 1.

leetcodemediumarrayhash-tabledynamic-programmingsorting
LeetCode 139 - Word Break

The problem asks us to determine whether a given string s can be broken into a sequence of valid words from a given dictionary wordDict. Essentially, we need to check if we can insert spaces into s such that every substring separated by these spaces exists in the dictionary.

leetcodemediumarrayhash-tablestringdynamic-programmingtriememoization
CF 72I - Goofy Numbers

We are asked to classify a single non-negative integer based on how it relates to its digits. Specifically, each digit of the number is considered as a potential divisor.

codeforcescompetitive-programming*specialimplementation
LeetCode 955 - Delete Columns to Make Sorted II

This problem asks us to remove the minimum number of columns from a list of equal length strings so that the resulting array of strings becomes lexicographically sorted.

leetcodemediumarraystringgreedy
LeetCode 1067 - Digit Count in Range

This problem asks us to count how many times a given digit d appears in every integer within a range [low, high]. For instance, if d = 1 and the range is [1, 13], we count all occurrences of the digit 1 in the numbers 1 through 13.

leetcodehardmathdynamic-programming
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 1550 - Three Consecutive Odds

This problem asks us to examine a list of integers, arr, and determine whether there exists a sequence of three consecut

leetcodeeasyarray
LeetCode 1325 - Delete Leaves With a Given Value

This problem asks us to repeatedly remove leaf nodes from a binary tree if their value matches a given target. A leaf no

leetcodemediumtreedepth-first-searchbinary-tree
LeetCode 1689 - Partitioning Into Minimum Number Of Deci-Binary Numbers

The problem asks us to determine the minimum number of positive deci-binary numbers required to sum up to a given decima

leetcodemediumstringgreedy
LeetCode 459 - Repeated Substring Pattern

The problem asks us to determine whether a given string can be formed by repeating one of its substrings multiple times. In other words, we want to know if there exists some substring pattern such that concatenating that pattern repeatedly recreates the entire string exactly.

leetcodeeasystringstring-matching
CF 17B - Hierarchy

We have employees and directed supervisor offers between them. An offer (a, b, c) means employee a is willing to supervise employee b for cost c. Qualifications are strictly decreasing along every offer, so q[a] > q[b].

codeforcescompetitive-programmingdfs-and-similardsugreedyshortest-paths
LeetCode 491 - Non-decreasing Subsequences

The problem gives us an integer array nums and asks us to return every distinct subsequence that is non-decreasing and has length at least two. A subsequence is formed by deleting zero or more elements from the array without changing the relative order of the remaining elements.

leetcodemediumarrayhash-tablebacktrackingbit-manipulation
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
CF 19E - Fairy

We are given an undirected graph. Each edge represents a segment drawn between two points. We may erase exactly one edge, and after removing it we want the remaining graph to become bipartite.

codeforcescompetitive-programmingdfs-and-similardivide-and-conquerdsu
LeetCode 1171 - Remove Zero Sum Consecutive Nodes from Linked List

The problem requires us to repeatedly remove consecutive nodes in a singly-linked list whose values sum to zero. The input is the head of a singly-linked list, where each node has an integer value in the range -1000 to 1000, and the list length ranges from 1 to 1000 nodes.

leetcodemediumhash-tablelinked-list
LeetCode 333 - Largest BST Subtree

The problem gives us the root of an arbitrary binary tree and asks us to find the size of the largest subtree that is also a valid Binary Search Tree, abbreviated as BST. A subtree is any node together with all of its descendants. This means we cannot selectively ignore children.

leetcodemediumdynamic-programmingtreedepth-first-searchbinary-search-treebinary-tree
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 1120 - Maximum Average Subtree

This problem asks us to find the maximum average value among all subtrees of a given binary tree. A subtree is defined as any node along with all of its descendants. The average of a subtree is the sum of its node values divided by the number of nodes in that subtree.

leetcodemediumtreedepth-first-searchbinary-tree
LeetCode 348 - Design Tic-Tac-Toe

The problem asks us to design a data structure that simulates an n x n Tic-Tac-Toe game between two players. We need to implement a class that supports two operations: - Initializing a game board of size n - Processing moves one at a time and immediately determining whether…

leetcodemediumarrayhash-tabledesignmatrixsimulation
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