from typing import List


def iou(box1: List[int], box2: List[int]) -> float:
    """
    Helper, calculates Intersection over union
    Args: 
        box1, box2: x, y, w, h of the boxes
    Output:   
        Intersection over union  
    """
    x11, y11, w1, h1 = box1
    x21, y21, w2, h2 = box2
    if w1 * h1 <= 0 or w2 * h2 <= 0:
        return 0
    x12, y12 = x11 + w1, y11 + h1
    x22, y22 = x21 + w2, y21 + h2

    area1, area2 = w1 * h1, w2 * h2
    xi1, yi1, xi2, yi2 = max([x11, x21]), max([y11, y21]), min([x12, x22]), min([y12, y22])

    if xi2 <= xi1 or yi2 <= yi1:
        return 0
    else:
        intersect = (xi2 - xi1) * (yi2 - yi1)
        union = area1 + area2 - intersect
        return intersect / union