Skip to content

Commit 5a72687

Browse files
committed
Update README.md format and enhance problem listing; add functionality to fetch problem stats
1 parent 76120cc commit 5a72687

File tree

2 files changed

+114
-26
lines changed

2 files changed

+114
-26
lines changed

README.md

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
1-
# Coding Everyday Until I Get A Job
2-
3-
## LeetCode Solutions
4-
5-
| # | Title | Solution | Type | Difficulty |
6-
|---| ----- | -------- | ---------- | ---------- |
7-
|0001|[Two Sum](https://leetcode.com/problems/two-sum/description/)|[Python](./array_hashing/0001-two-sum.py)|Array Hashing| Easy |
8-
|0020|[Valid Parentheses](https://leetcode.com/problems/valid-parentheses/description/)|[Python](./stack/0020-valid-parentheses.py)|Stack| Easy |
9-
|0049|[Group Anagrams](https://leetcode.com/problems/group-anagrams/description/)|[Python](./array_hashing/0049-group-anagrams.py)|Array Hashing| Medium |
10-
|0125|[Valid Palindrome](https://leetcode.com/problems/valid-palindrome/description/)|[Python](./two_pointers/0125-valid-palindrome.py)|Two Pointers| Easy |
11-
|0217|[Contains Duplicate](https://leetcode.com/problems/contains-duplicate/description/)|[Python](./array_hashing/0217-contains-duplicate.py)|Array Hashing| Easy |
12-
|0242|[Valid Anagram](https://leetcode.com/problems/valid-anagram/description/)|[Python](./array_hashing/0242-valid-anagram.py)|Array Hashing| Easy |
13-
|0347|[Top K Frequent Elements](https://leetcode.com/problems/top-k-frequent-elements/description/)|[Python](./array_hashing/0347-top-k-frequent-elements.py)|Array Hashing| Medium |
1+
# 📌 LeetCode Solutions - Coding Every Day Until I Get A Job
2+
3+
Welcome to my LeetCode solutions repository! 🚀 Here, I solve coding challenges every day to improve my problem-solving skills and prepare for technical interviews.
4+
5+
## 🔥 Problem List
6+
7+
| # | Title | Solution | Tags | Difficulty |
8+
|---| ----- | -------- | ---------- | ---- |
9+
|0001|[Two Sum](https://leetcode.com/problems/two-sum/description/)|[Python](./array_hashing/0001-two-sum.py)| Easy | Array, Hash Table |
10+
|0020|[Valid Parentheses](https://leetcode.com/problems/valid-parentheses/description/)|[Python](./stack/0020-valid-parentheses.py)| Easy | String, Stack |
11+
|0049|[Group Anagrams](https://leetcode.com/problems/group-anagrams/description/)|[Python](./array_hashing/0049-group-anagrams.py)| Medium | Array, Hash Table, String, Sorting |
12+
|0125|[Valid Palindrome](https://leetcode.com/problems/valid-palindrome/description/)|[Python](./two_pointers/0125-valid-palindrome.py)| Easy | Two Pointers, String |
13+
|0217|[Contains Duplicate](https://leetcode.com/problems/contains-duplicate/description/)|[Python](./array_hashing/0217-contains-duplicate.py)| Easy | Array, Hash Table, Sorting |
14+
|0242|[Valid Anagram](https://leetcode.com/problems/valid-anagram/description/)|[Python](./array_hashing/0242-valid-anagram.py)| Easy | Hash Table, String, Sorting |
15+
|0347|[Top K Frequent Elements](https://leetcode.com/problems/top-k-frequent-elements/description/)|[Python](./array_hashing/0347-top-k-frequent-elements.py)| Medium | Array, Hash Table, Divide and Conquer, Sorting, Heap (Priority Queue), Bucket Sort, Counting, Quickselect |
16+
17+
## 🚀 Keep Coding & Stay Motivated!
18+
19+
Happy coding! 😊

automata.py

Lines changed: 95 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,75 @@
1+
# import os
2+
# import re
3+
# import requests
4+
5+
# def extract_problem_info(file_path):
6+
# match = re.match(r"(\d+)-([a-z0-9-]+)\.py", os.path.basename(file_path))
7+
# if match:
8+
# problem_number, slug = match.groups()
9+
# return int(problem_number), slug, f"[{slug.replace('-', ' ').title()}](https://leetcode.com/problems/{slug}/description/)"
10+
# return None, None, None
11+
12+
# def get_problem_stats(slug):
13+
# url = "https://leetcode.com/graphql"
14+
# query = """
15+
# query getQuestionStats($titleSlug: String!) {
16+
# question(titleSlug: $titleSlug) {
17+
# difficulty
18+
# topicTags {
19+
# name
20+
# }
21+
# }
22+
# }
23+
# """
24+
# response = requests.post(url, json={"query": query, "variables": {"titleSlug": slug}})
25+
# try:
26+
# data = response.json()["data"]["question"]
27+
# difficulty = data["difficulty"]
28+
# tags = ", ".join(tag["name"] for tag in data["topicTags"])
29+
# return difficulty, tags
30+
# except (KeyError, TypeError):
31+
# return "Unknown", "Unknown"
32+
33+
# def build_readme():
34+
# topics = [d for d in os.listdir('.') if os.path.isdir(d)]
35+
# problem_entries = []
36+
37+
# for topic in topics:
38+
# for file in os.listdir(topic):
39+
# if file.endswith(".py"):
40+
# problem_number, slug, problem_title = extract_problem_info(file)
41+
# if problem_number:
42+
# difficulty, tags, accepted, submissions, acceptance_rate = get_problem_stats(slug)
43+
# problem_entries.append((problem_number, problem_title, f"[Python](./{topic}/{file})", difficulty, tags, accepted, submissions, acceptance_rate))
44+
45+
# problem_entries.sort()
46+
47+
# table_header = "| # | Title | Solution | Tags | Difficulty |\n|---| ----- | -------- | ---------- | ---- | -------- | ----------- | --------------- |"
48+
# table_rows = []
49+
50+
# for number, title, solution, tags, difficulty in problem_entries:
51+
# table_rows.append(f"|{number:04d}|{title}|{solution}| {tags} | {difficulty} | ")
52+
53+
# table_content = "\n".join([table_header] + table_rows)
54+
# readme_content = f"""# 📌 LeetCode Solutions - Coding Every Day Until I Get A Job
55+
56+
# Welcome to my LeetCode solutions repository! 🚀 Here, I solve coding challenges every day to improve my problem-solving skills and prepare for technical interviews.
57+
58+
# ## 🔥 Problem List
59+
60+
# {table_content}
61+
62+
# ## 🚀 Keep Coding & Stay Motivated!
63+
64+
# Happy coding! 😊"""
65+
66+
# with open("README.md", "w", encoding="utf-8") as f:
67+
# f.write(readme_content)
68+
69+
# if __name__ == "__main__":
70+
# build_readme()
71+
# print("README.md has been updated!")
72+
173
import os
274
import re
375
import requests
@@ -9,21 +81,26 @@ def extract_problem_info(file_path):
981
return int(problem_number), slug, f"[{slug.replace('-', ' ').title()}](https://leetcode.com/problems/{slug}/description/)"
1082
return None, None, None
1183

12-
def get_problem_difficulty(slug):
84+
def get_problem_stats(slug):
1385
url = "https://leetcode.com/graphql"
1486
query = """
15-
query getQuestionDifficulty($titleSlug: String!) {
87+
query getQuestionStats($titleSlug: String!) {
1688
question(titleSlug: $titleSlug) {
1789
difficulty
90+
topicTags {
91+
name
92+
}
1893
}
1994
}
2095
"""
2196
response = requests.post(url, json={"query": query, "variables": {"titleSlug": slug}})
2297
try:
23-
data = response.json()
24-
return data["data"]["question"]["difficulty"]
98+
data = response.json()["data"]["question"]
99+
difficulty = data["difficulty"]
100+
tags = ", ".join(tag["name"] for tag in data["topicTags"])
101+
return difficulty, tags
25102
except (KeyError, TypeError):
26-
return "Unknown"
103+
return "Unknown", "Unknown"
27104

28105
def build_readme():
29106
topics = [d for d in os.listdir('.') if os.path.isdir(d)]
@@ -34,24 +111,29 @@ def build_readme():
34111
if file.endswith(".py"):
35112
problem_number, slug, problem_title = extract_problem_info(file)
36113
if problem_number:
37-
difficulty = get_problem_difficulty(slug)
38-
problem_entries.append((problem_number, problem_title, f"[Python](./{topic}/{file})", topic.replace('_', ' ').title(), difficulty))
114+
difficulty, tags = get_problem_stats(slug)
115+
problem_entries.append((problem_number, problem_title, f"[Python](./{topic}/{file})", difficulty, tags))
39116

40117
problem_entries.sort()
41118

42-
table_header = "| # | Title | Solution | Type | Difficulty |\n|---| ----- | -------- | ---------- | ---------- |"
119+
table_header = "| # | Title | Solution | Tags | Difficulty |\n|---| ----- | -------- | ---------- | ---- |"
43120
table_rows = []
44121

45-
for number, title, solution, topic, difficulty in problem_entries:
46-
table_rows.append(f"|{number:04d}|{title}|{solution}|{topic}| {difficulty} |")
122+
for number, title, solution, tags, difficulty in problem_entries:
123+
table_rows.append(f"|{number:04d}|{title}|{solution}| {tags} | {difficulty} | ")
47124

48125
table_content = "\n".join([table_header] + table_rows)
49-
readme_content = f"""# Coding Everyday Until I Get A Job
126+
readme_content = f"""# 📌 LeetCode Solutions - Coding Every Day Until I Get A Job
127+
128+
Welcome to my LeetCode solutions repository! 🚀 Here, I solve coding challenges every day to improve my problem-solving skills and prepare for technical interviews.
50129
51-
## LeetCode Solutions
130+
## 🔥 Problem List
52131
53132
{table_content}
54-
"""
133+
134+
## 🚀 Keep Coding & Stay Motivated!
135+
136+
Happy coding! 😊"""
55137

56138
with open("README.md", "w", encoding="utf-8") as f:
57139
f.write(readme_content)

0 commit comments

Comments
 (0)