Fleet hit ratio optimization

Write codeHard40 min

Your task

A content delivery team is shrinking a fleet of edge nodes and must keep exactly keep of them. Over last week hits[i] counts the requests node i served from its cache and requests[i] counts the requests it received. The fleet wide hit ratio of a group is the total of their hits divided by the total of their requests, so a busy node pulls that figure further than a quiet one. Return the highest fleet wide hit ratio that any group of exactly keep nodes reaches, as a fraction between 0 and 1. Every requests entry is at least 1 and every hits entry is between 0 and its own requests entry. Return -1 when keep is below 1 or above the number of nodes.

Examples

best_hit_ratio(hits: list[int], requests: list[int], keep: int) -> float
Example 1
Inputbest_hit_ratio([90, 50, 0], [100, 100, 1], 2)
Output0.8910891089108911
Example 2
Inputbest_hit_ratio([3, 7, 2], [4, 9, 3], 3)
Output0.75
Example 3
Inputbest_hit_ratio([4, 4], [5, 5], 3)
Output-1