def count_intervals_brute(intervals: list[list[int]], points: list[int]) -> list[int]:public int[] countIntervalsBrute(int[][] intervals, int[] points)vector<int> countIntervalsBrute(vector<vector<int>> intervals, vector<int> points)function countIntervalsBrute(intervals, points)
def count_intervals_brute(intervals, points):
# Write your solution here
pass
class Solution {
public int[] countIntervalsBrute(int[][] intervals, int[] points) {
// Write your solution here
return new int[points.length];
}
}
#include <vector>
using namespace std;
vector<int> countIntervalsBrute(vector<vector<int>> intervals, vector<int> points) {
// Write your solution here
return vector<int>(points.size(), 0);
}
function countIntervalsBrute(intervals, points) {
// Write your solution here
}
Common Bugs to Avoid
Wrong: [1,0,1]Failing to count all intervals containing a point; possibly stopping after first match.✅ Remove early breaks in loops; count all intervals where start <= point <= end.
Wrong: [0,0,0]Using strict inequalities (start < point < end) excluding points on boundaries.✅ Change condition to inclusive: start <= point <= end.
Wrong: [0,1,0]Not handling zero-length intervals correctly; points equal to start and end not counted.✅ Include equality in interval containment check for zero-length intervals.
Wrong: [0,0,0]Code crashes or returns zeros when intervals list is empty due to missing empty check.✅ Add check for empty intervals list and return zero counts for all points.
Wrong: Timeout or no outputUsing brute force O(n*m) approach on large inputs causing TLE.✅ Implement sorting and line sweep or binary search approach to reduce complexity to O((n+m)log(n+m)).