Fading Coder

One Final Commit for the Last Sprint

Finding the Maximum Product of Five Elements in an Array

You are given an array of integers. Find the maximum possible product of five elements from the array, where the indices of these elements are in strictly increasing order. Input The input consists of multiple test cases. The first line contains an enteger t (1 ≤ t ≤ 2 × 10^4) — the number of test c...

Constructing Longest Word Chains Through Suffix-Prefix Overlap Backtracking

The objective is to assemble the longest possible concatenated string from a provided vocabulary list, beginning with a specified initial character. Each vocabulary entry may be utilized a maximum of two times during chain construction. When connecting two words, the trailing substring of the first...

Longest Substring Without Repeating Characters

Given a string s, determine the length of the longest substring that contains no repeating characters. Example 1: Input: s = "abcabcbb" Output: 3 Explanation: The answer is "abc", with the length of 3. Example 2: Input: s = "bbbbb" Output: 1 Explanation: The answer is &...

Insertion Sort and Shell Sort Algorithms

Insertion Sort Insertion sort constructs a sorted array incrementally. It takes one element from the input data and finds its correct position within the sorted list, repeating until no elements remain. Simple Insertion Sort For each element at index i (from 1 to n-1), the algorithm compares it with...

Calculating Sum of Numbers with Digit Sums in a Specified Range

Problem Analysis This problem requires calculating the sum of all integers from 1 to N where the sum of the digits of each integer falls within the inclusive range [A, B]. For example, with N=20, A=2, and B=5, the qualiyfing numbers are 2, 3, 4, 5, 11, 12, 13, 14, 15, and 20. Their total sum is 84....

Implementing High-Precision Arithmetic in C++ with a Custom Big Integer Class

A high-precision integer class enables arithmetic operations on numbers exceedign standard integer limits, icnluding handling negative values. This class uses a fixed-size array to store digits, with M defining the maximum length of the string representation. It overloads operators for addition, sub...

Determining Feasibility of Reaching the End in a Jump Game

The canJump function accepts an integer vector nums as input and returns a boolean value indicating weather it is possible to jump from the first element to the last element of the array. Let's analyze this code step by step: Variable Initialization: int maxReach = 0; Here, maxReach represents the f...

Dynamic Programming for Unbounded Knapsack Problems: Coin Change, Combination Sum, and Stair Climbing

Unbounded Knapsack Fundamentals In the unbounded knapsack problem, each item can be used an unlimited number of times, unlike the 0/1 knapsack where each item is used at most once. This difference requires two key implementation changes: When iterating through the knapsack capacity, we must iterate...

Solutions to the 2024 Blue Bridge Cup Provincial C++ Intermediate/Advanced Group Programming Problems

T1 - Reading Plan Problem: A book has (n) pages. On the first day, a person reads (x) pages. Each subsequent day, they read (y) pages more than the previous day. How many days are needed to finish the book? Input: Three integers (n), (x), (y) ((20 \le n \le 5000, 1 \le x, y \le 20)) separated by spa...

Determining the Champion Team in a Tournament

Problem: Find Champion I In a tournament with n teams, numbered from 0 to n - 1, you are given a square boolean matrix grid of size n x n. For all pairs (i, j) where 0 <= i, j <= n - 1 and i != j, if grid[i][j] == 1, then team i is stronger than team j. Otherwise, team j is stronger than team...