Tensorum
YouTubeশেখা শুরু করুন
LeetCode 274 · Counting Sort

H-Index

LeetCode 274 · মাঝারি · সমাধান, intuition ও ধাপে ধাপে ওয়াকথ্রু

Sorted descending, h = first i where citations[i] ≤ i.

মাঝারিArraySortingCounting Sort
LeetCode-এ খুলুন ↗

আমি H-Index (LeetCode 274) এভাবে সমাধান করেছি — Counting Sort প্যাটার্নের একটি মাঝারি প্রবলেম। নিচে: intuition, ধাপে ধাপে approach, আমার accepted Python কোড, animated test cases আর line-by-line debugger।

নিচের বিবরণ ইংরেজিতে।

Intuition

Sort citations from most to least. Walking down the list, paper i (0-based) still supports an h of i+1 as long as it has more than i citations; the first paper that doesn't stops the count.

Approach

  1. 1

    Sort descending.

  2. 2

    Advance i while citations[i] > i.

  3. 3

    Return i.

আমি কীভাবে সমাধান করেছি

Sort descendingPythonO(n log n) time
class Solution:
    def hIndex(self, citations: List[int]) -> int:
        citations.sort(reverse=True)
        i=0
        while i<len(citations):
            if not citations[i]>i: 
                #6,5,3,1,0 -->citations
                #0,1,2,3,0 -->index
                break
            i+=1
        return i
স্টেপ-থ্রু লোড হচ্ছে…

H-Index — সাধারণ প্রশ্ন

H-Index-এর পেছনে intuition কী?

Sort citations from most to least. Walking down the list, paper i (0-based) still supports an h of i+1 as long as it has more than i citations; the first paper that doesn't stops the count.

H-Index (LeetCode 274) কীভাবে সমাধান করবেন?

1. Sort descending. 2. Advance i while citations[i] > i. 3. Return i.

H-Index-এর time আর space complexity কত?

Time: O(n log n)। Space: O(1)। (Accepted approach: Sort descending।)

H-Index-এ সাধারণ ভুলগুলো কী?

A counting-sort version gives O(n).