Fading Coder

One Final Commit for the Last Sprint

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

Binary Search for Optimization Problems

Binary search is an efficient algorithm for locating a target value within a sorted sequence. Its core principle involves repeatedly dividing the search interval in half, leveraging monotonic properties to eliminate large portions of the search space without explicit enumeration. Implementation Stra...

Array Sorting Techniques with C++ Standard Algorithm

Function Signature and Requirements The sorting utility is provided by the <algorithm> header. The function accepts a starting iterator, an ending iterator, and an optional comparison predicate. Without a custom predicate, elements are ordered in ascending sequence. This utility is generic and...