Fading Coder

One Final Commit for the Last Sprint

Finding Two Numbers That Sum to a Target Value

Given an integer array values and a target integer goal, find the two numbers within the array whose sum equals goal and return their indices. Example 1: Input: values = [2,7,11,15], goal = 9 Output: [0,1] Explanation: values[0] + values[1] == 9. Example 2: Input: values = [3,2,4], goal = 6 Output:...

Implementing Linear Dynamic Programming in Python

Linear dynamic programming is a specific approach within dynamic programming used to solve problems with a linear structure. In this paradigm, the states of the problem exhibit a linear relationship, and information is typically stored and transferred using a one-dimensional array. It is commonly ap...

Implementing Linked List Operations in JavaScript: Node Removal and Reversal

Removing Nodes with a Specific Value from a Linked List Given the head node of a singly linked list and an integer value, the task is to delete all nodes whose value matches the given integer and return the new head of the list. Example: Input: head = [1,2,6,3,4,5,6], val = 6 Output: [1,2,3,4,5] App...

Computing the Greatest Common Divisor with the Euclidean Algorithm

The greatest common divisor (GCD) of two or more integers is the largest positive integer that divides each of the numbers without leaving a remainder. For instance, the common divisors of 12 and 18 are 1, 2, 3, and 6. The largest among them is 6, so gcd(12, 18) = 6. This concept is fundamental in a...

Efficient Techniques for Removing Duplicate Elements from JavaScript Arrays

Method 1: Using a New Array for Comparison This approach iterates through the original array and checks each element against a new array. If the element is not found, it is added. const originalArray = ['x', 5, 5, 5, 7, 9, 9, 'y', 'z', 'x']; const uniqueArray = []; const length = originalArray.lengt...

Computing the Minimum MEX of Subarray LCMs

Given a sequence (a) of (n) positive integers, a positive integer (x) is considered non-humor if there exists a contiguous subarray whose least common multiple (LCM) equals (x). The task is to find the smallest positive integer that is not non-humor, i.e., the minimum excluded value (MEX) from the s...

Optimizing Large Knapsack Problems with CDQ Divide and Conquer

Applying CDQ divide and conquer can significantly enhance the execution speed of the solution. In practice, this approach can pass all test cases within 10ms for the given data scale. For background on meet-in-the-middle search, refer to existing solutions on the topic. Problem Analysis This is a cl...

Algorithmic Solutions for Selected Problems from the 12th Blue Bridge Cup

B. Determining the Number of Unique Lines in a Grid Given a grid of points defined by coordinates (x, y) where x ranges from 0 to 19 and y ranges from 0 too 20, the objective is to calculate the total number of distinct straight lines that can be formed by connecting any two points. Implementation S...

Understanding and Implementing Union-Find Data Structures for Connectivity Problems

Union-Find, also known as Disjoint Set Union (DSU), is a data structure designed to efficiently handle connectivity queries and union operations betwean elements. Its primary use is to determine if two elements belong to the same connected component or set. Core Operations Union (Join): Merges the s...

Implementing the Two Sum Problem in C with Hash Tables

Core Concepts Dynamic Array Allocation To create a dynamic array in C, use malloc from stdlib.h: int* arr = (int*)malloc(len * sizeof(int)); Reading Array Input with scanf scanf automatically skips whitespace (spaces, tabs, newlines) when reading input. Use getchar() to clear the newline character l...