Skip to content

Conversation

@alokusw2
Copy link

@alokusw2 alokusw2 commented Jun 9, 2025

No description provided.

@super30admin
Copy link
Owner

  1. Correctness:

    • Problem 1 (Game Play Analysis II): The solution correctly uses FIRST_VALUE with PARTITION BY and ORDER BY to find the first device for each player. This is an efficient approach.
    • Problem 2 (Game Play Analysis III): The solution correctly calculates running totals using SUM with PARTITION BY and ORDER BY. This is the standard approach for such problems.
    • Problem 3 (Shortest Distance in a Plane): The solution correctly calculates the minimum distance between points using a self-join and handles the edge case of not comparing a point to itself. The rounding is also correctly implemented.
    • Problem 4 (Combine Two Tables): The solution correctly uses a LEFT JOIN to include all persons even if they don't have an address. The USING clause is appropriate here.
    • Problem 5 (Customers with Strictly Increasing Purchases): The solution correctly identifies customers with strictly increasing purchases using a self-join and the EVERY function. This is a clever approach.
  2. Time Complexity:

    • Problem 1: O(n log n) due to the window function's sorting.
    • Problem 2: O(n log n) for the same reason as Problem 1.
    • Problem 3: O(n²) due to the self-join comparing each point with every other point.
    • Problem 4: O(n) for the join operation.
    • Problem 5: O(n²) in the worst case due to the self-join.
  3. Space Complexity:

    • All solutions have space complexity proportional to their output size, which is optimal for these problems.
  4. Code Quality:

    • The code is well-structured and readable.
    • SQL formatting is consistent with proper indentation.
    • The use of CTEs (Common Table Expressions) in Problem 5 improves readability.
    • Comments separating problems are helpful.
  5. Efficiency:

    • All solutions are efficient given their problem constraints.
    • For Problem 3, while the solution is correct, it could be optimized by avoiding duplicate comparisons (comparing p1 to p2 and p2 to p1), but this would complicate the query.

Areas for Improvement:

  • Consider adding brief comments explaining the logic for each solution, especially for more complex queries like Problem 5.
  • For Problem 3, you could add a condition like ON (p1.x < p2.x) OR (p1.x = p2.x AND p1.y < p2.y) to avoid duplicate comparisons, though this might not significantly improve performance.

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.

2 participants