Skip to content

Commit 24b17dc

Browse files
committed
Feb 19
1 parent 2525345 commit 24b17dc

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

2025-02-February-LeetCoding-Challenge/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
| February 16 | [1718. Construct the Lexicographically Largest Valid Sequence](https://leetcode.com/problems/construct-the-lexicographically-largest-valid-sequence/) | Medium | Unsolved |
2323
| February 17 | [1079. Letter Tile Possibilities](https://leetcode.com/problems/letter-tile-possibilities/) | Medium | Solved |
2424
| February 18 | [2375. Construct Smallest Number From DI String](https://leetcode.com/problems/construct-smallest-number-from-di-string/) | Medium | Unsolved |
25-
| February 19 | []() | | |
25+
| February 19 | [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 | Unsolved |
2626
| February 20 | []() | | |
2727
| February 21 | []() | | |
2828
| February 22 | []() | | |
@@ -38,5 +38,5 @@
3838
| Level | Problems | Solved | Unsolved |
3939
| --- | --- | --- | --- |
4040
| Easy | 6 | 6 | 0 |
41-
| Medium | 11 | 9 | 2 |
41+
| Medium | 12 | 9 | 3 |
4242
| Hard | 0 | 0 | 0 |
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from collections import deque
2+
3+
4+
class Solution:
5+
def getHappyString(self, n: int, k: int) -> str:
6+
next_map = {'a': 'bc', 'b': 'ac', 'c': 'ab'}
7+
queue = deque(next_map.keys())
8+
while len(queue[0]) != n:
9+
u = queue.popleft()
10+
for v in next_map[u[-1]]:
11+
queue.append(u + v)
12+
return queue[k-1] if len(queue) >= k else ''
13+
14+
15+
def main():
16+
n = 1
17+
k = 3
18+
assert Solution().getHappyString(n, k) == 'c'
19+
20+
n = 1
21+
k = 4
22+
assert Solution().getHappyString(n, k) == ''
23+
24+
n = 3
25+
k = 9
26+
assert Solution().getHappyString(n, k) == 'cab'
27+
28+
29+
if __name__ == '__main__':
30+
main()

0 commit comments

Comments
 (0)