Skip to content

Conversation

@NehaDhaliwal
Copy link

No description provided.

Copy link

@Nandha2Tech Nandha2Tech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great Work!

@Nandha2Tech
Copy link

Great Work!

@super30admin
Copy link
Owner

  1. Problem 1.sql (Ranking Scores):

    • Correctness: The solution correctly uses dense_rank() to handle ties in scores appropriately.
    • Time Complexity: O(n log n) due to the sorting operation in dense_rank().
    • Space Complexity: O(n) for storing the result set.
    • Code Quality: Simple and clean, follows best practices.
    • Efficiency: No obvious optimizations needed for this straightforward problem.
  2. Problem 2.sql (Exchange Seats):

    • Correctness: The solution handles both even and odd number of students correctly, including the edge case where the last student doesn't need to swap when the count is odd.
    • Time Complexity: O(n) for the count operation and O(n log n) for the final sorting.
    • Space Complexity: O(n) for the result set.
    • Code Quality: The CASE statement is well-structured but could be more readable with better indentation. The subquery for counting could be moved to a WITH clause for better readability.
    • Efficiency: The solution is efficient, though using a window function for the count might be slightly more elegant.
  3. Problem 3.sql (Tree Node Types):

    • Correctness: Correctly identifies Root, Inner, and Leaf nodes using CASE and subqueries.
    • Time Complexity: O(n^2) due to the subquery in the CASE statement (for each row, it checks against all p_ids).
    • Space Complexity: O(n) for the result set.
    • Code Quality: Good structure, but the subquery could be moved to a JOIN for better performance and readability.
    • Efficiency: Could be optimized by using a LEFT JOIN instead of a subquery to reduce time complexity to O(n).
  4. Problem 4.sql (Department Top Three Salaries):

    • Correctness: Correctly uses dense_rank() to handle ties and selects top 3 salaries per department.
    • Time Complexity: O(n log n) for the window function operation.
    • Space Complexity: O(n) for the CTE and result set.
    • Code Quality: Excellent use of CTE and window functions, very readable.
    • Efficiency: No obvious optimizations needed.

General Observations:

  • The student demonstrates strong SQL skills, particularly with window functions and complex conditional logic.
  • All solutions handle edge cases appropriately.
  • Code formatting could be slightly improved with consistent indentation, especially in Problem 2.
  • The student could consider using more JOINs instead of subqueries where possible for better 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.

3 participants