import math


def quantile_index(n, quantile):
  """Returns index of the specified quantile in a sorted dataset of n elements.

  Args:
    n: Size of the sorted dataset.
    quantile: A value in [0, 1] indicating the desired quantile.

  Returns:
    Index of the specified quantile. If the quantile is between points at
    indices i and i+1, returns i.
  """
  return int(math.floor((n - 1) * quantile))