Skip to content

Commit bf6c7e7

Browse files
Zanger67/leetcodeZanger67/leetcode
authored andcommitted
Updated markdown files
1 parent 6936225 commit bf6c7e7

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

markdowns/Questions_By_Code_Length.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ Calculations are based on the code files's byte sizes.
8383
| 1743 | [Restore the Array From Adjacent Pairs](<https://leetcode.com/problems/restore-the-array-from-adjacent-pairs>) | Medium | | [solution](<_1743. Restore the Array From Adjacent Pairs.md>) | py | Jun 27, 2024 |
8484
| 846 | [Hand of Straights](<https://leetcode.com/problems/hand-of-straights>) | Medium | Daily, N150 | [solution](<_846. Hand of Straights.md>) | py | Jun 06, 2024 |
8585
| 75 | [Sort Colors](<https://leetcode.com/problems/sort-colors>) | Medium | Daily | [solution](<_75. Sort Colors.md>) | c, py | Jun 12, 2024 |
86+
| 1415 | [The k-th Lexicographical String of All Happy Strings of Length n](<https://leetcode.com/problems/the-k-th-lexicographical-string-of-all-happy-strings-of-length-n>) | Medium | Daily | [solution](<_1415. The k-th Lexicographical String of All Happy Strings of Length n.md>) | py | Feb 19, 2025 |
8687
| 641 | [Design Circular Deque](<https://leetcode.com/problems/design-circular-deque>) | Medium | | [solution](<_641. Design Circular Deque.md>) | py | Sep 30, 2024 |
8788
| 3045 | [Count Prefix and Suffix Pairs II](<https://leetcode.com/problems/count-prefix-and-suffix-pairs-ii>) | Hard | | [solution](<_3045. Count Prefix and Suffix Pairs II.md>) | py | Jun 29, 2024 |
8889
| 3213 | Weekly Contest 405 - q4 - [Construct String with Minimum Cost](<https://leetcode.com/problems/construct-string-with-minimum-cost>) | Hard | Contest | [solution](<_3213. Construct String with Minimum Cost.md>) | py | Jul 07, 2024 |
@@ -294,7 +295,6 @@ Calculations are based on the code files's byte sizes.
294295
| 2396 | [Strictly Palindromic Number](<https://leetcode.com/problems/strictly-palindromic-number>) | Medium | | [solution](<_2396. Strictly Palindromic Number.md>) | c, cpp, java, js, kt, py, rb, rs | Jun 09, 2024 |
295296
| 1833 | [Maximum Ice Cream Bars](<https://leetcode.com/problems/maximum-ice-cream-bars>) | Medium | | [solution](<_1833. Maximum Ice Cream Bars.md>) | c, java, py | Jun 23, 2024 |
296297
| 113 | [Path Sum II](<https://leetcode.com/problems/path-sum-ii>) | Medium | | [solution](<_113. Path Sum II.md>) | py | Jul 03, 2024 |
297-
| 1415 | [The k-th Lexicographical String of All Happy Strings of Length n](<https://leetcode.com/problems/the-k-th-lexicographical-string-of-all-happy-strings-of-length-n>) | Medium | Daily | [solution](<_1415. The k-th Lexicographical String of All Happy Strings of Length n.md>) | py | Feb 19, 2025 |
298298
| 129 | [Sum Root to Leaf Numbers](<https://leetcode.com/problems/sum-root-to-leaf-numbers>) | Medium | | [solution](<_129. Sum Root to Leaf Numbers.md>) | py | Jun 07, 2024 |
299299
| 1701 | [Average Waiting Time](<https://leetcode.com/problems/average-waiting-time>) | Medium | Daily | [solution](<_1701. Average Waiting Time.md>) | js, py | Jul 09, 2024 |
300300
| 2704 | [To Be Or Not To Be](<https://leetcode.com/problems/to-be-or-not-to-be>) | Easy | | [solution](<_2704. To Be Or Not To Be.md>) | js | Jul 09, 2024 |

markdowns/_1415. The k-th Lexicographical String of All Happy Strings of Length n.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,52 @@
1818
1919
------
2020

21+
> ### V1
22+
>
23+
> My initial attempt which was quite optimal. Achieves $O(n)$ using combinatorics where $n$ is the length of the output string aka the input $n$.
24+
>
25+
> ### V2
26+
>
27+
> A oneliner I produced with walrus operators. Both in an expanded "bit more readable" version and in the pure oneline state.
28+
>
29+
30+
------
31+
2132
## Solutions
2233

34+
- [m1415 v2 cursed oneliner expanded.py](<../my-submissions/m1415 v2 cursed oneliner expanded.py>)
35+
- [m1415 v2 oneliner.py](<../my-submissions/m1415 v2 oneliner.py>)
2336
- [m1415.py](<../my-submissions/m1415.py>)
2437
### Python
38+
#### [m1415 v2 cursed oneliner expanded.py](<../my-submissions/m1415 v2 cursed oneliner expanded.py>)
39+
```Python
40+
class Solution:
41+
def getHappyString(self, n: int, k: int) -> str:
42+
return (
43+
_pm_dfs := (
44+
lambda rem, n, output:
45+
''.join(output) if not n else
46+
_pm_dfs(
47+
rem - (pot_per_path if (temp := int(rem > (pot_per_path := 2 ** (n - 1)))) else 0),
48+
n - 1,
49+
output + ['abc'.replace(output[-1], '')[temp]]
50+
)
51+
)
52+
)(
53+
k - x * pot_n_min_1,
54+
n,
55+
[chr(ord('a') + x)]
56+
) if (x := (k - 1) // (pot_n_min_1 := 2 ** (n := n - 1))) <= 2 else \
57+
''
58+
```
59+
60+
#### [m1415 v2 oneliner.py](<../my-submissions/m1415 v2 oneliner.py>)
61+
```Python
62+
class Solution:
63+
def getHappyString(self, n: int, k: int) -> str:
64+
return (_pm_dfs := (lambda rem, n, output: ''.join(output) if not n else _pm_dfs(rem - (pot_per_path if (temp := int(rem > (pot_per_path := 2 ** (n - 1)))) else 0), n - 1, output + ['abc'.replace(output[-1], '')[temp]])))(k - x * pot_n_min_1,n, [chr(ord('a') + x)]) if (x := (k - 1) // (pot_n_min_1 := 2 ** (n := n - 1))) <= 2 else ''
65+
```
66+
2567
#### [m1415.py](<../my-submissions/m1415.py>)
2668
```Python
2769
class Solution:

0 commit comments

Comments
 (0)