A canvas game checks which sprites collide each frame. Each sprite's hit box is { x, y, width, height }.
Write collidingPairs(sprites) that returns how many pairs of sprites i < j overlap with positive area. Boxes that only touch along an edge or corner don't collide.
Input: sprites = [{"x":0,"y":0,"width":10,"height":10},{"x":5,"y":5,"width":10,"height":10},{"x":30,"y":30,"width":5,"height":5}] Output: 1
Only the first two sprites overlap. The third is far away.
Input: sprites = [{"x":0,"y":0,"width":10,"height":10},{"x":10,"y":0,"width":10,"height":10}] Output: 0
The two boxes only touch along x = 10.
0 <= sprites.length <= 10000 <= x, y <= 10^41 <= width, height <= 10^4Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #663 Colliding Sprite Pairs. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.