I have an array of flights that were flown for an airline. Each Element in that array looks like this:
[
'aircraft' => 'aircraft type',
'from' => 'departure airport code',
'to' => 'destination airport code'
]
I want to build an algorithm that determines the fleet size of that airline.
Every aircraft in the fleet has at least flown once. Every aircraft can only depart from an airport it has previously landed on.
Example:
Given this array of flights.
[
[
'type' => '747',
'from' => 'Berlin',
'to' => 'New York'
],
[
'type' => '747',
'from' => 'New York',
'to' => 'Chicago'
],
[
'type' => '747',
'from' => 'New York',
'to' => 'Cleveland'
],
[
'type' => '747',
'from' => 'Cleveland',
'to' => 'Vancouver'
]
]
We know that the fleet contains 2 747 aircrafts. One which has flown from Berlin -> NewYork -> Cleveland -> Vancouver and one which has flown New York -> Chicago.
But building this is quite difficult as a programm cant easily see this connection (example: where to go from New York?).