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 isASC.
Interview Explanation#
I keep movies with odd ids that are not boring and order them by rating from high to low.
