I have a list of integers that represent how many times an item has been used and I need to find the next number in the sequence that has been used the least amount of times (it might not even be in the list)
The amount of items is dynamic, the example uses 9 but that could be. Also, the amount of times it can appear is dynamic too.
We have X items, all of which are allowed to be used y times
Example.
We have 9 items, both of which are allowed to be used 2 times but should be used in order.
[1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2]
the above should return 3 as the next available item
[1, 2, 3, 4, 5]
the above should return 6 as the next available item
[1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9]
the above should return nothing, as there's no more available
I've already got me a function that's checking if the number appears at the max amount of uses
def is_item_available(item_number: int, uses: int, used_items: List):
"""Check if the item is available.
Args:
item_number (int): item number to be checked
uses (int): number of uses allowed
used_items (list): list of items currently used in a session
Returns:
bool: returns True if used item count is less than the uses number
"""
return used_items.count(item_number) < uses