|
| 1 | +# Day 26 |
| 2 | + |
| 3 | +## ⭐️ Move Zeroes – 26.1 |
| 4 | +### 🔗 Problem |
| 5 | +[LeetCode #283 – Move Zeroes](https://leetcode.com/problems/move-zeroes/) |
| 6 | + |
| 7 | +### 🧠 Core Idea |
| 8 | +Use a two-pointer approach to shift all non-zero elements forward while maintaining their relative order. |
| 9 | +One pointer (last_non_zero) marks the next position to place a non-zero, while the other scans through the array. |
| 10 | +After placing all non-zero values, fill the remaining positions with zeros. |
| 11 | +This ensures the operation is in-place and preserves order. |
| 12 | + |
| 13 | +### 📊 Example |
| 14 | +Input: `nums = [0,1,0,3,12]` |
| 15 | + |
| 16 | +Output: [1,3,12,0,0] |
| 17 | + |
| 18 | +### ⏱️ Complexity |
| 19 | +- Time: O(n) – Single pass through the array plus one pass to fill zeros |
| 20 | + |
| 21 | +- Space: O(1) – In-place, no extra structures |
| 22 | + |
| 23 | +👉 See full code in [move_zeroes.py](https://github.com/lyushher/LeetCode-Python-Easy-DSA/blob/main/day-26/move_zeroes.py) |
| 24 | + |
| 25 | +--- |
| 26 | + |
| 27 | +## ⭐️ Find All Numbers Disappeared in an Array – 26.2 |
| 28 | +### 🔗 Problem |
| 29 | +[LeetCode #448 – Find All Numbers Disappeared in an Array](https://leetcode.com/problems/find-all-numbers-disappeared-in-an-array/) |
| 30 | + |
| 31 | +### 🧠 Core Idea |
| 32 | +Since numbers are within the range [1, n], we can mark visited indices by flipping the sign of the element at abs(x) - 1. |
| 33 | +After one pass, the indices that remain positive indicate the missing numbers. |
| 34 | +Collect those indices + 1 as the result. |
| 35 | +This avoids extra memory usage and leverages in-place marking. |
| 36 | + |
| 37 | +### 📊 Example |
| 38 | +Input: `nums = [4,3,2,7,8,2,3,1]` |
| 39 | + |
| 40 | +Output: [5,6] -> Because 5 and 6 are not present in the array |
| 41 | + |
| 42 | +### ⏱️ Complexity |
| 43 | +- Time: O(n) – Single pass to mark and one pass to collect |
| 44 | +- |
| 45 | +- Space: O(1) – In-place marking (excluding output list) |
| 46 | + |
| 47 | +👉 See full code in [find_all_numbers_disappeared_in_an_array.py](https://github.com/lyushher/LeetCode-Python-Easy-DSA/blob/main/day-26/find_all_numbers_disappeared_in_an_array.py) |
0 commit comments