Fading Coder

One Final Commit for the Last Sprint

Efficient Pattern Matching with the KMP Algorithm

Given two strings text and pattern, find all starting indices in text where pattern occurs as a contiguous substring. Additionally, for every prefix of pattern, compute the length of its longest proper border—a proper border is a non-empty substring that is both a prefix and a suffix of the given pr...

Algorithmic Solutions for Competitive Programming Problems

Algorithmic Solutions for Competitive Programming Problems Extracting Initial Characters from Input Strings When solving problems that require extracting the first letters of words from input strings, a direct character-by-character approach can be effective: #include <iostream> #include <s...

Implementing Array Partitioning: A Deep Dive into the Lodash chunk Function

The chunk function is a utility designed to split a single array into multiple sub-arrays of a specific length. If the total number of elements isn't perfectly divisible by the chunk size, the final sub-array contains the remaining elements. This pattern is particularly useful in frontend developmen...

Singly Linked List Problem Walkthroughs on LeetCode

Deleting Nodes by Value in a Linked List A direct approach is to construct a new list containing only the nodes whoce values differ from the target. Traverse the original list, and when a node with a non-matching value is found, append it to the result. Care must be taken to terminate the new list p...

Finding Peak Elements in Arrays Using Binary Search Algorithm

A peak element in an array is one that is strictly greater than its neighboring elements. Given an integer array where no two adjacent values are equal, the task is to locate any peak element and return its index. Multiple peaks may exist, and returning any single peak is acceptable. The solution mu...

Efficiently Counting Inversion Pairs in Stock Records Using Merge Sort

Problem Definition Given an array of stock prices representing daily records, an inversion pair is defined as a tuple $(i, j)$ where $i < j$ and $record[i] > record[j]$. The objective is to calculate the total count of such pairs within the input array. For instance, given the input [9, 7, 5, 4, 6],...

Fundamentals of 2D Computational Geometry

Computational geometry problems typically operate in the real number space ℝ, requiring double-precision floating-point operations. The key challenge lies in comparing floating-point values due to precision errors. We often need to treat values like 1 and 1.0000001 as equal. We define an epsilon (ε)...

Efficient Array Processing: Squared Sorting, Subarray Minimization, and Spiral Construction

Sorting Squared Elements of a Monotonic Array Given an integer sequence arranged in non-decreasing order, the objective is to generate a new array containing the squares of each element, also sorted in non-decreasing order. Because the original input may contain negative values, squaring them can in...

25 Essential Python Programming Exercises: From Mathematical Puzzles to Classic Algorithms

Problem 1: Narcissistic Numbers (Armstrong Numbers) A Narcissistic number (also known as an Armstrong number or PPDI) is a 3-digit number where the sum of the cubes of its digits equals the number itself. For example: $1^3 + 5^3 + 3^3 = 153$. for candidate in range(100, 1000): hundreds = candidate /...

Sequential Lists and Linked Lists: Core Linear Data Structures Explored with Implementations and Exercises

Linear structures consist of a finite sequence of elements with identical properties. Common linear data structures include arrays, linked lists, stacks, queues, and strings. While linear structures follow a continuous logical arrangement, their physical storage may be either contiguous or non-conti...