Hone logo
Hone
Problems

Not Boring Movies

Imagine you're building a movie recommendation system. A crucial part of this is identifying movies that are genuinely interesting and not just filler. This challenge involves filtering a list of movies to find those that meet specific criteria for being "not boring."

Problem Description

You are given a table named Movies which contains information about movies. Each row in the table represents a movie and has the following columns:

  • id (integer): The unique identifier for the movie.
  • title (string): The title of the movie.
  • year (integer): The year the movie was released.
  • rating (decimal): The rating of the movie.

Your task is to select the movies that are considered "not boring." A movie is considered "not boring" if its rating is strictly greater than 5.0 OR if the year is 2000 or later and the title does not start with 'A'.

You need to return the id, title, year, and rating of these "not boring" movies. The results should be ordered by the movie's id in ascending order.

Examples

Example 1:

Input:
Movies table:
| id | title         | year | rating |
|----|---------------|------|--------|
| 1  | Movie A       | 1999 | 6.0    |
| 2  | Movie B       | 2000 | 4.0    |
| 3  | Movie C       | 2001 | 7.0    |
| 4  | Another Movie | 1998 | 8.0    |
| 5  | A Good Film   | 2005 | 3.0    |

Output:
| id | title         | year | rating |
|----|---------------|------|--------|
| 1  | Movie A       | 1999 | 6.0    |
| 3  | Movie C       | 2001 | 7.0    |
| 4  | Another Movie | 1998 | 8.0    |

Explanation:
- Movie A (id 1): rating is 6.0 (> 5.0), so it's not boring.
- Movie B (id 2): rating is 4.0 (<= 5.0) AND year is 2000, but title starts with 'M' which is not 'A'. However, the year is 2000 but the rating is not > 5.0, so we check the second condition. The year is 2000 and the title does not start with 'A'. Oh wait, I made a mistake in the manual check. Let's re-evaluate:
    - Movie B (id 2): rating is 4.0 (<= 5.0). Year is 2000 (>= 2000). Title starts with 'M' (does not start with 'A'). Thus, it's not boring. Let me correct the output for Movie B.
Corrected Output:
| id | title         | year | rating |
|----|---------------|------|--------|
| 1  | Movie A       | 1999 | 6.0    |
| 2  | Movie B       | 2000 | 4.0    |
| 3  | Movie C       | 2001 | 7.0    |
| 4  | Another Movie | 1998 | 8.0    |

Explanation (Corrected):
- Movie A (id 1): rating is 6.0 (> 5.0), so it's not boring.
- Movie B (id 2): rating is 4.0 (<= 5.0). Year is 2000 (>= 2000). Title starts with 'M' (does not start with 'A'). Both conditions for the second criterion are met (year is 2000 or later, AND title does not start with 'A'), so it's not boring.
- Movie C (id 3): rating is 7.0 (> 5.0), so it's not boring.
- Another Movie (id 4): rating is 8.0 (> 5.0), so it's not boring.
- A Good Film (id 5): rating is 3.0 (<= 5.0). Year is 2005 (>= 2000). Title starts with 'A'. The second part of the second criterion (title does not start with 'A') is NOT met. Therefore, it's boring.

**Example 2:**

Input: Movies table:

idtitleyearrating
1The Matrix19998.7
2Avatar20097.9
3Titanic19977.8
4Inception20108.8
5Pulp Fiction19948.9

Output:

idtitleyearrating
1The Matrix19998.7
2Avatar20097.9
3Titanic19977.8
4Inception20108.8
5Pulp Fiction19948.9

Explanation: All movies have a rating strictly greater than 5.0, so they are all considered "not boring." The second condition is not needed for any of these.

Example 3 (Edge Case):

Input:
Movies table:
| id | title         | year | rating |
|----|---------------|------|--------|
| 1  | Ancient Wars  | 1995 | 4.0    |
| 2  | Ancient Tales | 2000 | 4.0    |
| 3  | Modern Tales  | 1998 | 4.0    |
| 4  | Old Movie     | 1950 | 6.0    |

Output:
| id | title     | year | rating |
|----|-----------|------|--------|
| 4  | Old Movie | 1950 | 6.0    |

Explanation:
- Ancient Wars (id 1): rating 4.0 (<= 5.0), year 1995 (< 2000). Boring.
- Ancient Tales (id 2): rating 4.0 (<= 5.0). Year 2000 (>= 2000). Title starts with 'A'. Second condition fails. Boring.
- Modern Tales (id 3): rating 4.0 (<= 5.0), year 1998 (< 2000). Boring.
- Old Movie (id 4): rating 6.0 (> 5.0). Not boring.

Constraints

  • The Movies table will contain between 1 and 1000 rows.
  • The id column will be unique for each movie.
  • The year will be between 1900 and 2023.
  • The rating will be a decimal number between 0.0 and 10.0.
  • The title will be a non-empty string.

Notes

  • Remember to carefully consider the logical OR (OR) and AND (AND) operators when formulating your condition.
  • The comparison for the year should be "greater than or equal to 2000".
  • The comparison for the title should be "does not start with 'A'". This implies case-sensitivity; ensure your implementation matches this.
  • The final output needs to be sorted by id.

Pseudocode Solution Structure:

FUNCTION find_not_boring_movies(Movies_table):
  SET result_movies = empty list

  FOR EACH movie IN Movies_table:
    // Check the first condition: rating is strictly greater than 5.0
    IF movie.rating > 5.0 THEN
      ADD movie to result_movies
    // Check the second condition: year is 2000 or later AND title does not start with 'A'
    ELSE IF movie.year >= 2000 AND movie.title DOES NOT START WITH 'A' THEN
      ADD movie to result_movies
    END IF
  END FOR

  // Sort the result_movies by id in ascending order
  SORT result_movies BY movie.id ASCENDING

  RETURN result_movies
END FUNCTION
Loading editor...
plaintext