↓Skip to main content
  1. LeetCode/

LeetCode 620: Not Boring Movies

·1 min· ·
LeetCode Easy Database
Wei Yi Chung
Author
Wei Yi Chung
Working at the contributing of open source, distributed systems, and data engineering.
Table of Contents

Meta Data
#

Difficulty: easy First Attempt: 2021-10-10

  • Submissions: Runtime Error → Wrong Answer ×2 → Accepted

Approach
#

Filter with two ANDed conditions (SQL Template 1), id % 2 = 1 and description <> 'boring', then sort with ORDER BY rating DESC. Quote the string.

My Attempts
#

Attempt 1 left boring unquoted, so it was read as a column (RE); after quoting it forgot the ordering, then used ORDER BY rating (ascending by default); DESC passed.

Solution
#

SELECT *
FROM Cinema
WHERE id % 2 = 1 AND description <> 'boring'
ORDER BY rating DESC;

Complexity
#

Sorting dominates, O(n log n).

Mistakes to Avoid
#

  • Quote the string: 'boring'.
  • High to low is DESC; the default is ASC.

Interview Explanation
#

I keep movies with odd ids that are not boring and order them by rating from high to low.

Related

LeetCode 197: Rising Temperature
·1 min
LeetCode Easy Database
LeetCode 197 note: self-join Weather on a one-day date difference with today warmer; compare dates with DATEDIFF, never ids
LeetCode 595: Big Countries
·1 min
LeetCode Easy Database
LeetCode 595 note: filter with WHERE and OR for an area of at least 3 million or a population of at least 25 million
LeetCode 596: Classes With at Least 5 Students
·1 min
LeetCode Easy Database
LeetCode 596 note: group by class with HAVING COUNT(DISTINCT student) >= 5; older test data had duplicate rows, so count distinct students
LeetCode 175: Combine Two Tables
·1 min
LeetCode Easy Database
LeetCode 175 note: people without an address must still appear, so LEFT JOIN, leaving city and state NULL when unmatched
LeetCode 181: Employees Earning More Than Their Managers
·1 min
LeetCode Easy Database
LeetCode 181 note: self-join Employee on managerId = id to pair employees with managers, then compare salaries
LeetCode 182: Duplicate Emails
·1 min
LeetCode Easy Database
LeetCode 182 note: group by email and keep groups with HAVING COUNT(*) > 1