leetle

Daily challenge for 2026-08-18

595. Longest Sorted Interval Index

You are given a list of intervals, where each interval is represented as a list of two integers [start, end]. First, sort the intervals in ascending order by their start times. If two intervals have the same start time, sort them by their end times. After sorting, find the 0-based index of the interval with the longest duration (defined as end - start). If there is a tie, return the smallest index among those with the longest duration. If the list is empty, return -1.

Example:
Input: intervals = [[3, 4], [1, 5], [1, 3]]
Output: 1

Explanation:
Sorting the intervals yields [[1, 3], [1, 5], [3, 4]].
Their durations are 2, 4, and 1 respectively. The longest duration is 4, which is at index 1.

Run this challenge interactively in Python or JavaScript when the app loads.