def intervalIntersection(A: list[list[int]], B: list[list[int]]) -> list[list[int]]:public List<int[]> intervalIntersection(List<int[]> A, List<int[]> B)vector<vector<int>> intervalIntersection(vector<vector<int>>& A, vector<vector<int>>& B)function intervalIntersection(A, B)
def intervalIntersection(A, B):
# Write your solution here
pass
class Solution {
public List<int[]> intervalIntersection(List<int[]> A, List<int[]> B) {
// Write your solution here
return new ArrayList<>();
}
}
#include <vector>
using namespace std;
vector<vector<int>> intervalIntersection(vector<vector<int>>& A, vector<vector<int>>& B) {
// Write your solution here
return {};
}
function intervalIntersection(A, B) {
// Write your solution here
}
Common Bugs to Avoid
Wrong: [[1,5],[8,10],[15,24],[25,25]]Incorrectly adding intervals from one list without intersecting with the other; missing partial overlaps.✅ Compute intersection as [max(startA, startB), min(endA, endB)] only if max start <= min end, and advance pointer of interval with smaller end.
Wrong: [[2,2]]Missing single-point intersections due to strict inequality in overlap check.✅ Use <= in overlap condition: if max(startA, startB) <= min(endA, endB), add intersection.
Wrong: [[1,2],[3,4],[5,6],[1,10]]Treating intervals as unbounded or not advancing pointers properly, causing duplicates or incorrect intervals.✅ Advance pointer of interval with smaller end after processing intersection; do not add intervals without intersection.
Wrong: Timeout or no outputUsing brute force nested loops O(m*n) for large inputs.✅ Implement two-pointer approach with O(m+n) time complexity.