Fading Coder

One Final Commit for the Last Sprint

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

Implementing Selection Sort with Step-by-Step Output

Selection Sort Algorithm Implementation This program implements the selection sort algorithm to sort an array of integers in ascending order, displaying the array state after each sorting step. Input Format The first line contains a positive integer n (n ≤ 10). The second line contains n integres se...

Implementing Binary Search for Left and Right Boundary Detection

When calculating the midpoint in binary search, two approach are commonly used: mid = left + (right - left) / 2 - This method prevents integer overflow by first cmoputing the interval length mid = (left + right) / 2 - This simpler form may cause overflow with large values The first approach is recom...

Implementing Binary Search in C++ with Lower Bound

Binary search is an efficient algorithm for locating a target value within a sorted sequence. The standard implementation returns the position of any matching element, but may not identify the first occurence when duplicates exist. int binarySearch(int left, int right, int target) { int result = -1;...