LeetCode Weekly Contest 169 Solutions

Problem 1: Find N Unique Integers Sum up to Zero Given an integer n, any array of n unique integers that sum to 0 can be returned. Example 1: Input: n = 5 Output: [-7,-1,1,3,4] Explanation: These arrays are also correct [-5,-1,1,2,3], [-3,-1,2,-2,4]. Example 2: Input: n = 3 Output: [-1,0,1] Example 3: Input: n = 1 Output: [0] Constraints: 1 &l ...

Posted on Tue, 03 Nov 2026 16:11:59 +0000 by Zoud

Advanced Backtracking Approaches: IP Reconstruction and Subset Construction

Restoring Valid IPv4 Addresses Generating all possible valid IP address strings from a numeric sequence requires dividing the input into four segments where each part falls between 0 and 255. Leading zeros are not permitted unless the segment is exactly "0". A backtracking approach iterates through potential split points, validating s ...

Posted on Fri, 30 Oct 2026 16:47:19 +0000 by IMakeLousyCode

Understanding Backtracking Fundamentals and Combinatorial Generation

Core Principles of Backtracking Backtracking operates as an exhaustive search mechanism built upon recursive execution. Rather than optimizing pathfinding, it systematically evaluates every viable candidate configuration until valid outcomes are isolated. Although computationally expensive, this approach remains necessary for combinatorial doma ...

Posted on Fri, 30 Oct 2026 16:27:21 +0000 by Mr Camouflage

Algorithms for Palindrome Partitioning: Minimum Cuts and Exhaustive Generation

Palindrome partitioning is a common algorithmic challenge that involves splitting a string into several segments, where each segment reads the same forwards and backwards. This article explores two distinct variations of this problem: finding the minimum number of cuts required and generating all possible valid partitions. 1. Calculating the Mi ...

Posted on Fri, 30 Oct 2026 16:07:14 +0000 by graziano

Understanding Recursion Execution Flow and Backtracking in Tree Path Problems

The placement of code relative to a recursive call determines when it executes. Code placed before the recursive call runs during the stacking phase—when the function is first entered. Converse, code placed after the recursive call runs during the unstacking phase—after the recursive call returns. Consider this example demonstrating pre-recursi ...

Posted on Fri, 30 Oct 2026 16:03:46 +0000 by fallen_angel21

Implementing Backtracking Algorithms in Java with Practical Examples

Backtracking Fundamentals class BacktrackDemo { static void recursiveDemo(int step, LinkedList<String> path) { if (step == 3) return; System.out.println("Entering: " + path); path.add("step"); recursiveDemo(step + 1, path); path.removeLast(); System.out.print ...

Posted on Thu, 29 Oct 2026 16:05:31 +0000 by JonathanV

Backtracking Algorithms for Combination and Palindrome Partitioning

Problem 1: Combination Sum Given an array of distinct integers candidates and a target integer target, find all unique combinations where the chosen numbers sum to target. Each number may be used unlimited times. Algorithm Approach: The solution uses backtracking with a key condition: when exploring further elements, we start from the current i ...

Posted on Mon, 26 Oct 2026 16:50:21 +0000 by shortkid422

Dynamic Programming Patterns for Counting, Subset Sum, and Knapsack Variants

Counting Unique Binary Search Trees A binary search tree requires that all keys in the left subtree are smaller than the root, and all keys in the right subtree are larger. The number of structurally unique BSTs that store n distinct values depends only on n. Let ways[i] be the number of unique BSTs with i nodes. For the root, if the left subtr ...

Posted on Fri, 23 Oct 2026 16:34:32 +0000 by phpisawesome

Generating Unique Subsets from an Array with Duplicates

This problem requires generating all possible subsets (the power set) of an integer array that may contain duplicate elements. The solution must ensure that the resulting list of subsets contains no duplicates, although the subsets themselves may be returned in any order. For example, given the input nums = [1, 2, 2], the valid output includes ...

Posted on Mon, 19 Oct 2026 16:31:11 +0000 by Pickle

Essential Binary Tree Operations: Finding Bottom Left Value, Path Sum Variations, and Inorder-Postorder Construction

Finding the Bottom Left Tree ValueLocating the leftmost value in the last row of a binary tree can be efficiently achieved using Breadth-First Search (BFS). By processing the tree level by level, the first node encountered at each depth represents the leftmost node for that specific row. Upon completing the traversal, the value recorded for the ...

Posted on Sun, 18 Oct 2026 16:30:55 +0000 by batman