-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/leetcode #10
Feature/leetcode #10
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @SKAUL05 - I've reviewed your changes and they look great!
Here's what I looked at during the review
- 🟡 General issues: 4 issues found
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟢 Complexity: all looks good
- 🟢 Docstrings: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.
if mat[row][col] == 0: | ||
dq.append((row, col)) | ||
else: | ||
mat[row][col] = -1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (code_clarification): Consider using a more descriptive placeholder than -1 for uninitialized distances.
Using a named constant like 'UNVISITED' could improve readability and maintainability.
mat[row][col] = -1 | |
UNVISITED = -1 | |
mat[row][col] = UNVISITED |
|
||
while dq: | ||
r, c = dq.popleft() | ||
directions = [(0, -1), (0, 1), (-1, 0), (1, 0)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (performance): Consider defining 'directions' outside the while loop to avoid redefinition on each iteration.
directions = [(0, -1), (0, 1), (-1, 0), (1, 0)] | |
directions = [(0, -1), (0, 1), (-1, 0), (1, 0)] | |
while dq: | |
r, c = dq.popleft() | |
for direction in directions: | |
new_row, new_col = direction[0] + r, direction[1] + c |
for i in points: | ||
dist = math.sqrt(math.pow((i[0] - 0), 2) + math.pow((i[1] - 0), 2)) | ||
final[f"{str(i[0])}_{str(i[1])}"] = dist | ||
final = dict(sorted(final.items(), key=lambda item: item[1])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (performance): Sorting the entire dictionary might be inefficient for large input sizes when only 'k' elements are needed.
Consider using a heap or partial sort to optimize performance.
final = dict(sorted(final.items(), key=lambda item: item[1])) | |
import heapq | |
final = heapq.nsmallest(k, final.items(), key=lambda item: item[1]) |
final = dict(sorted(final.items(), key=lambda item: item[1])) | ||
print(final) | ||
z = [] | ||
for i in final: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (code_refinement): Using a more descriptive variable name than 'i' for the key in the dictionary could enhance readability.
for i in final: | |
for key in final: |
No description provided.