Fading Coder

One Final Commit for the Last Sprint

Hash Table Implementation for Common Algorithm Problems

Theory Overview Arrays, sets, and maps are all implementations of hash tables Hash tables excel at determining whether an element has been encountered previously Problem 1: Valid Anagram Problem Link: 242. Valid Anagram - LeetCode Difficulty: Easy Solution Approach: When the chaarcter range is small...

Implementing 2D Difference Arrays for Efficient Range Updates

Understanding Difference Arrays Given an array arr, its difference array diff is defined as: diff[0] = arr[0] diff[i] = arr[i] - arr[i-1] for i > 0 To reconstruct the original array from the difference array: arr[i] = diff[0] + diff[1] + ... + diff[i] For range updates [l, r] with value x: diff[l...

Finding Handsome Loners Without Friends

When everyone is busy posting photos on social media, there are always some people who are too handsome to have friends. This problem asks you to identify those who are too handsome to have friends. Input Format: The first line contains a positive integer ( N ) (≤100), the number of known friend cir...

Contest Problem Analysis: Maximization, Fragmentation, Permutations, and River Crossing

Maximizing Triples Product Given three integers, you can increment any of them exactly five times. The goal is to maximize their final product. To achieve the maximum product, we should always increment the smallest of the three integers. This minimizes the disparity between the values, which yields...

Finding the Lowest Common Ancestor in a Binary Tree

Minimum Absolute Difference in a Binary Search Tree To compute the minimum absolute difference between values in a binary search tree, leverage the property that an in-order traversal yields a sorted sequence. By tracking the previous node during traversal, differences can be calculatde efficiently....

Solving 2020 Blue Bridge Cup Java Group B Provincial Contest Problems

Problem Statement: Calculate how many digit '2's are needed to create doorplates numbered from 1 to 2020. Each digit is counted separately (e.g., doorplate 1017 contains one '0', two '1's, and one '7'). Solution: public class DigitCounter { public static void main(String[] args) { int count = 0; for...

Solving Algorithmic Problems with Search Techniques and Backtracking

P1092 NOIP2004 Senior Division: Alphametic Puzzle This problem involves solving an alphametic puzzle where letters represent digits in a base-N addition. The solution uses depth-first search with pruning to assign digits to letters efficient. #include <iostream> #include <vector> #includ...

Day 9: String Manipulation Part 2

151. Reverse Words in a String Given a string, reverse the order of its words (with each word’s internal characters remaining in their original order). The result must not contain leading/trailing spaces, and consecutive words must be separated by exact one space. Examples: Input: "the sky is b...

Light Switching Problem: Counting Active Bulbs After Multiple Operations

Problem Understanding This problem simulates an operation process where m people interact with n light bulbs. Initially, all bulbs are in the ON state (represented by '1' for ON and '0' for OFF). The operations follow these rules: Person 1: Turns off all bulbs (all states become 0). Person 2: Toggle...

Breadth-First Search Algorithms: Trees, Graphs, and Matrices

Core Concepts and Queue Usage Breadth-First Search (BFS) is fundamental for traversing graphs and trees, particularly useful for level order traversal, identifying connected components, topological sorting, and finding the shortest path in unweighted graphs (where all edges possess a length of 1). W...