Skip to content

Commit d34a38c

Browse files
committed
display information about specific problem
1 parent f147025 commit d34a38c

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

lcpp.py

+23-4
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ def pick_problems(user_data, problems, topic_list, k=5, problem_type=ProblemType
4040
for maybe_skip in ['hard', 'revisit', 'refresh']:
4141
skip_set.update(user_data[maybe_skip] if maybe_skip not in args.list else [])
4242

43-
problem_set = (set(problems) & selected_topics) - skip_set
43+
problem_set = (set(problems) & selected_topics & set(int(key) for key in all_problems.keys())) - skip_set
44+
#print(problem_set)
4445
if problem_type==ProblemType.Random:
4546
return random.sample(list(problem_set), min(len(problem_set),k))
4647
return []
@@ -56,6 +57,14 @@ def mark_problem(user_data, mark_type, leetcode_id):
5657
with open('user.json', 'w') as f:
5758
f.write(re.sub(r',\n ', ',', json.dumps(user_data, indent=2)))
5859

60+
def print_info(all_problems, problem_to_companies, my_companies, leetcode_id):
61+
problem = all_problems[str(leetcode_id)]
62+
difficulty_string = "medium difficulty" if problem['Difficulty'] == "Medium" else "considered easy" if problem['Difficulty'] == 'Easy' else problem['Difficulty']
63+
print(f"{leetcode_id} {problem['Name']} is {difficulty_string}: {problem['Acceptance']} of submissions pass")
64+
company_list = my_companies & set(problem_to_companies[str(leetcode_id)])
65+
company_list_string = f"including: {', '.join(company_list)}" if len(company_list) > 0 else f"including: {','.join(problem_to_companies[str(leetcode_id)][:5])}"
66+
print(f"{len(company_list)} companies have asked this question {company_list_string}")
67+
5968
if __name__ == "__main__":
6069
parser = argparse.ArgumentParser(
6170
description="",
@@ -68,6 +77,7 @@ def mark_problem(user_data, mark_type, leetcode_id):
6877
'array hash table ll greedy backtrack graph etc')
6978
parser.add_argument('--list', '-l', nargs='+', default=['blind75'], help="Companies interested in (or file(s) containing comma-delimited problems)")
7079
parser.add_argument('--num_problems', '-k', type=int, default=5, help="Determine number of problems to solve")
80+
parser.add_argument('--info', action='store', type=int, help="Get details on a problem ID")
7181

7282
args = parser.parse_args()
7383

@@ -96,7 +106,10 @@ def mark_problem(user_data, mark_type, leetcode_id):
96106
# load from file
97107
problem_set.update(user_data[elem.lower()])
98108

99-
if args.interactive:
109+
print_info_func = lambda id: print_info(all_problems, problem_to_companies, my_companies, id)
110+
if args.info:
111+
print_info_func(args.info)
112+
elif args.interactive:
100113
problems = pick_problems(user_data, problems=problem_set, topic_list=args.topic_list, k=args.num_problems)
101114
problem_set -= set(problems)
102115

@@ -106,6 +119,8 @@ def mark_problem(user_data, mark_type, leetcode_id):
106119
if len(problems) == 0:
107120
print("Your --topic_list is either invalid or all completed. Repicking from all topics.")
108121
problems = pick_problems(user_data, problems=problem_set, topic_list=topics.keys(), k=args.num_problems)
122+
if len(problems) == 0:
123+
problems = pick_problems(user_data, problems=set(range(1,1700)), topic_list=topics.keys(), k=args.num_problems)
109124

110125
valid_inputs = ["info", "hint", "easy", "hard", "quit", "pause", "break"]
111126
print(f"Other valid inputs: {', '.join(valid_inputs)}")
@@ -123,6 +138,7 @@ def mark_problem(user_data, mark_type, leetcode_id):
123138
# TODO need problem to topic dictionary
124139
raise Exception("Not Implemented Yet")
125140
elif inp == 'info':
141+
print_info_func(leetcode_id)
126142
difficulty_string = "medium difficulty" if problem['Difficulty'] == "Medium" else "considered easy" if problem['Difficulty'] == 'Easy' else problem['Difficulty']
127143
print(f"{leetcode_id} {problem['Name']} is {difficulty_string}: {problem['Acceptance']} of submissions pass")
128144
company_list = my_companies & set(problem_to_companies[str(leetcode_id)])
@@ -152,8 +168,11 @@ def mark_problem(user_data, mark_type, leetcode_id):
152168
# TODO pick problem with same topic and higher acceptance rate (if possible). If none, default to above line
153169
start_time = timer()
154170
elif inp == 'skip':
155-
leetcode_id = pick_problems(user_data, problems=problem_set, topic_list=args.topic_list, k=1)[0]
156-
start_time = timer()
171+
try:
172+
leetcode_id = pick_problems(user_data, problems=problem_set, topic_list=args.topic_list, k=1)[0]
173+
start_time = timer()
174+
except IndexError:
175+
break
157176
elif inp.startswith('revisit'):
158177
marked_id = int(inp.split(' ')[1]) if len(inp.split(' ')) > 0 else leetcode_id
159178
mark_problem(user_data, 'revisit', marked_id)

0 commit comments

Comments
 (0)