brain

tamnd's digital brain — notes, problems, research

42715 notes

LeetCode 1600 - Throne Inheritance

The problem asks us to design a data structure that simulates a royal inheritance system. There is a king at the top of the family tree, and over time people can be born or die. We must support three operations efficiently: 1. Add a child to an existing person. 2.

leetcodemediumhash-tabletreedepth-first-searchdesign
LeetCode 974 - Subarray Sums Divisible by K

The problem asks us to count how many non-empty contiguous subarrays have a sum that is divisible by a given integer k. A subarray is any continuous segment of the array. For example, in the array [1,2,3], the subarrays include [1], [2], [3], [1,2], [2,3], and [1,2,3].

leetcodemediumarrayhash-tableprefix-sum
CF 16C - Monitor

We start with a monitor whose dimensions are a × b. Both values are integers. We want to shrink this monitor so that the new dimensions keep the exact aspect ratio x : y.

codeforcescompetitive-programmingbinary-searchnumber-theory
LeetCode 1528 - Shuffle String

The problem asks us to take a string s and an integer array indices of the same length, and produce a new string where e

leetcodeeasyarraystring
LeetCode 2005 - Subtree Removal Game with Fibonacci Tree

The problem defines a special kind of binary tree called a Fibonacci tree. The structure is recursive: - order(0) is an empty tree. - order(1) is a single node. - order(n) has: - a root node, - a left subtree equal to order(n - 2), - a right subtree equal to order(n - 1).

leetcodehardmathdynamic-programmingtreebinary-treegame-theory
LeetCode 530 - Minimum Absolute Difference in BST

This problem gives us the root node of a Binary Search Tree, abbreviated as BST, and asks us to find the minimum absolute difference between the values of any two distinct nodes in the tree.

leetcodeeasytreedepth-first-searchbreadth-first-searchbinary-search-treebinary-tree
CF 120E - Put Knight!

We are asked to analyze a two-player game on an n × n chessboard. Petya and Gena take turns placing knights such that no knight can threaten another. A knight threatens positions in its standard L-shaped moves.

codeforcescompetitive-programminggamesmath
LeetCode 1297 - Maximum Number of Occurrences of a Substring

Please provide the missing problem number or title you want the guide for. Your prompt contains the formatting/template

leetcodemediumhash-tablestringsliding-window
LeetCode 1735 - Count Ways to Make Array With Product

The problem asks us to count the number of ways to fill an array of size ni with positive integers such that the product of all elements equals ki. Each query in the input array queries is independent, meaning we compute the answer for each (ni, ki) pair separately.

leetcodehardarraymathdynamic-programmingcombinatoricsnumber-theory
LeetCode 1132 - Reported Posts II

The problem asks us to calculate the average daily percentage of posts that were removed after being reported as spam. We are given two tables: Actions and Removals.

leetcodemediumdatabase
CF 80A - Panoramix's Prediction

Yesterday the Gauls defeated n Roman soldiers, and n is guaranteed to be a prime number. Today they defeated m soldiers, where m n. We need to decide whether m is exactly the next prime number that comes immediately after n. The key detail is the phrase "next prime".

codeforcescompetitive-programmingbrute-force
LeetCode 1072 - Flip Columns For Maximum Number of Equal Rows

The problem gives us an m x n binary matrix, where every element is either 0 or 1. We are allowed to choose any set of columns and flip them. Flipping a column means changing every 0 in that column to 1, and every 1 to 0.

leetcodemediumarrayhash-tablematrix
LeetCode 595 - Big Countries

This problem asks us to query a database table named World and return a subset of countries that qualify as big countries.

leetcodeeasydatabase
LeetCode 1723 - Find Minimum Time to Finish All Jobs

This problem is asking us to assign a set of jobs, each with a specific time requirement, to k workers such that every job is assigned to exactly one worker, and we minimize the maximum total working time among all workers.

leetcodehardarraydynamic-programmingbacktrackingbit-manipulationbitmask
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
LeetCode 592 - Fraction Addition and Subtraction

The problem requires computing the result of a mathematical expression containing fractions with addition and subtraction operators. The input is a single string, expression, which consists of positive or negative fractions in the format numerator/denominator.

leetcodemediummathstringsimulation
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
CF 64A - Factorial

We are asked to compute the factorial of a given integer $n$. Factorial is the product of all positive integers up to $n$, so for $n = 3$, the factorial is $1 times 2 times 3 = 6$. The input is a single integer, and the output is the single integer result of this product.

codeforcescompetitive-programming*specialimplementation
CF 18C - Stripe

We have a strip of cells, and each cell contains an integer. We may cut the strip only between adjacent cells, which splits the array into a left part and a right part. The task is to count how many cut positions produce two non-empty parts with equal sums.

codeforcescompetitive-programmingdata-structuresimplementation
LeetCode 172 - Factorial Trailing Zeroes

The problem asks us to determine how many trailing zeroes appear at the end of n!, where n! represents the factorial of n. A factorial is defined as: For example: - 5!

leetcodemediummath
LeetCode 1308 - Running Total for Different Genders

The problem is asking us to compute cumulative scores for each gender across different days in a competition. The input

leetcodemediumdatabase
CF 121B - Lucky Transformation

We are given a decimal string and an operation count k. Each operation looks for the leftmost occurrence of the substring "47". Suppose the substring "47" starts at position x using 1-based indexing. If x is odd, we replace both digits with '4', so "47" becomes "44".

codeforcescompetitive-programmingstrings
CF 22E - Scheme

Each person points to exactly one other person. If someone learns the news, they call the person they point to, who then calls the next person, and so on. We may add extra directed edges of the form x -> y, meaning person x must also call y.

codeforcescompetitive-programmingdfs-and-similargraphstrees
LeetCode 1632 - Rank Transform of a Matrix

The problem asks us to assign a rank to every element in a matrix while preserving ordering relationships inside rows and columns. For any two elements that share the same row or the same column: - If one value is smaller, its rank must also be smaller.

leetcodehardarrayunion-findgraph-theorytopological-sortsortingmatrix
CF 91E - Igloo Skyscraper

Each walrus builds a skyscraper whose height changes linearly over time. Walrus i starts with height a[i] and gains b[i] floors every minute, so at time t its height equals: $$hi(t) = ai + bi cdot t$$ For every query [l, r, t], we must find an index inside that interval whose…

codeforcescompetitive-programmingdata-structuresgeometry
CF 128C - Games with Rectangle

We start with a rectangle drawn on grid paper. Only the border matters, not the interior. Players repeatedly draw a strictly smaller rectangle inside the previous one.

codeforcescompetitive-programmingcombinatoricsdp
LeetCode 427 - Construct Quad Tree

The problem asks us to convert a binary matrix into a Quad-Tree representation. A Quad-Tree is a recursive tree structure where every internal node has exactly four children, each representing one quadrant of the current square region.

leetcodemediumarraydivide-and-conquertreematrix
LeetCode 1332 - Remove Palindromic Subsequences

The problem gives us a string s that contains only the characters 'a' and 'b'. In one operation, we are allowed to remov

leetcodeeasytwo-pointersstring
LeetCode 1788 - Maximize the Beauty of the Garden

We are given an integer array flowers, where each element represents the beauty value of a flower in a line. We may remove any flowers we want, while preserving the relative order of the remaining flowers. After removals, the remaining sequence must form a valid garden.

leetcodehardarrayhash-tablegreedyprefix-sum
LeetCode 1780 - Check if Number is a Sum of Powers of Three

The problem asks whether a given integer n can be expressed as the sum of distinct powers of three. A power of three is any number of the form: where x is a non-negative integer. That means the valid powers are: - 3^0 = 1 - 3^1 = 3 - 3^2 = 9 - 3^3 = 27 - and so on.

leetcodemediummath
CF 77A - Heroes

We have exactly seven heroes and three bosses. Each boss gives some amount of experience, and every hero assigned to that boss receives an equal share rounded down. If a boss gives x experience and its team has k heroes, then every hero in that team receives x // k.

codeforcescompetitive-programmingbrute-forceimplementation
LeetCode 824 - Goat Latin

This problem asks us to transform a given sentence into a fictional language called Goat Latin, following a specific set of string manipulation rules. The input is a string called sentence, where words are separated by a single space.

leetcodeeasystring
LeetCode 2308 - Arrange Table by Gender

The problem asks us to rearrange the rows of a Genders table in a specific repeating order while maintaining internal so

leetcodemediumdatabase
CF 76E - Points

We are given up to one hundred thousand points on a 2D plane. For every unordered pair of points, we must compute the squared Euclidean distance between them and add all those values together.

codeforcescompetitive-programmingimplementationmath
LeetCode 106 - Construct Binary Tree from Inorder and Postorder Traversal

The problem provides two traversal orders of the same binary tree: - inorder, which follows the order: left subtree, root, right subtree - postorder, which follows the order: left subtree, right subtree, root We must reconstruct the original binary tree and return its root node.

leetcodemediumarrayhash-tabledivide-and-conquertreebinary-tree
CF 43C - Lucky Tickets

We are given a collection of ticket pieces. Each piece is a number, representing the fragment of a ticket that was originally divisible by three. The problem asks us to reconstruct the maximum number of lucky tickets we can from these pieces.

codeforcescompetitive-programminggreedy
LeetCode 91 - Decode Ways

This problem asks us to determine how many different valid ways a numeric string can be decoded into letters using the mapping: - "1" → 'A' - "2" → 'B' - ... - "26" → 'Z' The input is a string s containing only digits.

leetcodemediumstringdynamic-programming
CF 14A - Letter

We are given a rectangular grid representing a sheet of graph paper with _n_ rows and _m_ columns. Some of the squares are shaded, marked by *, and the rest are unshaded, marked by ..

codeforcescompetitive-programmingimplementation
LeetCode 1494 - Parallel Courses II

The problem asks us to determine the minimum number of semesters required to complete n courses when there are prerequis

leetcodeharddynamic-programmingbit-manipulationgraph-theorybitmask
LeetCode 295 - Find Median from Data Stream

The problem asks us to design a data structure that continuously receives integers from a stream and can efficiently return the median of all numbers seen so far. The median is defined as the middle element in a sorted list.

leetcodehardtwo-pointersdesignsortingheap-(priority-queue)data-stream
LeetCode 1006 - Clumsy Factorial

The problem asks us to compute a clumsy factorial for a given positive integer n. A standard factorial multiplies all integers from n down to 1, but the clumsy factorial modifies the operations: instead of multiplying all numbers, it cycles through '', '/', '+', and '-' in…

leetcodemediummathstacksimulation
CF 67B - Restoration of the Permutation

We are given a permutation A of numbers from 1 to n. For every value i, we know a number b[i]. This number describes how many elements appear before i in the permutation and are at least i + k. The condition is attached to the value itself, not to the position.

codeforcescompetitive-programminggreedy
CF 131B - Opposites Attract

We are asked to count all pairs of clients whose assigned numbers are exact opposites. Each client has a number between -10 and 10, and a pair is valid if one client has number $x$ and the other has number $-x$.

codeforcescompetitive-programmingimplementationmath
LeetCode 1062 - Longest Repeating Substring

The problem asks us to find the length of the longest substring that appears at least twice in a given string s. A substring is a contiguous sequence of characters inside a string. The repeated substrings may overlap with each other, which is an important detail.

leetcodemediumstringbinary-searchdynamic-programmingrolling-hashsuffix-arrayhash-function
LeetCode 1115 - Print FooBar Alternately

This problem is a classic concurrency synchronization task. We are given a class FooBar with two methods, foo() and bar().

leetcodemediumconcurrency
LeetCode 1364 - Number of Trusted Contacts of a Customer

This problem asks us to analyze relationships between customers, their contacts, and invoices. We are given three tables: Customers, Contacts, and Invoices. The Customers table identifies each customer by customerid along with their name and email.

leetcodemediumdatabase
LeetCode 1333 - Filter Restaurants by Vegan-Friendly, Price and Distance

The problem is asking us to filter and sort a list of restaurants based on multiple criteria. Each restaurant is represe

leetcodemediumarraysorting
LeetCode 266 - Palindrome Permutation

The problem asks whether the characters of a given string can be rearranged to form a palindrome. A palindrome is a string that reads the same forward and backward. Examples include "racecar", "abba", and "a".

leetcodeeasyhash-tablestringbit-manipulation
LeetCode 1534 - Count Good Triplets

The problem asks us to count the number of good triplets in an integer array arr based on three difference constraints a, b, and c.

leetcodeeasyarrayenumeration
LeetCode 511 - Game Play Analysis I

This problem asks us to determine the first day each player logged into a game based on a table called Activity. Each row of this table contains a playerid, the deviceid used, the eventdate on which the player logged in, and the number of gamesplayed during that session.

leetcodeeasydatabase
CF 29A - Spit Problem

Each camel stands at a unique coordinate on a number line. A camel at position x spits exactly toward position x + d. If another camel stands there, it gets hit. We need to determine whether there exists a pair of camels such that each one hits the other.

codeforcescompetitive-programmingbrute-force
LeetCode 797 - All Paths From Source to Target

The problem gives us a directed acyclic graph, usually abbreviated as a DAG. The graph contains n nodes labeled from 0 to n - 1. The graph is represented as an adjacency list, where graph[i] contains all nodes that can be reached directly from node i.

leetcodemediumbacktrackingdepth-first-searchbreadth-first-searchgraph-theory
LeetCode 896 - Monotonic Array

This problem asks us to determine whether a given array of integers is monotonic. An array is considered monotonic if it is entirely non-decreasing (monotone increasing) or entirely non-increasing (monotone decreasing).

leetcodeeasyarray
LeetCode 1462 - Course Schedule IV

This problem gives us a directed acyclic graph representing course dependencies. Each course is a node, and a prerequisi

leetcodemediumdepth-first-searchbreadth-first-searchgraph-theorytopological-sort
LeetCode 1381 - Design a Stack With Increment Operation

This problem requires designing a specialized stack data structure, called CustomStack, that not only supports the usual

leetcodemediumarraystackdesign
LeetCode 92 - Reverse Linked List II

This problem asks us to reverse only a specific portion of a singly linked list, rather than reversing the entire list. We are given the head of a linked list and two integer positions, left and right, where left <= right.

leetcodemediumlinked-list
LeetCode 1113 - Reported Posts

The problem is asking us to determine the number of posts that were reported yesterday grouped by the reason for the report.

leetcodeeasydatabase
CF 64B - Expression

The input is a tiny arithmetic expression written as a three-character string. The first and third characters are digits from 0 to 9, and the middle character is either + or -. The task is to evaluate the expression and print the resulting integer.

codeforcescompetitive-programming*specialexpression-parsing
LeetCode 1605 - Find Valid Matrix Given Row and Column Sums

The problem gives us two arrays: - rowSum, where rowSum[i] represents the total sum required for row i - colSum, where c

leetcodemediumarraygreedymatrix
LeetCode 443 - String Compression

The problem asks us to perform in place string compression on an array of characters. The input is not a string object, but a mutable array named chars, where each element is a single character. The compression rule is based on groups of consecutive repeated characters.

leetcodemediumtwo-pointersstring
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
LeetCode 1617 - Count Subtrees With Max Distance Between Cities

The input describes an undirected tree with n cities. Since the graph is a tree, there are exactly n - 1 edges and there is a unique simple path between every pair of cities. The problem asks us to examine every possible connected subset of cities.

leetcodeharddynamic-programmingbit-manipulationtreeenumerationbitmask
LeetCode 1086 - High Five

The problem asks us to compute the top five average score for each student given a list of [ID, score] pairs. Each ID represents a unique student, and score represents a single score they received.

leetcodeeasyarrayhash-tablesortingheap-(priority-queue)
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
LeetCode 146 - LRU Cache

The problem asks us to design an efficient cache that follows the Least Recently Used, or LRU, eviction policy. A cache stores a limited number of key-value pairs.

leetcodemediumhash-tablelinked-listdesigndoubly-linked-list
CF 63D - Dividing Island

We are asked to divide an island into connected territories for multiple parties. The island is represented by two rectangles placed side by side: one of size a by b and another of size c by d.

codeforcescompetitive-programmingconstructive-algorithms
LeetCode 482 - License Key Formatting

The problem gives us a string s that represents a license key. The string contains uppercase letters, lowercase letters, digits, and dashes. The existing dashes are only separators and do not necessarily represent the correct final grouping.

leetcodeeasystring
LeetCode 997 - Find the Town Judge

The problem describes a town containing n people labeled from 1 to n. Among these people, there may exist a special person called the town judge. The judge must satisfy two strict conditions: 1. The judge trusts nobody. 2. Every other person trusts the judge.

leetcodeeasyarrayhash-tablegraph-theory
CF 28A - Bender Problem

We are given a sequence of nails in the plane, each with integer coordinates, and a collection of straight rods. The nails define the vertices of a closed polyline that only moves along horizontal or vertical segments.

codeforcescompetitive-programmingimplementation
LeetCode 275 - H-Index II

This problem asks us to compute a researcher's h-index from a sorted list of citation counts. The input array citations is sorted in non-decreasing order, meaning the citation counts appear from smallest to largest.

leetcodemediumarraybinary-search
LeetCode 775 - Global and Local Inversions

The problem presents an array nums of length n that is a permutation of integers from 0 to n-1. A global inversion is defined as any pair (i, j) such that i < j and nums[i] nums[j], meaning the earlier element is larger than a later element anywhere in the array.

leetcodemediumarraymath
LeetCode 739 - Daily Temperatures

The problem gives an array called temperatures, where each element represents the temperature recorded on a specific day. For every day, we must determine how many days in the future we need to wait until a warmer temperature appears.

leetcodemediumarraystackmonotonic-stack
LeetCode 789 - Escape The Ghosts

This problem takes place on an infinite two dimensional grid. You begin at coordinate (0, 0) and want to reach a destination called target. At the same time, several ghosts also move on the grid from their own starting positions.

leetcodemediumarraymath
LeetCode 226 - Invert Binary Tree

The problem gives the root node of a binary tree and asks us to invert the tree. Inverting a binary tree means swapping the left and right child of every node in the tree.

leetcodeeasytreedepth-first-searchbreadth-first-searchbinary-tree
LeetCode 1102 - Path With Maximum Minimum Value

The problem asks us to find the maximum possible score of a path from the top-left corner (0, 0) to the bottom-right corner (m-1, n-1) of a 2D grid. Each cell in the grid contains an integer value, and the score of a path is defined as the minimum value along that path.

leetcodemediumarraybinary-searchdepth-first-searchbreadth-first-searchunion-findheap-(priority-queue)matrix
LeetCode 931 - Minimum Falling Path Sum

The problem asks for the minimum sum of any falling path through an n x n integer matrix. A falling path is defined as a sequence of elements starting from any element in the first row and moving row by row to the last row.

leetcodemediumarraydynamic-programmingmatrix
LeetCode 890 - Find and Replace Pattern

The problem gives us a list of words and a target pattern string. We need to determine which words follow the exact same structural character relationship as the pattern.

leetcodemediumarrayhash-tablestring
LeetCode 1543 - Fix Product Name Format

The problem asks us to clean and aggregate sales data from a Sales table. Each row contains a unique saleid, a productna

leetcodeeasydatabase
LeetCode 1263 - Minimum Moves to Move a Box to Their Target Location

The problem is a variant of the classic "Sokoban" puzzle. You are given a grid representing a warehouse, where a player

leetcodehardarraybreadth-first-searchheap-(priority-queue)matrix
LeetCode 1039 - Minimum Score Triangulation of Polygon

This problem asks us to triangulate a convex polygon in such a way that the total triangulation score is minimized. We are given an array values, where each element represents the value assigned to a vertex of the polygon.

leetcodemediumarraydynamic-programming
LeetCode 1017 - Convert to Base -2

This problem asks us to convert a non-negative integer n into its representation using base -2, instead of the usual positive bases such as base 2, base 10, or base 16. In standard binary representation, numbers are written as powers of 2. For example: which becomes "1101".

leetcodemediummath
LeetCode 717 - 1-bit and 2-bit Characters

In this problem, we are given a binary array called bits. The array represents a sequence of encoded characters using the following rules: - A one-bit character is represented by a single 0 - A two-bit character is represented by either 10 or 11 The array is guaranteed to end…

leetcodeeasyarray
LeetCode 936 - Stamping The Sequence

This problem asks us to reconstruct a target string by repeatedly applying a smaller string called stamp. We begin with a string s that has the same length as target, but every character is initially '?'.

leetcodehardstringstackgreedyqueue
CF 37B - Computer Game

The boss starts with max health and regenerates reg health every second. We own several scrolls. Each scroll can only be activated when the boss health is at most some percentage of the original health.

codeforcescompetitive-programminggreedyimplementation
LeetCode 1515 - Best Position for a Service Centre

The problem asks us to find the optimal location for a service center on a 2D map such that the total Euclidean distance

leetcodehardarraymathgeometryrandomized
LeetCode 507 - Perfect Number

This problem asks us to determine whether a given positive integer num is a perfect number. A perfect number is defined as a number whose sum of positive divisors, excluding the number itself, equals the number.

leetcodeeasymath
LeetCode 63 - Unique Paths II

This problem asks us to count how many different valid paths exist for a robot moving through a grid while avoiding obstacles. The robot starts in the top-left corner of the grid at position (0, 0) and wants to reach the bottom-right corner at position (m - 1, n - 1).

leetcodemediumarraydynamic-programmingmatrix
LeetCode 1031 - Maximum Sum of Two Non-Overlapping Subarrays

The problem gives us an integer array nums and two fixed subarray lengths, firstLen and secondLen. We must select exactly two contiguous subarrays such that: - One subarray has length firstLen - The other subarray has length secondLen - The two subarrays do not overlap - The…

leetcodemediumarraydynamic-programmingsliding-window
CF 29D - Ant on the Tree

We are asked to construct a path for an ant on a tree. The tree has n vertices, with vertex 1 as the root, and n-1 edges connecting them so the graph is connected.

codeforcescompetitive-programmingconstructive-algorithmsdfs-and-similartrees
LeetCode 186 - Reverse Words in a String II

The problem asks us to reverse the order of words in a character array s in-place. Each word is a contiguous sequence of non-space characters, and words are separated by exactly one space.

leetcodemediumtwo-pointersstring
CF 12A - Super Agent

We are asked to check whether a password entered on a 3×3 keypad is symmetric with respect to its central button. The keypad is represented as a 3×3 grid of characters, where "X" indicates a pressed button and "." indicates an unpressed one.

codeforcescompetitive-programmingimplementation
LeetCode 1317 - Convert Integer to the Sum of Two No-Zero Integers

The problem asks us to split a given integer n into two positive integers a and b such that: - a + b = n - Neither a nor b contains the digit 0 anywhere in their decimal representation Such integers are called No-Zero integers.

leetcodeeasymath
CF 73F - Plane of Tanks

We have a tank that wants to move from point A to point B along the straight segment connecting them. The tank moves with constant speed $v$, which we must choose as small as possible. There are $n$ enemy tanks placed on the plane.

codeforcescompetitive-programmingbrute-forcegeometry
LeetCode 619 - Biggest Single Number

The problem gives us a database table named MyNumbers that contains a single column, num. The table may contain duplicate values because there is no primary key restriction. Our task is to find the largest number that appears exactly once in the table.

leetcodeeasydatabase
LeetCode 1168 - Optimize Water Distribution in a Village

The problem asks us to supply water to all houses in a village in the most cost-effective way. Each house has two options: either build a well in the house with a fixed cost, or connect the house to another house via pipes, where each pipe has its own construction cost.

leetcodehardunion-findgraph-theoryheap-(priority-queue)minimum-spanning-tree
CF 42B - Game of chess unfinished

We are given a chess position containing exactly four pieces on a standard 8×8 board. White has two rooks and one king, black has only a king. The position is already legal, meaning no two pieces share a square and the two kings are not adjacent.

codeforcescompetitive-programmingimplementation
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 943 - Find the Shortest Superstring

The problem asks us to find the shortest superstring that contains all the given strings in the array words as substrings.

leetcodehardarraystringdynamic-programmingbit-manipulationbitmask
LeetCode 2012 - Sum of Beauty in the Array

The problem asks us to compute a "beauty" score for each element in an array nums, excluding the first and last elements. Specifically, for each index i in the range 1 <= i <= nums.length - 2, the beauty of nums[i] is determined by two conditions: 1.

leetcodemediumarray
CF 130J - Date calculation

We are given a year in the Gregorian calendar and a day number inside that year. The task is to determine the actual calendar date corresponding to that day number.

codeforcescompetitive-programming*special