@@ -40,7 +40,8 @@ def pick_problems(user_data, problems, topic_list, k=5, problem_type=ProblemType
40
40
for maybe_skip in ['hard' , 'revisit' , 'refresh' ]:
41
41
skip_set .update (user_data [maybe_skip ] if maybe_skip not in args .list else [])
42
42
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)
44
45
if problem_type == ProblemType .Random :
45
46
return random .sample (list (problem_set ), min (len (problem_set ),k ))
46
47
return []
@@ -56,6 +57,14 @@ def mark_problem(user_data, mark_type, leetcode_id):
56
57
with open ('user.json' , 'w' ) as f :
57
58
f .write (re .sub (r',\n ' , ',' , json .dumps (user_data , indent = 2 )))
58
59
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
+
59
68
if __name__ == "__main__" :
60
69
parser = argparse .ArgumentParser (
61
70
description = "" ,
@@ -68,6 +77,7 @@ def mark_problem(user_data, mark_type, leetcode_id):
68
77
'array hash table ll greedy backtrack graph etc' )
69
78
parser .add_argument ('--list' , '-l' , nargs = '+' , default = ['blind75' ], help = "Companies interested in (or file(s) containing comma-delimited problems)" )
70
79
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" )
71
81
72
82
args = parser .parse_args ()
73
83
@@ -96,7 +106,10 @@ def mark_problem(user_data, mark_type, leetcode_id):
96
106
# load from file
97
107
problem_set .update (user_data [elem .lower ()])
98
108
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 :
100
113
problems = pick_problems (user_data , problems = problem_set , topic_list = args .topic_list , k = args .num_problems )
101
114
problem_set -= set (problems )
102
115
@@ -106,6 +119,8 @@ def mark_problem(user_data, mark_type, leetcode_id):
106
119
if len (problems ) == 0 :
107
120
print ("Your --topic_list is either invalid or all completed. Repicking from all topics." )
108
121
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 )
109
124
110
125
valid_inputs = ["info" , "hint" , "easy" , "hard" , "quit" , "pause" , "break" ]
111
126
print (f"Other valid inputs: { ', ' .join (valid_inputs )} " )
@@ -123,6 +138,7 @@ def mark_problem(user_data, mark_type, leetcode_id):
123
138
# TODO need problem to topic dictionary
124
139
raise Exception ("Not Implemented Yet" )
125
140
elif inp == 'info' :
141
+ print_info_func (leetcode_id )
126
142
difficulty_string = "medium difficulty" if problem ['Difficulty' ] == "Medium" else "considered easy" if problem ['Difficulty' ] == 'Easy' else problem ['Difficulty' ]
127
143
print (f"{ leetcode_id } { problem ['Name' ]} is { difficulty_string } : { problem ['Acceptance' ]} of submissions pass" )
128
144
company_list = my_companies & set (problem_to_companies [str (leetcode_id )])
@@ -152,8 +168,11 @@ def mark_problem(user_data, mark_type, leetcode_id):
152
168
# TODO pick problem with same topic and higher acceptance rate (if possible). If none, default to above line
153
169
start_time = timer ()
154
170
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
157
176
elif inp .startswith ('revisit' ):
158
177
marked_id = int (inp .split (' ' )[1 ]) if len (inp .split (' ' )) > 0 else leetcode_id
159
178
mark_problem (user_data , 'revisit' , marked_id )
0 commit comments