H-Index
LeetCode 274 · मध्यम · उपाय, intuition आणि टप्प्याटप्प्याने वॉकथ्रू
Sorted descending, h = first i where citations[i] ≤ i.
मी 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
Sort descending.
- 2
Advance i while citations[i] > i.
- 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 iH-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).