Service Lane
easy⏱ 15 mintypescriptchallengesproblem-solving-basic-
LEARN BY DOINGPut your intuition to work3 steps
Service Lane
Use the lesson’s examples and explanation to check your idea.
Personal reflection. Nothing is sent to an AI service.8 5
2 3 1 2 3 2 3 3
0 3
4 6
6 7
3 5
0 7
1
2
3
2
1
Sample case — your program reads stdin and prints to stdout.
Starter Service lane has varying widths. For each query (entry i, exit j), find minimum width in segment [i,j]. Output the largest vehicle type that can pass: 1=bike, 2=car, 3=truck.
Example: widths=[2,3,1,2,3,2,3,3], query [0,3] → min width in [2,3,1,2] is 1 → Output: 1 (only bike can pass)
Input format
First line: n t (space-separated). Second line: n space-separated integers (widths). Next t lines: i j (space-separated, entry and exit indices).
Output format
For each query, output the maximum vehicle type (1, 2, or 3) that can pass.
Constraints
2 ≤ n ≤ 10⁵, 1 ≤ t ≤ 1000, 1 ≤ width[i] ≤ 3, 0 ≤ i ≤ j < n