task given an array of integers citations where citationsi is the number of citations a researcher received for their ith paper return compute the researcher s hindex according to the definition of hindex on wikipedia a scientist has an index h if h of their n papers have at least h citations each and the other n h papers have no more than h citations each if there are several possible values for h the maximum one is taken as the hindex hindex link https en wikipedia orgwikihindex implementation notes use sorting of array leetcode link https leetcode comproblemshindexdescription n lencitations runtime complexity on logn space complexity o1 return hindex of citations hindex3 0 6 1 5 3 hindex1 3 1 1 hindex1 2 3 2 hindex test traceback most recent call last valueerror the citations should be a list of non negative integers hindex1 2 3 traceback most recent call last valueerror the citations should be a list of non negative integers hindex1 2 3 traceback most recent call last valueerror the citations should be a list of non negative integers validate return h index of citations h_index 3 0 6 1 5 3 h_index 1 3 1 1 h_index 1 2 3 2 h_index test traceback most recent call last valueerror the citations should be a list of non negative integers h_index 1 2 3 traceback most recent call last valueerror the citations should be a list of non negative integers h_index 1 2 3 traceback most recent call last valueerror the citations should be a list of non negative integers validate
def h_index(citations: list[int]) -> int:
    

    
    if not isinstance(citations, list) or not all(
        isinstance(item, int) and item >= 0 for item in citations
    ):
        raise ValueError("The citations should be a list of non negative integers.")

    citations.sort()
    len_citations = len(citations)

    for i in range(len_citations):
        if citations[len_citations - 1 - i] <= i:
            return i

    return len_citations


if __name__ == "__main__":
    import doctest

    doctest.testmod()