Maximum Student-Teacher Distance
Problem statement
Students occupy positions 0 through n - 1. For every position, return the maximum absolute distance to any teacher in teacherPositions.
Function
maximumTeacherDistances(n: int, teacherPositions: int[]) → int[]Examples
Example 1
n = 5teacherPositions = [3,0,1,4]return = [4,3,2,3,4]Only the leftmost and rightmost teacher can maximize a student's absolute distance.
Example 2
n = 1teacherPositions = [0]return = [0]Only the leftmost and rightmost teacher can maximize a student's absolute distance.
Example 3
n = 5teacherPositions = [2]return = [2,1,0,1,2]Only the leftmost and rightmost teacher can maximize a student's absolute distance.
Constraints
1 <= n <= 200000.1 <= teacherPositions.length <= n.0 <= teacherPositions[i] < n.
Source note: Author-written prompt excerpt retained for source fidelity.