LeetCode 1495: Friendly Movies Streamed Last Month Solution

Master LeetCode problem 1495 (Friendly Movies Streamed Last Month), a easy challenge, with our optimized solutions in Java, C++, and Python. Explore detailed explanations, test your code in our interactive editor, and prepare for coding interviews.

1495. Friendly Movies Streamed Last Month

Problem Explanation

Explanation:

To solve this problem, we need to find the movies that were streamed by at least two friends in the last month. We can achieve this by using a HashMap to store the count of unique friends who streamed each movie. Then, we iterate through the HashMap and count the movies that were streamed by at least two friends.

  • Create a HashMap to store the count of unique friends who streamed each movie.
  • Iterate through the streaming history and update the count in the HashMap.
  • Iterate through the HashMap and count the movies streamed by at least two friends.

Time Complexity: O(n) where n is the number of streaming records
Space Complexity: O(n) for the HashMap

:

Solution Code

import java.util.*;

class Solution {
    public int numMoviesViewedLastMonth(List<List<Integer>> movies) {
        Map<Integer, Integer> movieCount = new HashMap<>();
        int result = 0;
        
        for (List<Integer> movie : movies) {
            for (int friend : movie) {
                movieCount.put(friend, movieCount.getOrDefault(friend, 0) + 1);
            }
        }
        
        for (int count : movieCount.values()) {
            if (count >= 2) {
                result++;
            }
        }
        
        return result;
    }
}

Try It Yourself

Loading code editor...

Related LeetCode Problems

Frequently Asked Questions

How to solve LeetCode 1495 (Friendly Movies Streamed Last Month)?

This page provides optimized solutions for LeetCode problem 1495 (Friendly Movies Streamed Last Month) in Java, C++, and Python, along with a detailed explanation and an interactive code editor to test your code.

What is the time complexity of LeetCode 1495 (Friendly Movies Streamed Last Month)?

The time complexity for LeetCode 1495 (Friendly Movies Streamed Last Month) varies by solution. Check the detailed explanation section for specific complexities in Java, C++, and Python implementations.

Can I run code for LeetCode 1495 on DevExCode?

Yes, DevExCode provides an interactive code editor where you can write, test, and run your code for LeetCode 1495 in Java, C++, or Python.

Back to LeetCode Solutions