-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Weekly contest 405 - First time getting 3/4 and for some reason it w…
…as Qs 1, 2, and 4 but not 3 lol
- Loading branch information
Showing
57 changed files
with
641 additions
and
423 deletions.
There are no files selected for viewing
Submodule .Readme Updater
updated
from 003fa6 to 66408b
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# 3210. w contest 405 - q1 | ||
|
||
*All prompts are owned by LeetCode. To view the prompt, click the title link above.* | ||
|
||
*[Back to top](<../README.md>)* | ||
|
||
------ | ||
|
||
> *First completed : July 06, 2024* | ||
> | ||
> *Last updated : July 06, 2024* | ||
|
||
------ | ||
|
||
> **Related Topics** : **[N](<by_topic/N.md>), [/](</.md>), [A](<by_topic/A.md>)** | ||
> | ||
> **Acceptance Rate** : **Unknown** | ||
|
||
------ | ||
|
||
## Solutions | ||
|
||
- [w contest 405/e3210 q1.py](<../my-submissions/w contest 405/e3210 q1.py>) | ||
### Python | ||
#### [e3210 q1.py](<../my-submissions/w contest 405/e3210 q1.py>) | ||
```Python | ||
class Solution: | ||
def getEncryptedString(self, s: str, k: int) -> str: | ||
k %= len(s) | ||
return s[k:] + s[:k] | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# 3211. w contest 405 - q2 | ||
|
||
*All prompts are owned by LeetCode. To view the prompt, click the title link above.* | ||
|
||
*[Back to top](<../README.md>)* | ||
|
||
------ | ||
|
||
> *First completed : July 06, 2024* | ||
> | ||
> *Last updated : July 06, 2024* | ||
|
||
------ | ||
|
||
> **Related Topics** : **[N](<by_topic/N.md>), [/](</.md>), [A](<by_topic/A.md>)** | ||
> | ||
> **Acceptance Rate** : **Unknown** | ||
|
||
------ | ||
|
||
## Solutions | ||
|
||
- [w contest 405/m3211 q2.py](<../my-submissions/w contest 405/m3211 q2.py>) | ||
### Python | ||
#### [m3211 q2.py](<../my-submissions/w contest 405/m3211 q2.py>) | ||
```Python | ||
class Solution: | ||
def validStrings(self, n: int) -> List[str]: | ||
output = [] | ||
|
||
def dfs(curr: List[str], | ||
output: List[str], | ||
remaining: int, | ||
prevIsOne: bool) -> None : | ||
if not remaining : | ||
output.append(''.join(curr)) | ||
return | ||
|
||
curr.append('1') | ||
remaining -= 1 | ||
dfs(curr, output, remaining, True) | ||
curr.pop() | ||
|
||
if prevIsOne : | ||
curr.append('0') | ||
dfs(curr, output, remaining, False) | ||
curr.pop() | ||
dfs([], output, n, True) | ||
return output | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# 3213. w contest 405 - q4 | ||
|
||
*All prompts are owned by LeetCode. To view the prompt, click the title link above.* | ||
|
||
*[Back to top](<../README.md>)* | ||
|
||
------ | ||
|
||
> *First completed : July 06, 2024* | ||
> | ||
> *Last updated : July 06, 2024* | ||
|
||
------ | ||
|
||
> **Related Topics** : **[N](<by_topic/N.md>), [/](</.md>), [A](<by_topic/A.md>)** | ||
> | ||
> **Acceptance Rate** : **Unknown** | ||
|
||
------ | ||
|
||
## Solutions | ||
|
||
- [w contest 405/h3213 q4.py](<../my-submissions/w contest 405/h3213 q4.py>) | ||
- [w contest 405/h3213.md](<../my-submissions/w contest 405/h3213.md>) | ||
### Python | ||
#### [h3213 q4.py](<../my-submissions/w contest 405/h3213 q4.py>) | ||
```Python | ||
class Solution: | ||
def minimumCost(self, target: str, words: List[str], costs: List[int]) -> int: | ||
wordToCost = {} | ||
for w, c in zip(words, costs) : | ||
if w in wordToCost and wordToCost[w] <= c : | ||
continue | ||
wordToCost[w] = c | ||
|
||
words = sorted(list(set(words)), key=lambda x: len(x)) | ||
maxWrd = len(words) - 1 | ||
|
||
dp = [0] + [inf] * len(target) | ||
|
||
for i in range(len(target)) : | ||
while maxWrd >= 0 and len(words[maxWrd]) > len(target) - i : | ||
maxWrd -= 1 | ||
if maxWrd < 0 : | ||
break | ||
|
||
for word in words[:maxWrd + 1] : | ||
if word == target[i:i+len(word)] : | ||
dp[i + len(word)] = min(dp[i + len(word)], dp[i] + wordToCost[word]) | ||
|
||
return -1 if dp[-1] == inf else dp[-1] | ||
|
||
``` | ||
|
||
### md | ||
#### [h3213.md](<../my-submissions/w contest 405/h3213.md>) | ||
```md | ||
Did the contest live and got through Q1 & Q2 very quickly. When I saw Q3 however, | ||
I got really confused so I decided to just skip it for now. Somehow, I was able to get | ||
Q4 then when I got back to Q3, I realized what the solution was and laid out the steps, | ||
but didn't have enough time to implement it. So yeah... good contest lol. First time | ||
getting 3 questions too funny enough lol. | ||
``` | ||
|
Oops, something went wrong.