feat(content): add new problem pages, reorganize docs into (problems) subfolders, and update meta display to page

This commit is contained in:
Prad Nukala committed 2026-10-05 13:07:56 -04:00
1 parent 74939c31d7
commit ea62cda955
115 files changed
+174 -24

No files matched your search

@@ -0,0 +1,56 @@
---
title: '39. Combination Sum'
description: Given an array of distinct integers candidates and a target integer target, return a list of all unique combinations of candidates where the chosen numbers sum to target. You may return the combinations in any order
icon: dot
topics:
- { name: "Array", slug: "array" }
- { name: "Backtracking", slug: "backtracking" }
issue: "https://github.com/prdlk/leetcode/issues/150"
sidebar:
label: 'Combination Sum'
badge: 'Medium'
---
### Example 1:
- Input: `candidates = [2,3,6,7], target = 7`
- Output: `[[2,2,3],[7]]`
- Explanation: `2` and `3` are `candidates`, and `2 + 2 + 3 = 7`. Note that `2` can be used multiple times. `7` is a candidate, and `7 = 7`. These are the only two combinations.
### Example 2:
- Input: `candidates = [2,3,5], target = 8`
- Output: `[[2,2,2,2],[2,3,3],[3,5]]`
### Example 3:
- Input: `candidates = [2], target = 1`
- Output: `[]`
### Constraints:
- `1 <= candidates.length <= 30`
- `2 <= candidates[i] <= 40`
- All elements of `candidates` are distinct.
- `1 <= target <= 40`
## Solution
```py
class Solution:
def combinationSum(self, candidates: list[int], target: int) -> list[list[int]]:
candidates.sort()
result, path = [], []
def backtrack(start, remaining):
if remaining == 0:
result.append(path[:])
return
for i in range(start, len(candidates)):
if candidates[i] > remaining:
break
path.append(candidates[i])
backtrack(i, remaining - candidates[i])
path.pop()
backtrack(0, target)
return result
```
@@ -0,0 +1,55 @@
---
title: '46. Permutations'
description: Given an array nums of distinct integers, return all the possible permutations. You can return the answer in any order
icon: dot
topics:
- { name: "Array", slug: "array" }
- { name: "Backtracking", slug: "backtracking" }
issue: "https://github.com/prdlk/leetcode/issues/151"
sidebar:
label: 'Permutations'
badge: 'Medium'
---
### Example 1:
- Input: `nums = [1,2,3]`
- Output: `[[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]`
### Example 2:
- Input: `nums = [0,1]`
- Output: `[[0,1],[1,0]]`
### Example 3:
- Input: `nums = [1]`
- Output: `[[1]]`
### Constraints:
- `1 <= nums.length <= 6`
- `-10 <= nums[i] <= 10`
- All the integers of `nums` are unique.
## Solution
```py
class Solution:
def permute(self, nums: list[int]) -> list[list[int]]:
result, path = [], []
used = [False] * len(nums)
def backtrack():
if len(path) == len(nums):
result.append(path[:])
return
for i in range(len(nums)):
if used[i]:
continue
used[i] = True
path.append(nums[i])
backtrack()
path.pop()
used[i] = False
backtrack()
return result
```
@@ -0,0 +1,45 @@
---
title: '78. Subsets'
description: Given an integer array nums of unique elements, return all possible subsets (the power set)
icon: dot
topics:
- { name: "Array", slug: "array" }
- { name: "Backtracking", slug: "backtracking" }
- { name: "Bit Manipulation", slug: "bit-manipulation" }
issue: "https://github.com/prdlk/leetcode/issues/149"
sidebar:
label: 'Subsets'
badge: 'Medium'
---
### Example 1:
- Input: `nums = [1,2,3]`
- Output: `[[],[1],[2],[1,2],[3],[1,3],[2,3],[1,2,3]]`
### Example 2:
- Input: `nums = [0]`
- Output: `[[],[0]]`
### Constraints:
- `1 <= nums.length <= 10`
- `-10 <= nums[i] <= 10`
- All the numbers of `nums` are unique.
## Solution
```py
class Solution:
def subsets(self, nums: list[int]) -> list[list[int]]:
res = []
def backtrack(i, path):
res.append(path[:])
for num_idx in range(i, len(nums)):
path.append(nums[num_idx])
backtrack(num_idx + 1, path)
path.pop()
backtrack(0, [])
return res
```