Binary Tree Algorithms: Bottom-Left Value, Path Sum Variants, and Tree Construction from Traversals

Finding the Bottom-Left Node Value Given the root of a binary tree, return the value of the leftmost node at the deepest level. Breadth-First Search (Iterative) A level-order traversal naturally visits nodes layer by layer. The first node encountered in the final level is the answer. #include <queue> int findBottomLeftValue(TreeNode* roo ...

Posted on Sat, 13 Jun 2026 17:35:17 +0000 by eideticmnemonic

Algorithmic Problem Solving Techniques and Implementations

Equalizing Card Piles (Greedy Approach) To distribute cards equally among $N$ piles, calculate the average number of cards per pile and subtract this value from each pile's count. This transforms the problem into finding the minimum number of moves to zero out the differences. Iterating from left to right, if a pile has a non-zero discrpeancy, ...

Posted on Wed, 10 Jun 2026 16:32:25 +0000 by bdichiara

Generating Valid IP Addresses and Subsets from Given Inputs

Valid IP Address Generation Given a string containing only digits, geenrate all possbile valid IP address combinations. A valid IP address consists of four integers between 0-255 separated by dots, with no leading zeros. class IPGenerator { vector<string> validIPs; bool isValidSegment(const string& s, int start, int end) ...

Posted on Tue, 09 Jun 2026 16:46:05 +0000 by Coronet

Backtracking Algorithms for Combination Sum and Palindrome Partitioning

Combination Sum The objective is to find all unique combinations from a list of candidate numbers that sum up to a given target. Each number may be used multiple times. The solution uses recursive backtracking with the following approach: Parameters include the candidate array, target value, current combination, and results collection Terminat ...

Posted on Fri, 05 Jun 2026 17:01:53 +0000 by abushahin

Backtracking Algorithms: A Comprehensive Introduction

Core Concept Backtracking is a systematic search technique that explores all possible solutions by building candidates incrementally and abandoning ("backtracking") a candidate as soon as it determines that the candidate cannot possibly lead to a valid solution. Problems Addressed Backtracking effectively solves the following categori ...

Posted on Sat, 30 May 2026 20:01:14 +0000 by kuri7548

Backtracking Algorithms for Combination Sum and Palindrome Partitioning

Combination Sum (Problem 39) Given a distinct integer array candidates and a target value target, find all unique combinations in candidates where the numbers sum to target. Each number may be used repeatedly. The solution uses backtracking with these key components: Parameters: The recursive function tracks the current sum, path, and starting ...

Posted on Tue, 26 May 2026 18:10:30 +0000 by mfindlay

Implementing Grid-Based Word Search Using Depth-First Search

The task requires determining if a target sequence of characters exists within a two-dimensional matrix. The characters must be formed by traversing adjacent cells horizontally or vertically, ensuring no cell is reused during the path construction for a single attempt. Problem Constraints: Input: A 2D character array board and a string word. O ...

Posted on Sun, 24 May 2026 18:06:08 +0000 by TheSaint97

Algorithmic Solutions for Programming Competition Problems

Everyone Loves to Sleep Convert all times to minutes and store in a sorted set. Use binary search to find the nearest alarm time. If no alarm exists after bedtime, calculate duration untill first alarm next day. #include <iostream> #include <set> #include <climits> using namespace std; void calculateSleepDuration() { int ...

Posted on Fri, 22 May 2026 16:54:24 +0000 by Salkcin

Determining Feasibility of Safe Aircraft Landing Sequence with Single Runway

Problem Description N aircraft are preparing to land at an airport with only one runway. The i-th aircraft arrives above the airport at time Ti and has enough remaining fuel to continue circling for Di units of time. This means it can begin landing at the earleist at time Ti, and at the latest at time Ti + Di. The landing process itself require ...

Posted on Sun, 17 May 2026 06:05:57 +0000 by inkfish

Backtracking the N-Queens Puzzle with Early Output

Given an n × n chessboard, place n queens so that no two attack each other. A valid placement guarantees exactly one queen per row and per column, and at most one queen on every diagonal (both positive and negative slopes). The task is to enumerate every valid configuration, print the first three in lexicographical order, and finally output the ...

Posted on Sat, 16 May 2026 16:22:06 +0000 by mtucker6784