Skip to content
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

Merged
merged 4 commits into from
Apr 19, 2024
Merged

Feature/leetcode #10

merged 4 commits into from
Apr 19, 2024

Conversation

SKAUL05
Copy link
Owner

@SKAUL05 SKAUL05 commented Apr 19, 2024

No description provided.

@SKAUL05 SKAUL05 merged commit 9813654 into master Apr 19, 2024
3 checks passed
Copy link

@sourcery-ai sourcery-ai bot left a 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

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
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
Copy link

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.

Suggested change
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)]
Copy link

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.

Suggested change
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]))
Copy link

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.

Suggested change
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:
Copy link

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.

Suggested change
for i in final:
for key in final:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant