CS Theory

Find the Town Judge

Three approaches to solve the town judge problem using graph theory. From brute force adjacency lists to optimized counting methods and adjacency matrix solutions with O(N) time complexity.

February 5, 2026

Find Words That Follow a Bigram Pattern

Given a sentence with words separated by spaces and two consecutive words, return all third words that follow this bigram pattern. The solution finds all occurrences of the first word followed by the second word, then extracts what comes after.

February 5, 2026

Flatten Binary Trees to Linked Lists

How to convert binary trees into linked lists in place using preorder traversal. Two approaches: flattening with recursion and converting BSTs to doubly linked lists.

February 5, 2026

Flipping Binary Trees to Match Preorder Traversal

Given a binary tree and a target preorder traversal sequence, find the minimum number of nodes to flip by swapping left and right children to match the target sequence. This problem demonstrates how recursive tree traversal can handle structural modifications during traversal.

February 5, 2026

Gray Code

The Gray code of number n equals (n>>1) ^ n. This simple formula generates the sequence where each adjacent pair differs by only one bit, useful in digital communications and error correction systems.

February 5, 2026

Happy Number

Detect whether a number becomes 1 through repeated sum of squares of its digits. Use Floyd's cycle detection algorithm with fast and slow pointers to identify loops in the sequence.

February 5, 2026

Implement strStr

Two approaches to implement the strStr function that finds the first occurrence of a substring in a string. The brute force method checks each position while KMP offers better performance for certain cases.

February 5, 2026

Integer to Roman Conversion

Convert integers to Roman numerals using two approaches: digit-by-digit processing with reversal or enumeration leveraging problem constraints. The first method handles each digit position systematically while the second precomputes all possible combinations.

February 5, 2026

Isomorphic Strings

Check if two strings are isomorphic by verifying character mapping rules. One string's characters can replace another to match it, but different characters cannot map to the same target.

February 5, 2026

Largest Component Size by Common Factor

Find the largest connected component in a graph where nodes connect if they share common factors greater than 1. Uses union-find with path compression for efficient grouping.

February 5, 2026