Skip to content

Conversation

@arushi2106
Copy link

@arushi2106 arushi2106 commented May 28, 2025

Added SQL1_Q1_Solution.sql for the Big Countries LeetCode problem.

@arushi2106 arushi2106 changed the title Completed Q1 SQL Homework Completed Q2_Sql1 Homework May 29, 2025
@BharathVuppala96
Copy link

Good Work

@super30admin
Copy link
Owner

Let me evaluate each solution separately:

  1. Q1_Solution.sql:
  • Correctness: Appears correct for finding countries with large area or population.
  • Time Complexity: O(n) where n is number of rows in World table (full table scan).
  • Space Complexity: O(1) - no additional space needed.
  • Code Quality: Well-structured and readable. Good use of parentheses for clarity.
  • Efficiency: Could benefit from indexes on area and population columns if this is a frequent query.
  1. Q1_Solution_UsingDECLARE_SET:
  • Correctness: Function name suggests it's for a different problem (Nth highest salary).
  • Time Complexity: O(n log n) for sorting.
  • Space Complexity: O(n) for sorting.
  • Code Quality: Syntax error - missing column after "order by desc". Function name doesn't match purpose.
  • Efficiency: LIMIT with offset can be inefficient for large N.
  1. Q3_Sql1_solution.sql:
  • Correctness: Correct approach to delete duplicate emails keeping lowest ID.
  • Time Complexity: O(n log n) for window function and O(n) for deletion.
  • Space Complexity: O(n) for temporary ranked_emails CTE.
  • Code Quality: Well-structured using CTE. Clear logic.
  • Efficiency: Good approach, though some databases might optimize self-join better.
  1. SQL1_Q2_Question.sql:
  • Correctness: Correct for finding Nth highest salary with dense_rank().
  • Time Complexity: O(n log n) for sorting in window function.
  • Space Complexity: O(n) for CTE.
  • Code Quality: Good use of CTE and dense_rank(). IFNULL seems unnecessary since NULL would return anyway.
  • Efficiency: Dense_rank() handles ties appropriately.
  1. sql1_q3_crossjoin:
  • Correctness: Correct for deleting duplicate emails keeping lower ID.
  • Time Complexity: O(n^2) for cross join.
  • Space Complexity: O(1) - no additional storage.
  • Code Quality: Compact but less readable than CTE version. Could use comments.
  • Efficiency: Cross join may be less efficient than window function approach for large tables.

General Observations:

  • Good variety of approaches shown.
  • Some solutions have syntax errors or naming mismatches.
  • Window functions are generally preferred over self-joins for readability.
  • Consistent indentation and formatting would improve readability across solutions.

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