Skip to content

Commit e0ec371

Browse files
committed
uploaded new files
1 parent 90b2d5a commit e0ec371

File tree

12 files changed

+166
-0
lines changed

12 files changed

+166
-0
lines changed

.idea/.gitignore

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/Leetcode-solutions.iml

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/inspectionProfiles/Project_Default.xml

+27
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/inspectionProfiles/profiles_settings.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Solution for Problem 2490: Circular Sentence
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Solution for Problem 2490: Circular Sentence
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Solution for Problem 796: Rotate String
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Solution for Problem 796: Rotate String

Daily Problems/create_problem.py

+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
import os
2+
import requests
3+
4+
5+
def fetch_problem_info(problem_id):
6+
"""
7+
Fetch only the title and difficulty of a problem using problem ID
8+
"""
9+
# Get problem info from LeetCode API
10+
response = requests.get('https://leetcode.com/api/problems/all/')
11+
if response.status_code != 200:
12+
raise Exception(f"Failed to fetch problems list: {response.status_code}")
13+
14+
problems_data = response.json()
15+
problem_info = next(
16+
(p for p in problems_data['stat_status_pairs']
17+
if str(p['stat']['frontend_question_id']) == str(problem_id)),
18+
None
19+
)
20+
21+
if not problem_info:
22+
raise Exception(f"Problem {problem_id} not found")
23+
24+
# Extract only needed information
25+
return {
26+
'title': problem_info['stat']['question__title'],
27+
'difficulty': ['Easy', 'Medium', 'Hard'][problem_info['difficulty']['level'] - 1],
28+
'question_id': problem_id
29+
}
30+
31+
32+
def create_problem_structure(problem_info, base_dir):
33+
"""
34+
Create problem folder with solution files in appropriate difficulty subfolder
35+
"""
36+
question_id = problem_info['question_id']
37+
title = problem_info['title']
38+
difficulty = problem_info['difficulty']
39+
40+
# Create directory name in format "XXXX. Title"
41+
dir_name = f"{question_id}. {title}"
42+
43+
# Full path to problem directory
44+
problem_dir = os.path.join(base_dir, difficulty, dir_name)
45+
46+
if not os.path.exists(problem_dir):
47+
# Create problem directory
48+
os.makedirs(problem_dir, exist_ok=True)
49+
50+
# Create solution files
51+
solution_py = os.path.join(problem_dir, 'solution.py')
52+
solution_r = os.path.join(problem_dir, 'solution.R')
53+
54+
# Create solution.py with basic template
55+
with open(solution_py, 'w', encoding='utf-8') as f:
56+
f.write(f"# Solution for Problem {question_id}: {title}\n")
57+
58+
# Create solution.R with basic template
59+
with open(solution_r, 'w', encoding='utf-8') as f:
60+
f.write(f"# Solution for Problem {question_id}: {title}\n")
61+
62+
print(f"Created problem folder: {dir_name}")
63+
print(f"Location: {problem_dir}")
64+
else:
65+
print(f"Problem already exists: {dir_name}")
66+
67+
68+
def main():
69+
# Base directory for all problems
70+
base_directory = r"Daily Problems"
71+
72+
while True:
73+
problem_id = input("Enter the LeetCode problem ID (or 'q' to quit): ")
74+
if problem_id.lower() == 'q':
75+
break
76+
77+
try:
78+
print(f"\nFetching problem {problem_id}...")
79+
problem_info = fetch_problem_info(problem_id)
80+
81+
print(f"Found problem: {problem_id}. {problem_info['title']}")
82+
print(f"Difficulty: {problem_info['difficulty']}")
83+
84+
create_problem_structure(problem_info, base_directory)
85+
86+
except Exception as e:
87+
print(f"Error processing problem {problem_id}: {str(e)}")
88+
89+
print("\nWould you like to fetch another problem?")
90+
91+
92+
if __name__ == "__main__":
93+
main()

0 commit comments

Comments
 (0)