Skip to content

Conversation

@alokusw2
Copy link

@alokusw2 alokusw2 commented Jun 9, 2025

No description provided.

@super30admin
Copy link
Owner

  1. Correctness:

    • Problem 1 (Consecutive Numbers): The solution correctly identifies numbers appearing at least three times consecutively by joining the table to itself and checking for consecutive IDs and matching numbers.
    • Problem 2 (Number of Passengers in Each Bus): The solution uses a window function to count passengers arriving before each bus and then calculates the difference between consecutive buses. This appears correct.
    • Problem 3 (User Activity): The solution correctly counts distinct users active within the 30-day window.
    • Problem 4 (Dynamic Pivoting): The dynamic SQL approach is correct for pivoting the table by store.
  2. Time Complexity:

    • Problem 1: O(n) due to the self-joins on indexed IDs.
    • Problem 2: O(n log n) due to the window function and sorting.
    • Problem 3: O(n) for scanning the Activity table.
    • Problem 4: O(n) for building the pivot, but depends on the number of stores.
  3. Space Complexity:

    • Problem 1: O(n) for storing the intermediate joined results.
    • Problem 2: O(n) for the window function results.
    • Problem 3: O(n) for storing the grouped results.
    • Problem 4: O(n) for the dynamic SQL execution.
  4. Code Quality:

    • The solutions are well-structured and readable.
    • SQL formatting is consistent.
    • Comments are present where needed, especially in the dynamic pivoting solution.
    • Best practices are followed, such as using DISTINCT where appropriate and proper JOIN conditions.
  5. Efficiency:

    • All solutions appear efficient for their respective problems.
    • No obvious optimizations are needed, though for Problem 1, an alternative approach using window functions could be considered for potentially better performance with large datasets.

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