| Bytes | Lang | Time | Link |
|---|---|---|---|
| 184 | Python3 | 250825T171213Z | Ajax1234 |
| 072 | Scala | 230411T090834Z | 138 Aspe |
| 020 | Charcoal | 221224T215904Z | Neil |
| 060 | JavaScript Node.js | 221224T154907Z | l4m2 |
| 044 | R | 221224T144511Z | Dominic |
| 010 | Jelly | 221224T131034Z | AndrovT |
Python3, 184 bytes
def f(p):
l,r=[],[]
while p:
if[]==l:l+=[p.pop()]
u=[[],[]]
for x,y in p:u[any(X<y for X,Y in l)]+=[(x,y)]
l+=u[1];p=u[0]
if[]==u[1]:r+=[l];l=[]
return max(map(len,r+[l]))
Scala, 72 bytes
Modified from @AndrovT's answer
Golfed version, try it online!
def f(t:List[Interval]):Int={t.map{v=>t.count{w=>w.r>v.l&&v.r>w.l}}.max}
Ungolfed version
object Main {
def main(args: Array[String]): Unit = {
val intervals = List(Interval(1, 5), Interval(2, 8), Interval(6, 9), Interval(5, 7), Interval(4, 6))
println(maxOverlap(intervals))
}
case class Interval(l: Int, r: Int)
def maxOverlap(intervals: List[Interval]): Int = {
intervals.map { v =>
intervals.count { w =>
w.r > v.l && v.r > w.l
}
}.max
}
}
Charcoal, 20 bytes
UMθ…⌊ι⌈ιI⌈EθLΦθ⁻ι⁻ιλ
Try it online! Link is to verbose version of code. Explanation: Assumes that @AndrovT's interpretation of the problem is correct.
UMθ…⌊ι⌈ι
Turn each starting and ending pair into a range.
I⌈EθLΦθ⁻ι⁻ιλ
For each passenger, do double set difference to see whether how many ranges intersect with other passengers and output the maximum.
JavaScript (Node.js), 60 bytes
x=>Math.max(...x.map(v=>x.map(w=>n+=w.r>v.l&v.r>w.l,n=0)|n))
Same approach as AndrovT
R, 44 bytes
\(a,b)max(rowSums((d=sapply(a,`<`,b))&t(d)))
Same approach as AndrovT (upvote that!), combined with the observation that we can just calculate a single matrix of start-greater-than-stops, and AND it with itself after transposing to get the matrix of all passenger overlaps.
Calculating the matrix is easy in R by taking input as two lists, one of starts and one of stops, and using a vectorized greater-than comparison.
Jelly, 10 bytes
<>ƭ"Ạ¥þUSṀ
The goal is to find the passenger that whose journey overlaps with the most other passengers. The result is that number +1.
<>ƭ"Ạ¥þUSṀ
þU - outer product with itself with reversed elements
<>ƭ"Ạ¥ - takes [a, b], [c, d] and returns a<c && b>d
S - sum rows
Ṁ - maximum