brain

tamnd's digital brain — notes, problems, research

43815 notes

CF 67E - Save the City!

We are given a simple polygon listed in clockwise order. The first two vertices form a horizontal edge AB, and every other vertex lies strictly on the same side of that edge. Along the segment AB, every integer-coordinate point is a possible location for a watchtower.

codeforcescompetitive-programminggeometry
LeetCode 1703 - Minimum Adjacent Swaps for K Consecutive Ones

This problem asks us to determine the minimum number of adjacent swaps needed to make exactly k ones appear consecutively in a binary array. The input array nums contains only 0 and 1. In one operation, we may swap two neighboring elements.

leetcodehardarraygreedysliding-windowprefix-sum
LeetCode 480 - Sliding Window Median

The problem asks us to compute the median for every contiguous subarray, or "window", of size k as that window slides from left to right across the input array. For each position of the window, we consider exactly k elements.

leetcodehardarrayhash-tablesliding-windowheap-(priority-queue)
LeetCode 1118 - Number of Days in a Month

The problem asks us to determine the number of days in a specific month of a given year. The inputs are two integers: year, which ranges from 1583 to 2100, and month, which ranges from 1 (January) to 12 (December).

leetcodeeasymath
LeetCode 620 - Not Boring Movies

The problem is asking us to query a database table called Cinema and return a filtered set of movies based on two conditions: the movie ID must be odd, and its description must not be "boring". The result must then be sorted in descending order by the movie's rating.

leetcodeeasydatabase
CF 119C - Education Reform

We have up to 50 subjects. Each subject has three properties. The interval $[ai, bi]$ describes how many homework exercises this subject may assign. We are free to choose any value inside that interval. The value $ci$ is the subject complexity.

codeforcescompetitive-programmingdp
LeetCode 381 - Insert Delete GetRandom O(1) - Duplicates allowed

The problem asks us to design a data structure called RandomizedCollection that behaves like a multiset. Unlike a normal set, duplicate values are allowed.

leetcodehardarrayhash-tablemathdesignrandomized
LeetCode 1316 - Distinct Echo Substrings

The problem asks us to find the number of distinct non-empty substrings of a given string text that can be expressed as

leetcodehardstringtrierolling-hashhash-function
LeetCode 111 - Minimum Depth of Binary Tree

The problem asks us to determine the minimum depth of a binary tree. In other words, given the root of a binary tree, we want to find the shortest path from the root node down to the nearest leaf node.

leetcodeeasytreedepth-first-searchbreadth-first-searchbinary-tree
LeetCode 392 - Is Subsequence

The problem asks whether string s can be formed from string t by deleting some characters from t without changing the order of the remaining characters. A subsequence does not require characters to be adjacent. The only requirement is that the relative ordering stays the same.

leetcodeeasytwo-pointersstringdynamic-programming
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 355 - Design Twitter

This problem asks us to design a simplified version of a social media platform similar to Twitter. The system must support four main operations: 1. Users can post tweets. 2. Users can follow other users. 3. Users can unfollow other users. 4.

leetcodemediumhash-tablelinked-listdesignheap-(priority-queue)
LeetCode 1742 - Maximum Number of Balls in a Box

The problem describes a scenario in which you have a sequence of balls numbered consecutively from lowLimit to highLimit, inclusive. Each ball must be placed into a box, where the box number is determined by the sum of the digits of the ball’s number.

leetcodeeasyhash-tablemathcounting
CF 24D - Broken robot

The board has N rows and M columns. A robot starts at cell (i, j) and repeatedly performs one random move. From an interior cell it has four equally likely choices: stay in place, move left, move right, or move down.

codeforcescompetitive-programmingdpmathprobabilities
CF 23B - Party

We can think of the party as an undirected friendship graph. Every person is a vertex, and an edge means two people are friends.

codeforcescompetitive-programmingconstructive-algorithmsgraphsmath
LeetCode 1162 - As Far from Land as Possible

The problem requires finding the water cell in a given n x n grid that is farthest from any land cell, using Manhattan distance. The grid consists only of 0s and 1s, where 0 represents water and 1 represents land.

leetcodemediumarraydynamic-programmingbreadth-first-searchmatrix
LeetCode 380 - Insert Delete GetRandom O(1)

This problem asks us to design a custom data structure called RandomizedSet that supports three operations: 1. Insert a value into the set. 2. Remove a value from the set. 3. Return a random element from the set.

leetcodemediumarrayhash-tablemathdesignrandomized
LeetCode 1380 - Lucky Numbers in a Matrix

This problem asks us to identify all lucky numbers in a given matrix. A lucky number is defined as a value that satisfie

leetcodeeasyarraymatrix
CF 69D - Dot

We start with a point on the plane at coordinates (x, y). Players alternate turns, and on each turn they may do one of two things. They may add one of the given movement vectors to the current position.

codeforcescompetitive-programmingdpgames
LeetCode 506 - Relative Ranks

The problem gives us an array named score, where each element represents the score earned by an athlete in a competition. Every athlete has a unique score, which means there are no ties to worry about when determining rankings.

leetcodeeasyarraysortingheap-(priority-queue)
LeetCode 1289 - Minimum Falling Path Sum II

The problem asks us to compute the minimum sum of a falling path with non-zero shifts in a square n x n matrix. A fallin

leetcodehardarraydynamic-programmingmatrix
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 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 970 - Powerful Integers

This problem asks us to generate all integers that can be written in the form: where: - i = 0 - j = 0 - the resulting value is less than or equal to bound The inputs are three integers: - x, the base of the first exponential term - y, the base of the second exponential term -…

leetcodemediumhash-tablemathenumeration
LeetCode 1315 - Sum of Nodes with Even-Valued Grandparent

That is a long, structured reference document and will exceed a single response comfortably. I can provide the complete

leetcodemediumtreedepth-first-searchbreadth-first-searchbinary-tree
LeetCode 520 - Detect Capital

--- [LeetCode Problem 520](https://leetcode.com/problems/detect-capital/) Difficulty: 🟢 Easy Topics: String

leetcodeeasystring
LeetCode 2010 - The Number of Seniors and Juniors to Join the Company II

The problem asks us to simulate a hiring process with a fixed salary budget of $70,000, where candidates are classified as either "Senior" or "Junior" and each has a unique salary.

leetcodeharddatabase
LeetCode 1784 - Check if Binary String Has at Most One Segment of Ones

In this problem, we are given a binary string s that contains only the characters '0' and '1'. The string is guaranteed to begin with '1', which means there are no leading zeros. The task is to determine whether the string contains at most one contiguous segment of ones.

leetcodeeasystring
LeetCode 522 - Longest Uncommon Subsequence II

The problem asks us to find the length of the longest string in the array that is not a subsequence of any other string in the same array. A subsequence is formed by deleting zero or more characters from a string without changing the order of the remaining characters.

leetcodemediumarrayhash-tabletwo-pointersstringsorting
LeetCode 1680 - Concatenation of Consecutive Binary Numbers

The problem asks us to build a very large binary number by concatenating the binary representations of every integer fro

leetcodemediummathbit-manipulationsimulation
CF 14C - Four Segments

We are given exactly four line segments on the 2D plane. Every segment is axis-aligned, or may even degenerate into a single point.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsgeometryimplementationmath
CF 4C - Registration System

We are building a username registration system. Every incoming request contains a desired username. If that username has never appeared before, registration succeeds immediately and we print OK.

codeforcescompetitive-programmingdata-structureshashingimplementation
LeetCode 803 - Bricks Falling When Hit

This problem asks us to simulate a sequence of brick removals in a 2D grid, while determining how many additional bricks become unstable and fall after each removal.

leetcodehardarrayunion-findmatrix
CF 66D - Petya and His Friends

We need to construct n distinct positive integers with two simultaneous properties. First, every pair of numbers must share a common divisor larger than 1. In other words, for every pair (ai, aj), their gcd cannot equal 1. Second, the gcd of the entire set must equal 1.

codeforcescompetitive-programmingconstructive-algorithmsmathnumber-theory
CF 116B - Little Pigs and Wolves

We have a small rectangular grid where each cell is either empty, contains a pig, or contains a wolf. A wolf may eat one pig that is directly adjacent to it in one of the four cardinal directions. Once a pig is eaten, it disappears and cannot be eaten again.

codeforcescompetitive-programminggreedyimplementation
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 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
CF 1941D - Rudolf and the Ball Game

We have a circle of n players, numbered 1 through n clockwise. The ball starts with player x. There are m throws, and each throw has a distance r_i and a remembered direction c_i. The direction could be clockwise (0), counterclockwise (1), or unknown (?).

codeforcescompetitive-programmingdfs-and-similardpimplementation
LeetCode 1025 - Divisor Game

The problem describes a two-player turn-based game between Alice and Bob. The game starts with a single integer n written on a chalkboard. Alice always takes the first turn.

leetcodeeasymathdynamic-programmingbrainteasergame-theory
LeetCode 1590 - Make Sum Divisible by P

This problem asks us to determine the smallest contiguous subarray we can remove from a given array of positive integers

leetcodemediumarrayhash-tableprefix-sum
LeetCode 580 - Count Student Number in Departments

This problem asks us to determine how many students are enrolled in each department, including departments that currently have no students. We are given two tables: Student and Department.

leetcodemediumdatabase
LeetCode 1597 - Build Binary Expression Tree From Infix Expression

The problem asks us to construct a binary expression tree from a valid infix arithmetic expression string. An infix expr

leetcodehardstringstacktreebinary-tree
LeetCode 1596 - The Most Frequently Ordered Products for Each Customer

The problem requires us to find the most frequently ordered product or products for each customer from a set of three tables: Customers, Orders, and Products. Each customerid may have multiple orders, and each order contains a productid.

leetcodemediumdatabase
LeetCode 1428 - Leftmost Column with at Least a One

This problem gives us access to a binary matrix where every row is sorted in non-decreasing order. That means every row

leetcodemediumarraybinary-searchmatrixinteractive
LeetCode 384 - Shuffle an Array

The problem asks us to design a data structure that supports two operations on an integer array: 1. Reset the array back to its original order. 2. Return a randomly shuffled version of the array.

leetcodemediumarraymathdesignrandomized
LeetCode 73 - Set Matrix Zeroes

The problem gives us a two dimensional matrix of integers with m rows and n columns. We must modify the matrix in place so that whenever a cell contains 0, every element in that cell's entire row and entire column also becomes 0.

leetcodemediumarrayhash-tablematrix
LeetCode 221 - Maximal Square

The problem gives us a two dimensional binary matrix where each cell contains either '0' or '1'. Our task is to find the largest square submatrix that contains only '1' values, then return the area of that square.

leetcodemediumarraydynamic-programmingmatrix
LeetCode 710 - Random Pick with Blacklist

The problem asks us to design a data structure that can repeatedly return a random integer from the range [0, n - 1], while excluding all integers that appear in a blacklist. Every valid number must have exactly the same probability of being chosen.

leetcodehardarrayhash-tablemathbinary-searchsortingrandomized
LeetCode 882 - Reachable Nodes In Subdivided Graph

The problem gives us an undirected graph with n original nodes. Each edge has an associated subdivision count, meaning the edge is replaced by a chain of intermediate nodes. For an edge [u, v, cnt], the original direct connection between u and v no longer exists as a single edge.

leetcodehardgraph-theoryheap-(priority-queue)shortest-path
LeetCode 142 - Linked List Cycle II

This problem asks us to determine whether a singly linked list contains a cycle and, if it does, return the exact node where that cycle begins. A linked list is normally a sequence of nodes where each node points to the next one, eventually ending with null.

leetcodemediumhash-tablelinked-listtwo-pointers
LeetCode 1516 - Move Sub-Tree of N-Ary Tree

This problem asks us to modify the structure of an N-ary tree by moving one subtree under another node. Every node contains a unique value, and each node may have any number of children.

leetcodehardtreedepth-first-search
LeetCode 416 - Partition Equal Subset Sum

The problem asks whether an array of positive integers can be divided into two subsets such that both subsets have exactly the same sum. Suppose the total sum of all numbers in the array is S.

leetcodemediumarraydynamic-programming
LeetCode 1355 - Activity Participants

This problem asks us to analyze participation counts for different activities and return only the activities whose parti

leetcodemediumdatabase
CF 8E - Beads

We are asked to generate a specific string of beads of length n according to a Martian’s unique notion of string equivalence. Each bead is either red (0) or blue (1).

codeforcescompetitive-programmingdpgraphs
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
LeetCode 1447 - Simplified Fractions

The problem asks us to generate all simplified fractions between 0 and 1 (exclusive) where the denominator does not exce

leetcodemediummathstringnumber-theory
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
CF 130B - Gnikool Ssalg

The problem asks us to reverse a string. Given a sequence of characters, the output should be the same sequence but in the opposite order, so that the first character becomes the last, the second becomes the second-to-last, and so on.

codeforcescompetitive-programming*specialimplementationstrings
LeetCode 496 - Next Greater Element I

The problem is asking us to find the next greater element for each element in nums1 within another array nums2. Formally, for each element in nums1, we need to locate its position in nums2 and then find the first element to its right in nums2 that is greater than itself.

leetcodeeasyarrayhash-tablestackmonotonic-stack
LeetCode 681 - Next Closest Time

The problem gives us a valid time string in the format "HH:MM" and asks us to construct the next chronological time using only the digits already present in the original time. The important detail is that digits may be reused any number of times.

leetcodemediumhash-tablestringbacktrackingenumeration
LeetCode 1345 - Jump Game IV

The problem is asking for the minimum number of steps required to reach the last index of an integer array, starting fro

leetcodehardarrayhash-tablebreadth-first-search
LeetCode 1217 - Minimum Cost to Move Chips to The Same Position

The problem asks us to move n chips located at various positions along a one-dimensional line so that they all end up at the same position. Each chip can be moved either by 2 units at zero cost or by 1 unit at a cost of 1.

leetcodeeasyarraymathgreedy
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
LeetCode 852 - Peak Index in a Mountain Array

This problem gives us a special type of array called a mountain array. A mountain array strictly increases until it reaches a single peak element, then strictly decreases afterward. In other words, there exists some index i such that: - arr[0] < arr[1] < ...

leetcodemediumarraybinary-search
LeetCode 740 - Delete and Earn

The problem gives us an integer array nums, and we want to maximize the total number of points earned by repeatedly deleting elements. When we delete a number x, we gain x points. However, deleting x also forces the removal of every occurrence of x - 1 and x + 1.

leetcodemediumarrayhash-tabledynamic-programming
LeetCode 38 - Count and Say

The problem asks us to generate the nth term of the "count-and-say" sequence. This sequence is built recursively, where each term is created by describing the previous term.

leetcodemediumstring
LeetCode 1518 - Water Bottles

The problem is asking us to determine the maximum number of water bottles a person can drink given two integers: numBott

leetcodeeasymathsimulation
CF 47A - Triangular numbers

We are asked to determine if a given positive integer can be represented as a triangular number. Triangular numbers are formed by arranging dots into an equilateral triangle, so the _n_-th triangular number is the sum of the first _n_ positive integers.

codeforcescompetitive-programmingbrute-forcemath
CF 63E - Sweets Game

The board is a fixed hexagon with 19 cells. Some cells contain chocolates, some are empty. Two players alternate moves, and a move consists of choosing a contiguous segment of chocolates that lies on a straight line parallel to one of the three hexagon directions.

codeforcescompetitive-programmingbitmasksdfs-and-similardpgamesimplementation
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 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
CF 3B - Lorry

We have a lorry with capacity v. There are two kinds of boats.

codeforcescompetitive-programminggreedysortings
LeetCode 1354 - Construct Target Array With Multiple Sums

The problem asks whether it is possible to construct a given target array from an initial array arr of the same length,

leetcodehardarrayheap-(priority-queue)
LeetCode 939 - Minimum Area Rectangle

The problem gives us a collection of distinct points on a 2D plane. Each point is represented as [x, y], where x is the horizontal coordinate and y is the vertical coordinate.

leetcodemediumarrayhash-tablemathgeometrysorting
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
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
CF 113B - Petr#

We are asked to count how many distinct substrings of a given string t start with a string sbegin and end with another string send. The key detail is that substrings are considered different only by their content, not by their position in t.

codeforcescompetitive-programmingbrute-forcedata-structureshashingstrings
LeetCode 254 - Factor Combinations

The problem asks us to generate every unique way to express a number n as a product of integers greater than 1 and less than n. A factor combination is a list of integers whose product equals n. The order inside a combination does not matter.

leetcodemediumbacktracking
CF 1C - Ancient Berland Circus

We are given the coordinates of three vertices of some regular polygon. The polygon itself is unknown: we do not know how many sides it has, where its center is, or which vertices the three points correspond to.

codeforcescompetitive-programminggeometrymath
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 433 - Minimum Genetic Mutation

The problem describes a mutation process between genetic sequences. Each gene is represented as a string of exactly 8 characters, and every character must be one of four possible nucleotides: 'A', 'C', 'G', or 'T'.

leetcodemediumhash-tablestringbreadth-first-search
CF 89B - Widget Library

We are asked to simulate a tiny GUI layout system. There are three kinds of widgets. A plain Widget has a fixed width and height. HBox and VBox are container widgets that can store other widgets. An HBox places children horizontally, while a VBox places them vertically.

codeforcescompetitive-programmingdpexpression-parsinggraphsimplementation
LeetCode 1393 - Capital Gain/Loss

The Stocks table records stock trading activity. Each row represents either a Buy or Sell operation for a specific stock

leetcodemediumdatabase
LeetCode 750 - Number Of Corner Rectangles

The problem asks us to count the number of corner rectangles in a binary m x n matrix grid. A corner rectangle is defined as a set of four 1s in the grid that form the corners of an axis-aligned rectangle. Importantly, only the corners need to be 1; the interior cells can be 0.

leetcodemediumarraymathdynamic-programmingmatrix
LeetCode 1261 - Find Elements in a Contaminated Binary Tree

The problem gives us a binary tree where every node value has been contaminated and replaced with -1. However, we know t

leetcodemediumhash-tabletreedepth-first-searchbreadth-first-searchdesignbinary-tree
LeetCode 543 - Diameter of Binary Tree

The problem asks us to compute the diameter of a binary tree. The diameter is defined as the length of the longest path between any two nodes, measured in number of edges. Importantly, this path does not need to pass through the root of the tree.

leetcodeeasytreedepth-first-searchbinary-tree
CF 26B - Regular Bracket Sequence

We are given a string consisting solely of opening and closing parentheses. The task is to determine the maximum length of a subsequence that forms a valid, or regular, bracket sequence.

codeforcescompetitive-programminggreedy
LeetCode 2011 - Final Value of Variable After Performing Operations

This problem asks us to simulate a simple programming language with a single integer variable X that starts at 0. We are given a list of string operations, each of which either increments (++X or X++) or decrements (--X or X--) the value of X by 1.

leetcodeeasyarraystringsimulation
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
LeetCode 864 - Shortest Path to Get All Keys

This problem asks us to find the shortest path to collect all keys in a 2D grid maze. The grid contains walls, open spaces, keys, locks, and a starting point. You can move in the four cardinal directions but cannot move diagonally, through walls, or outside the grid.

leetcodehardarraybit-manipulationbreadth-first-searchmatrix
LeetCode 725 - Split Linked List in Parts

The problem gives us the head of a singly linked list and an integer k. We must divide the linked list into exactly k consecutive parts while preserving the original order of nodes. The important requirement is that the parts should be as evenly sized as possible.

leetcodemediumlinked-list
CF 19D - Points

We maintain a dynamic set of points on a 2D plane. Three operations are supported.

codeforcescompetitive-programmingdata-structures
CF 87B - Vasya and Types

The language in this problem has only two real base types, void and errtype. Every other type is defined through typedef, and every query asks us to evaluate a type expression with typeof. A type expression is built from a base name plus some number of and & operators.

codeforcescompetitive-programmingimplementationstrings
LeetCode 1530 - Number of Good Leaf Nodes Pairs

This problem gives us the root of a binary tree and an integer distance. We need to count how many pairs of leaf nodes s

leetcodemediumtreedepth-first-searchbinary-tree
LeetCode 783 - Minimum Distance Between BST Nodes

The problem asks us to find the minimum difference between values of any two nodes in a Binary Search Tree (BST). In other words, given a BST, we need to calculate the smallest absolute difference a - b where a and b are values of two distinct nodes.

leetcodeeasytreedepth-first-searchbreadth-first-searchbinary-search-treebinary-tree
LeetCode 85 - Maximal Rectangle

The problem asks us to find the area of the largest rectangle containing only 1s in a binary matrix. The matrix consists of characters '0' and '1', where '1' represents a valid cell that may belong to a rectangle and '0' represents a blocked cell that cannot be included.

leetcodehardarraydynamic-programmingstackmatrixmonotonic-stack
LeetCode 181 - Employees Earning More Than Their Managers

This problem gives us a single database table named Employee. Each row represents one employee and contains four pieces of information: Column Meaning --- --- id Unique identifier for the employee name Employee name salary Employee salary managerId The id of that employee's…

leetcodeeasydatabase
CF 36B - Fractal

We start with an n × n pattern consisting of black cells (*) and white cells (.). This pattern acts like a template.

codeforcescompetitive-programmingimplementation
LeetCode 454 - 4Sum II

The problem gives four integer arrays, nums1, nums2, nums3, and nums4, each containing n elements. We must count how many index tuples (i, j, k, l) satisfy: The important detail is that we are counting tuples of indices, not unique value combinations.

leetcodemediumarrayhash-table
CF 98A - Help Victoria the Wise

We have six gems, each with one of six possible colors. The six gems must be placed onto the six faces of a cube. Two placements are considered identical if one can be rotated into the other. The input is simply a string of length six.

codeforcescompetitive-programmingbrute-forceimplementation