Mid
From PDF
Coding
C# Coding Interview
Find All Subsets (Power Set)?
Short answer: List<List<int>> Subsets(int[] nums)
Example code
{
List<List<int>> result = new List<List<int>>(); GenerateSubsets(nums, 0, new List<int>(), result); return result;
} void GenerateSubsets(int[] nums, int index, List<int> current, List<List<int>> result)
{
if (index == nums.Length)
{ result.Add(new List<int>(current)); return;
} // Exclude nums[index] GenerateSubsets(nums, index + 1, current, result); // Include nums[index] current.Add(nums[index]); GenerateSubsets(nums, index + 1, current, result); current.RemoveAt(current.Count - 1); Follow on: } Explanation: Backtracking approach includes/excludes each element.
Real-world example (ShopNest)
In coding rounds, state complexity aloud, write a clear ShopNest-flavored example (orders, carts), then handle edge cases (empty list, null, overflow).
Say this in the interview
- Define — one clear sentence (the short answer above).
- Example — relate it to a project like ShopNest or your real work.
- Trade-off — when you would not use it.
Share this Q&A
Share preview image: https://www.toolliyo.com/images/toolliyo-logo.png