Spaces:
Configuration error
Configuration error
File size: 4,525 Bytes
69fca97 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 | <!DOCTYPE html>
<html lang="en" class="dark">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, initial-scale=1.0">
<title>Subsets | DSA Portfolio</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="../assets/style.css">
<link rel="preconnect"
href="https://fonts.googleapis.com">
<link
href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;700;800&family=JetBrains+Mono:wght@400;500&display=swap"
rel="stylesheet">
</head>
<body class="bg-slate-950 text-white font-inter">
<!-- Header -->
<header class="border-b border-white/10">
<div class="max-w-7xl mx-auto px-6 py-5">
<a href="../index.html"
class="text-cyan-400">
← Back to Portfolio
</a>
</div>
</header>
<!-- Main -->
<main class="max-w-7xl mx-auto px-6 py-16 grid lg:grid-cols-3 gap-10">
<!-- Content -->
<section class="lg:col-span-2">
<p class="text-cyan-400 font-mono">
Recursion / Backtracking
</p>
<h1 class="text-5xl font-black mt-4">
Subsets
</h1>
<p class="text-slate-400 mt-6 text-lg">
Generate all possible subsets of a given array using recursion and backtracking.
</p>
<!-- Intuition -->
<div class="mt-14">
<h2 class="text-3xl font-bold">
Intuition
</h2>
<p class="text-slate-300 mt-5 leading-8">
For every element we have two choices:
either include it in the subset or exclude it.
This naturally forms a recursion tree.
</p>
</div>
<!-- Algorithm -->
<div class="mt-14">
<h2 class="text-3xl font-bold">
Algorithm
</h2>
<ol class="mt-5 space-y-3 text-slate-300 list-decimal list-inside">
<li>Start recursion from index 0</li>
<li>Include current element</li>
<li>Move to next index</li>
<li>Backtrack by removing element</li>
<li>Exclude current element</li>
</ol>
</div>
<!-- Dry Run -->
<div class="mt-14">
<h2 class="text-3xl font-bold">
Dry Run
</h2>
<div class="mt-5 p-6 rounded-2xl bg-white/5 border border-white/10 font-mono">
[] <br>
[1] <br>
[1,2] <br>
[2]
</div>
</div>
<!-- Code -->
<div class="mt-14">
<h2 class="text-3xl font-bold">
Python Solution
</h2>
<pre
class="mt-5 p-6 rounded-2xl bg-black overflow-x-auto border border-white/10 text-sm code-block">
<code>
class Solution:
def subsets(self, nums):
ans = []
def backtrack(i, curr):
if i == len(nums):
ans.append(curr[:])
return
curr.append(nums[i])
backtrack(i + 1, curr)
curr.pop()
backtrack(i + 1, curr)
backtrack(0, [])
return ans
</code>
</pre>
</div>
</section>
<!-- Sidebar -->
<aside>
<div class="sticky top-10 p-6 rounded-3xl bg-white/5 border border-white/10">
<h2 class="text-2xl font-bold">
Problem Info
</h2>
<div class="mt-8 space-y-5">
<div>
<p class="text-slate-400 text-sm">
Difficulty
</p>
<p class="text-yellow-400 font-semibold">
Medium
</p>
</div>
<div>
<p class="text-slate-400 text-sm">
Topic
</p>
<p>
Recursion
</p>
</div>
<div>
<p class="text-slate-400 text-sm">
Time Complexity
</p>
<p>
O(2^n)
</p>
</div>
<div>
<p class="text-slate-400 text-sm">
Space Complexity
</p>
<p>
O(n)
</p>
</div>
<div>
<p class="text-slate-400 text-sm">
Platform
</p>
<p>
LeetCode
</p>
</div>
<div>
<p class="text-slate-400 text-sm">
Date Solved
</p>
<p>
2026-05-08
</p>
</div>
</div>
</div>
</aside>
</main>
</body>
</html> |