Range Intersection

Given a set of float ranges such as A = (3.5, 6.8), B = (4.5, 7.7), C = (2.2, 10.8), etc., find the intersection of the ranges (in this example if we only had A, B and C as input the output would have been (4.,5, 6.8)) Return range (0, 0) if the answer doesn’t exist (one or more of the input ranges has no intersection with the other ranges).

pair<floatfloat> FindRangeIntersection(vector<pair<floatfloat>> &arr)
{
    float max_start = FLT_MIN;
    float min_end = FLT_MAX;
    for (auto f : arr)
    {
        max_start = f.first > max_start ? f.first : max_start;
        min_end = f.second < min_end ? f.second : min_end;
 
        // If a range is completely outside of bound there is no intersection
        if (max_start > f.second || min_end < f.first)
            return make_pair(0.0f, 0.0f);
    }
 
    return make_pair(max_start, min_end);
}