g | x | w | all
Bytes Lang Time Link
010Uiua240827T022914Znyxbird
048Arturo240822T075625Zchunes
132C gcc221223T104035Zmatteo_c
033x8664 machine code221230T120409Zm90
00805AB1E221228T093400ZKevin Cr
048Python 3221223T015320Ztsh
086Haskell221225T112710ZRoman Cz
005Vyxal221223T085323Zu-ndefin
040R221223T081255Zpajonk
007Jelly221223T110722ZAndrovT
007Jelly221223T142811ZJonathan
111Excel ms365221223T101158ZJvdV
015Charcoal221223T002830ZNeil
918Nibbles221223T091739ZDominic
2420J221223T012531ZJonah
061JavaScript ES6221223T005006ZArnauld
020Pip221223T032012Zjezza_99
056Factor221223T015623Zchunes
237Python3221223T002051ZAjax1234

Uiua, 10 bytes

/↥\+⬚0-∩°⊚

Takes input as [leaving][boarding]

Try it!

Arturo, 48 bytes

$=>[max values tally flatten map&=>[@..dec do&]]

Try it!

Port of my Factor answer.

C (gcc), 137 134 133 132 bytes

-2 byte thanks to @ceilingcat

m;n;k;i;q;l;main(c,v)int**v;{for(;++n-l;k=0)for(i=1;i++<c;m=fmax(k+=atoi(v[i++-1])<=n&n<q,m))l=fmax(q=atoi(v[i]),l);printf("%d",m);}

Try it online!

x86-64 machine code, 33 bytes

92 99 31 C9 57 56 AF 75 02 FF C9 AF 75 02 FF C1 FF CE 75 F2 5E 5F 39 D1 0F 47 D1 FF C8 75 E5 92 C3

Try it online!

Following the standard calling convention for Unix-like systems (from the System V AMD64 ABI), this takes an array of pairs of 32-bit integers with the address in RDI and the length in ESI, and takes the number of stations in EDI.

This program runs backwards through the stations, keeping track of the number of passengers on the train, and the answer is the highest that number has been.

In assembly:

f:
    xchg edx, eax   # Switch the number of stations into EAX.
    cdq             # Set EDX to 0 by sign-extending EAX.
    xor ecx, ecx    # Set ECX to 0.
            # EAX will hold the current station, ECX the current number of passengers,
            #  and EDX the highest number of passengers so far.
next_station:
    push rdi        # Save the value of RDI onto the stack.
    push rsi        # Save the value of RSI onto the stack.
next_passenger:
    scasd           # Compare EAX and the value at address RDI, advancing the pointer.
    jne s0          # (That value is the starting station.) Jump if they are unequal.
    dec ecx         # (If they are equal) Subtract 1 from the current passenger count.
s0:
    scasd           # Compare EAX and the value at address RDI, advancing the pointer.
    jne s1          # (That value is the ending station.) Jump if they are unequal.
    inc ecx         # (If they are equal) Add 1 to the current passenger count.
s1:
    dec esi         # Subtract 1 from ESI, counting down from the number of passengers.
    jnz next_passenger  # Jump back, to repeat, if it's not zero.
    pop rsi         # Restore the value of RSI from the stack.
    pop rdi         # Restore the value of RDI from the stack.
    cmp ecx, edx    # Compare the current passenger count and EDX.
    cmova edx, ecx  # If the current passenger count is higher, set EDX to that.
    dec eax         # Subtract 1 from EAX, progressing backwards through the stations.
    jnz next_station# Jump back, to repeat, if it's not zero.
    xchg edx, eax   # Switch the highest passenger count into EAX (to be returned).
    ret             # Return.

05AB1E, 8 bytes

εŸ¨}˜D¢à

Try it online or verify all test cases.

Explanation:

ε      # Map over each pair of the (implicit) input-list:
 Ÿ     #  Pop the pair, and push a list in the inclusive range of it
  ¨    #  Remove the last item (the destination-seat)
}˜     # After the map: flatten the list of lists
  D    # Duplicate it
   ¢   # Pop both, and count how many times each occurs
    à  # Pop and leave the maximum count
       # (which is output implicitly as result)

Python 3, 48 bytes

lambda a:max(sum(p<x<[q]for*p,q in a)for x in a)

Try it online!


Python 3, 50 bytes

lambda a:max(sum(p<=x<q for p,q in a)for x,y in a)

Try it online!

Haskell, 86 bytes

import Data.Ix
import Data.List
s=maximum.map length.group.sort.concat.map(init.range)

Try it online!

Vyxal, 5 bytes

rfĊ↑t

Try it online! Takes a list of start stations and a list of end stations.

r     # range (vectorises)
 f    # flatten
  Ċ   # counts of every element
   ↑  # get the maximum element by its tail
    t # tail

Vyxal, 7 bytes

∩÷rfĊ↑t

Try it online! The original solution, taking a list of pairs. This transposes then item splits ÷ first, before continuing with the solution above.

R, 40 bytes

\(x,y)max(table(unlist(Map(seq,x,y-1))))

Attempt This Online!

Takes input as two vectors - of starts and ends of the travels.

Jelly, 7 bytes

‘r"FĠẈṀ

Try it online!

-2 bytes: Takes start stations and end stations as separate lists.

‘r"FĠẈṀ
‘        - increment
 r"      - vectorized range
   F     - flatten
    Ġ    - group indices by value
     Ẉ   - lengths
      Ṁ  - maximum 

Jelly, 7 bytes

r/ṖṬ)SṀ

A monadic Link that accepts a list of pairs of station numbers for the passengers and yields the minimum seat count.

Try it online!

How?

r/ṖṬ)SṀ - Link: list of pairs of positive integers, P
    )   - for each (board, alight) in P:
 /      -   reduce by:
r       -     inclusive range -> [board, board+1, ..., alight]
  Ṗ     -   pop (the passenger does not need their seat at their destination)
   Ṭ    -   untruth - e.g. [3,4,5] -> [0,0,1,1,1]
     S  - sum (the columns of that)
      Ṁ - maximum

Excel (ms365), 111 bytes

enter image description here

Formula in D1:

=MAX(BYROW(A1:B5,LAMBDA(a,LET(x,SEQUENCE(MAX(a)-MIN(a),,MIN(a)+1),MAX(COUNTIFS(A1:A5,"<="&x,B1:B5,">"&x),1)))))

Charcoal, 19 17 15 bytes

I⌈EθΣEθ№…⌊λ⌈λ⌊ι

Try it online! Link is to verbose version of code. Edit: Saved 2 bytes by using Minimum and Maximum to obtain the starting and ending stations for each passenger. Saved a further 2 bytes by only checking the starting stations instead of all stations, which allowed me to rewrite the expression to make it work on TIO as well as ATO. Explanation:

   θ            Input journeys
  E             Map over passengers
      θ         Input journeys
     E          Map over passengers
       №        Count of
             ⌊  Starting station of
              ι Outer passenger in
        …       Range from
         ⌊      Starting station of
          λ     Inner passenger to
           ⌈    Ending station of
            λ   Inner passenger
    Σ           Take the sum
 ⌈              Take the maximum
I               Cast to string
                Implicitly print

Nibbles, 9 bytes (18 nibbles)

`/.=~+!$_~>$,@$,$]

Takes input as lists of start stations and end stations.

`/.=~+!$_~>$,@$,$]
      !$_           # zip input lists together
         ~          # using function:
          >$        #   drop inp1 elements
            ,@      #   from range 1..inp2
     +              # now flatten the list of lists
   =~               # and group elements
              $     # by their own values;      
  .            ,$   # get the length of each group
`/                  # and fold over this list
                 ]  #   returning the maximum

enter image description here

J, 24 20 bytes

[:>./[:+/1=,.I."#./]

Attempt This Online!

Found independently, but conceptually very similar to tsh's python approach.

J, 24 bytes

[:>./[:#/.~@;<@i.@-+&.>]

Try it online!

JavaScript (ES6), 61 bytes

-3 thanks to @l4m2

a=>a.map(g=([p,q])=>p<q&&g([p+1,q],m+=m<(g[p]=-~g[p])),m=0)|m

Try it online!

Pip, 20 bytes

M:($+:{@_Na,b}MUa)Ma

Try It Online!

Factor, 56 bytes

[ [ last2 [a,b) ] map concat histogram values supremum ]

Try it online!

                    ! { { 1 5 } { 2 8 } { 6 9 } { 5 7 } { 4 6 } }
[ last2 [a,b) ] map ! { { 1 2 3 4 } { 2 3 4 5 6 7 } { 6 7 8 } { 5 6 } { 4 5 } }
concat              ! { 1 2 3 4 2 3 4 5 6 7 6 7 8 5 6 4 5 }
histogram           ! H{ { 1 1 } { 2 2 } { 3 2 } { 4 3 } { 5 3 } { 6 3 } { 7 2 } { 8 1 } }
values              ! { 1 2 2 3 3 3 2 1 }
supremum            ! 3

Python3, 237 bytes:

lambda x:min(f(x))
def f(x):
 q=[(x,[])]
 while q:
  a,b=q.pop(0)
  if[]==a:yield len(b);continue
  for I,i in enumerate(b):
   if all(y<=a[0][0]or a[0][1]<=x for x,y in i):q+=[(a[1:],b[:I]+[[*i,a[0]]]+b[I+1:])]
  q+=[(a[1:],b+[[a[0]]])]

Try it online!