Fading Coder

One Final Commit for the Last Sprint

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...

Efficient Range Queries Using Prefix Sums in One and Two Dimensions

Prefix Sums in One-Dimensional Arrays LeetCode Problem: Range Sum Query - Immutable Problem Overview Given an integer array nums, implement a data structure that can efficiently answer multiple queries for the sum of elements between indices left and right inculsive. Core Idea Instead of recalculati...

Implementing a B-Tree in Java with Top-Down Insertion and Deletion

B-trees are height-balanced search trees dseigned to minimize I/O by packing many ordered keys into a single node sized to a disk block or cache line. Instead of assuming all data lives in main memory (as typical for AVL or Red-Black trees), B-trees optimize for large datasets by reducing the number...
First Prev 2 3 4 5 6 7 8 9 10 11 Last