Problem · Array
MediumGoldman Sachs logoGoldman SachsFULLTIMEONSITE INTERVIEW

Problem statement

citations is sorted in nondecreasing order. Return the greatest integer h such that at least h papers each have at least h citations.

Your solution must run in O(log n) time.

Function

hIndexSorted(citations: int[]) → int

Examples

Example 1

citations = [0,1,3,5,6]return = 3

Three papers have at least three citations.

Example 2

citations = [1,2,100]return = 2

Two papers have at least two citations.

Constraints

  • 0 <= citations.length <= 100000
  • 0 <= citations[i] <= 10^9
  • citations is sorted in nondecreasing order.

More Goldman Sachs problems

drafts saved locally
public int hIndexSorted(int[] citations) {
  // write your code here
}
citations[0,1,3,5,6]
expected3
checking account