exportconstmin_num_taxis=(requests:number[][]):number=>{consttaxis:number[]=[]// sort by dropoff timerequests.sort((reqA,reqB)=>reqA[1]-reqB[1])requests.forEach(request=>{const[pickup,dropoff]=requestletfoundTaxi=falsefor(lettaxi=0;taxi<=taxis.length;taxi++){if(pickup>taxis[taxi]){foundTaxi=truetaxis[taxi]=dropoff}}if(!foundTaxi){taxis.push(dropoff)}})returntaxis.length}
and tests
import{min_num_taxis}from'.'describe('min_num_taxis',()=>{it('should return the number of taxis needed per request',()=>{expect(min_num_taxis([[1,4]])).toBe(1)expect(min_num_taxis([[5,9],[1,4]])).toBe(1)expect(min_num_taxis([[1,4],[2,9],[3,6],[5,8]])).toBe(3)})})
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
My solution in Typescript
and tests