Comprehensive Guide to Python Lists
1. List Problem: Maximum Product Subarray
**Scenario:** Given a list of integers (both positive and negative), find the contiguous subarray that has the maximum
product.
**Input:**
`input_list = [2, 3, -2, 4, -1]`
**Expected Output:** `48` (from subarray `[2, 3, -2, 4]`)
2. List Problem: Longest Increasing Subsequence (LIS)
**Scenario:** Find the length of the longest increasing subsequence in a list of integers.
**Input:**
`input_list = [10, 9, 2, 5, 3, 7, 101, 18]`
**Expected Output:** `4` (from the subsequence `[2, 3, 7, 101]`)
3. Set Problem: Smallest Missing Positive Integer
**Scenario:** Given a list of integers, find the smallest positive integer that does not exist in the list using set operations.
**Input:**
Page 1
Comprehensive Guide to Python Lists
`input_list = [3, 4, -1, 1]`
**Expected Output:** `2`
4. Set Problem: Power Set of a Set
**Scenario:** Generate the power set of a given set using recursion.
**Input:**
`input_set = {1, 2, 3}`
**Expected Output:** `[{}, {1}, {2}, {3}, {1, 2}, {1, 3}, {2, 3}, {1, 2, 3}]`
5. Tuple Problem: Maximum Sum of Non-Adjacent Elements
**Scenario:** Given a tuple of integers, find the maximum sum you can get by selecting non-adjacent elements.
**Input:**
`input_tuple = (3, 2, 7, 10)`
**Expected Output:** `13` (selecting `3` and `10`)
6. Tuple Problem: Kth Permutation of Elements in a Tuple
Page 2
Comprehensive Guide to Python Lists
**Scenario:** Given a tuple of distinct integers, find the kth permutation of its elements.
**Input:**
`input_tuple = (1, 2, 3)`, `k = 4`
**Expected Output:** `(2, 3, 1)` (the 4th permutation of `(1, 2, 3)`)
7. Dictionary Problem: Nested Dictionary Sum
**Scenario:** Given a nested dictionary, find the sum of all values (assuming values are integers).
**Input:**
```python
nested_dict = {'a': 5, 'b': {'c': 10, 'd': {'e': 2}}, 'f': 7}
```
**Expected Output:** `24`
8. Dictionary Problem: Find Most Frequent Word Pair in Text
**Scenario:** Given a large string of text, find the most frequent consecutive word pair using a dictionary to count
occurrences.
**Input:**
Page 3
Comprehensive Guide to Python Lists
`text = "the cat and the dog and the cat chased the dog"`
**Expected Output:** `"the cat"`
9. Mixed Problem: Find All Pairs of Integers That Sum to a Target Using Dictionary
**Scenario:** Given a list of integers, find all unique pairs that sum to a given target.
**Input:**
`input_list = [1, 5, 7, -1, 5]`, `target = 6`
**Expected Output:** `[(1, 5), (7, -1)]`
10. Mixed Problem: Word Break Problem
**Scenario:** Given a string `s` and a dictionary of valid words `word_dict`, check if `s` can be segmented into valid
words.
**Input:**
`s = "leetcode"`, `word_dict = ["leet", "code"]`
**Expected Output:** `True` (since `"leetcode"` can be split as `"leet"` + `"code"`)
Page 4