Fading Coder

One Final Commit for the Last Sprint

Algorithm Template Library: Data Structures and Graph Theory

Data Structures Mo's Algorithm Standard Mo's Algorithm Used to solve problems like P1494 [National Training Team] Little Z's Socks. #include <bits/stdc++.h> #define int long long using namespace std; const int MAXN = 200010; struct Query { int l, r, idx; }; struct Fraction { int numerator, den...

Using a Modified Sieve to Count Composite Numbers Built from Exactly 12 Prime Factors

A specialized variant of the Sieve of Eratosthenes can simultaneously tag integer primality and record the count of prime factors for each composite. This technique is particularly effective when searching for numbers within a range whose total number of prime factors (with multiplicity) equals a gi...

Validating Numeric Strings: Implementing an isNumeric Function

Objective Implement a function to determine if a given string represents a valid numeric value, including integers, decimals, and numbers in scientific notation. Examples of Valid Inputs "+100", "5e2", "-123", "3.1416", "-1E-16" Examples of Invalid I...

Minimum Grouping for Non-Overlapping Intervals

Given N closed intervals [x_i, y_i], split them into the least number of groups such that all intervals in each group are pairwise non-overlapping (including endpoints). Output this minimum count. Input Format The first line contains an integer N, the number of intervals. The next N lines each conta...

Calculating Specific Digit Occurrences in Integers

Algorithm LogicThe task requires implementing a function that calculates the frequency of a specific digit (0-9) within a given integer. The primary challenge involves handling the sign of the input number and the edge case where the input is zero.Since the input integer is passed as a const int, it...

Backtracking Algorithm Solutions: Finding Increasing Subsequences and Permutations

Problem 491: Increasing Subsequences Given an enteger array nums, find all strictly increasing subsequences that contain at least two elements. Return the solution without duplicate subsequences. The key challenge here is that we cannot sort the original array, as sorting would transfrom every subse...

Identifying Gems in a Collection Using Hash Sets

Problem OverviewGiven a string gem_types representing the different categories of precious stones, and another string inventory representing the stones in your possession, determine how many of the stones you own are actually precious. Each character in inventory represents a single stone.Constraint...

Analyzing CSP-J Preliminary Round Exam Questions from 2017

Multiple Choice Questions Question 1 In 8-bit two's complement representation, the binary number 10101011 corresponds to which decimal value? Options: A. 43 B. -85 C. -43 D. -84 Answer: B Explanation: The most significnat bit indicates negativity. Covnerting from two's complement yields -85. Questio...

Solving the Tower of Hanoi Problem with C

Problem Description The Tower of Hanoi is a classic mathematical puzzle. The setup consists of three pegs and a number of disks of different sizes. Initially, all disks are stacked on the first peg in order of size, with the largest at the bottom and smallest at the top. The objective is to move the...

Array Rotation Algorithms: Multiple Approaches to Shift Elements Right

Given an array, shift its elements to the right by k positions, where k is a non-negative number. Example 1: Input: [1,2,3,4,5,6,7] and k = 3 Output: [5,6,7,1,2,3,4] Explenation: Right rotation by 1 step: [7,1,2,3,4,5,6] Right rotation by 2 steps: [6,7,1,2,3,4,5] Right rotasion by 3 steps: [5,6,7,1,...