Generating All Permutations of an Array

Given an array nums containing distinct integers, return all possible permutations. You may return the answer in any order. Example 1: <strong>Input:</strong> nums = [1,2,3] <strong>Output:</strong> [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]] Example 2: <strong>Input:</strong> nums = [0,1] <strong&g ...

Posted on Wed, 29 Jul 2026 16:21:02 +0000 by onicsoft

Four Tasks from a Beginner Contest: Permutation Duel, Sub-grid Matching, Hamiltonian Walks, and Optimal Chemical Blending

Task A – Permutation Duel A cyclic permutation maps [1\to2\to3\to\dots\to13\to1] Two players choose indices (x,y\in[1,13]). Compare the images (p(x)) and (p(y)); output the winner or "Draw". int main() { int x, y; std::cin >> x >> y; int px = (x == 13 ? 1 : x + 1); int py = (y == 13 ? 1 : y + 1); if (px == ...

Posted on Fri, 15 May 2026 19:42:06 +0000 by NathanLedet

Backtracking with Element Tracking for Deduplication

Problem 491: Non-decreasing Subsequences Given an integer array nums, return all the different non-decreasing subsequences that have atleast two elements. The answer can be in any order. When two integers are equal, this counts as a valid increasing sequecne. Example 1: Input: nums = [4,6,7,7] Output: [[4,6],[4,6,7],[4,6,7,7],[4,7],[4,7,7],[6,7 ...

Posted on Fri, 08 May 2026 23:26:45 +0000 by mcccy005

Foundations of Search: Classic Problems and Algorithmic Insights

A: Chessboard Rook Placement Given an (n \times n) board where certain positions marked # allow placement, determine the number of ways to place (k) identical, non-attacking rooks. Constraints: (k \leq n \leq 8). Since each row can hold at most one rook, a depth-first search over rows is feasible. The state space is bounded by ((n+1)^n), at mos ...

Posted on Thu, 07 May 2026 01:45:42 +0000 by benzrf