Yelp | OA 2019 | Business Open Hours Ratio
Anonymous User
5313

image

My solution

My solution to this problem but some of the test cases were failing.

public float openHoursRatio(TimeRange queryTimeRange, List<TimeRange> openHours) {
        float sum = 0;
        for (TimeRange range : openHours) {
            sum += Float.min(range.end, queryTimeRange.end) - Float.max(queryTimeRange.start, range.start);
        }
        return sum / (queryTimeRange.end - queryTimeRange.start);
    }

I need help for this problem.

Comments (16)