LeetCode 1113: Reported Posts Solution
Master LeetCode problem 1113 (Reported Posts), 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.
1113. Reported Posts
Problem Explanation
Explanation
To solve this problem, we can iterate over the list of reported posts and maintain a count of each post's report count. Then, we can iterate over the list of posts and check if the post has been reported more than the threshold. If so, we add it to the result list.
Algorithm
- Create a map to store the count of each reported post.
- Iterate over the list of reported posts and update the count in the map.
- Iterate over the list of posts and check if the post has been reported more than the threshold.
- If the count exceeds the threshold, add the post to the result list.
- Return the result list.
Time Complexity
The time complexity of this algorithm is O(n), where n is the total number of reported posts and posts.
Space Complexity
The space complexity of this algorithm is O(n), where n is the total number of reported posts.
Solution Code
import java.util.*;
class Solution {
public List<Integer> reportPosts(int[] reported, int[] posts, int threshold) {
Map<Integer, Integer> reportCount = new HashMap<>();
List<Integer> result = new ArrayList<>();
for (int report : reported) {
reportCount.put(report, reportCount.getOrDefault(report, 0) + 1);
}
for (int post : posts) {
if (reportCount.containsKey(post) && reportCount.get(post) >= threshold) {
result.add(post);
}
}
return result;
}
}Try It Yourself
Loading code editor...
Related LeetCode Problems
Frequently Asked Questions
How to solve LeetCode 1113 (Reported Posts)?
This page provides optimized solutions for LeetCode problem 1113 (Reported Posts) 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 1113 (Reported Posts)?
The time complexity for LeetCode 1113 (Reported Posts) varies by solution. Check the detailed explanation section for specific complexities in Java, C++, and Python implementations.
Can I run code for LeetCode 1113 on DevExCode?
Yes, DevExCode provides an interactive code editor where you can write, test, and run your code for LeetCode 1113 in Java, C++, or Python.