|
| 1 | +# Day 27 |
| 2 | + |
| 3 | +## ⭐️ Relative Ranks – 27.1 |
| 4 | +### 🔗 Problem |
| 5 | +[LeetCode #506 – Relative Ranks](https://leetcode.com/problems/relative-ranks/) |
| 6 | + |
| 7 | +### 🧠 Core Idea |
| 8 | +Pair each score with its original index, sort scores in descending order, and assign medals to the top three athletes ("Gold Medal", "Silver Medal", "Bronze Medal"). |
| 9 | +For the remaining athletes, assign their rank number as a string. |
| 10 | +Place the results back into their original positions to preserve input order. |
| 11 | + |
| 12 | +### 📊 Example |
| 13 | +Input: `score = \[10,3,8,9,4]` |
| 14 | + |
| 15 | +Output: \["Gold Medal","5","Bronze Medal","Silver Medal","4"] |
| 16 | + |
| 17 | +### ⏱️ Complexity |
| 18 | +- Time: O(n log n) – Sorting the scores |
| 19 | + |
| 20 | +- Space: O(n) – For the result array and index pairs |
| 21 | + |
| 22 | +👉 See full code in [relative_ranks.py](https://github.com/lyushher/LeetCode-Python-Easy-DSA/blob/main/day-27/relative_ranks.py) |
| 23 | + |
| 24 | +--- |
| 25 | + |
| 26 | +## ⭐️ Find the Difference – 27.2 |
| 27 | +### 🔗 Problem |
| 28 | +[LeetCode #389 – Find the Difference](https://leetcode.com/problems/find-the-difference/) |
| 29 | + |
| 30 | +### 🧠 Core Idea |
| 31 | +The extra character in string `t` can be found by XORing all characters in `s` and `t`. Matching characters cancel out, leaving only the added character. |
| 32 | +Alternatively, compute the difference of ASCII sums of `t` and `s`. |
| 33 | +Both methods work in linear time and constant space. |
| 34 | + |
| 35 | +### 📊 Example |
| 36 | +Input: s = "abcd", t = "abcde" |
| 37 | + |
| 38 | +Output: "e" → Because "e" is the extra character in `t` |
| 39 | + |
| 40 | +### ⏱️ Complexity |
| 41 | +- Time: O(n) – One pass through both strings |
| 42 | + |
| 43 | +- Space: O(1) – Only a few variables used |
| 44 | + |
| 45 | +👉 See full code in [find_the_difference.py](https://github.com/lyushher/LeetCode-Python-Easy-DSA/blob/main/day-27/find_the_difference.py) |
0 commit comments