Problem · Array
Common Train Arrival Times
Learn this problemProblem statement
You are given trainTimes, where trainTimes[i] lists the integer times at which train i arrives at one station.
Return every distinct time that appears in every train's list, in ascending order.
Function
commonTrainArrivalTimes(trainTimes: int[][]) → int[]Examples
Example 1
trainTimes = [[360,480,520,700,950,1100,1440],[1230,670,480,820,360,980,490]]return = [360,480]Only 360 and 480 occur in both trains' arrival lists, and they are returned in ascending order.
Example 2
trainTimes = [[1,2,3,4],[0,2,4,6],[2,4,8]]return = [2,4]The values 2 and 4 are present for all three trains.
Constraints
2 <= trainTimes.length <= 100.1 <= trainTimes[i].length.- The total number of listed arrivals is at most
3000. 0 <= trainTimes[i][j] <= 10^9.