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).