def whereStartEndPairsInRange(startIdxs, endIdxs, minStartIdx, maxEndIdx):
	"""Given an ordered collection of start and end pairs, a minimum start
	index, and a maximum end index, return the first and last index into the
	start and end pairs collection such that the pair at that index is included
	in the range (the returned last index is not inclusive, as is typical in
	python).

	Note that this assumes that both the startIdxs and endIdxs are already
	sorted in ascending order. This is necessary for the returned indices
	to be meaningful when used to index the arrays passed in.

	Returns (-1, -1) if no (start, end) pairs fall in the range

	>>> starts = [0, 5]
	>>> ends = [1, 10]
	>>> minStart, maxEnd = 0, 20
	>>> whereStartEndPairsInRange(starts, ends, minStart, maxEnd)
	(0, 2)
	>>> minStart = 1
	>>> whereStartEndPairsInRange(starts, ends, minStart, maxEnd)
	(1, 2)
	>>> minStart, maxEnd = 0, 8
	>>> whereStartEndPairsInRange(starts, ends, minStart, maxEnd)
	(0, 1)
	>>> minStart, maxEnd = 1, 8
	>>> whereStartEndPairsInRange(starts, ends, minStart, maxEnd)
	(-1, -1)
	"""
	# fail fast
	assert(len(startIdxs) == len(endIdxs))
	empty = (-1, -1)
	if not len(startIdxs):
		return empty

	# find first startIdx >= minStartIdx
	tsIdx = -1
	ts = -1
	while ts < minStartIdx:
		try:
			tsIdx += 1
			ts = startIdxs[tsIdx]
		except IndexError: # reached end
			break

	# find last endIdx < maxEndIdx
	teIdx = tsIdx - 1
	te = -1
	while te < maxEndIdx:
		try:
			teIdx += 1
			te = endIdxs[teIdx]
		except IndexError:
			break

	if tsIdx == teIdx: # empty set
		return empty

	return tsIdx, teIdx