{"id":22513974,"url":"https://github.com/emahtab/car-pooling","last_synced_at":"2026-01-06T20:51:19.884Z","repository":{"id":79525343,"uuid":"429842938","full_name":"eMahtab/car-pooling","owner":"eMahtab","description":null,"archived":false,"fork":false,"pushed_at":"2021-11-19T15:25:32.000Z","size":4,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-02T03:26:16.499Z","etag":null,"topics":["car-pooling","leetcode"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/eMahtab.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-11-19T15:19:19.000Z","updated_at":"2021-11-19T15:26:15.000Z","dependencies_parsed_at":"2023-05-10T17:00:27.430Z","dependency_job_id":null,"html_url":"https://github.com/eMahtab/car-pooling","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Fcar-pooling","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Fcar-pooling/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Fcar-pooling/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Fcar-pooling/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eMahtab","download_url":"https://codeload.github.com/eMahtab/car-pooling/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245952358,"owners_count":20699472,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["car-pooling","leetcode"],"created_at":"2024-12-07T03:15:27.611Z","updated_at":"2026-01-06T20:51:19.857Z","avatar_url":"https://github.com/eMahtab.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Car Pooling\n## https://leetcode.com/problems/car-pooling\nThere is a car with capacity empty seats. The vehicle only drives east (i.e., it cannot turn around and drive west).\n\nYou are given the integer capacity and an array trips where trip[i] = [numPassengersi, fromi, toi] indicates that the ith trip has numPassengersi passengers and the locations to pick them up and drop them off are fromi and toi respectively. \n\nThe locations are given as the number of kilometers due east from the car's initial location.\n\nReturn true if it is possible to pick up and drop off all passengers for all the given trips, or false otherwise.\n\n \n```\nExample 1:\n\nInput: trips = [[2,1,5],[3,3,7]], capacity = 4\nOutput: false\n\nExample 2:\n\nInput: trips = [[2,1,5],[3,3,7]], capacity = 5\nOutput: true\n\nExample 3:\n\nInput: trips = [[2,1,5],[3,5,7]], capacity = 3\nOutput: true\n\nExample 4:\n\nInput: trips = [[3,2,7],[3,7,9],[8,3,9]], capacity = 11\nOutput: true\n``` \n\n### Constraints:\n```\n1 \u003c= trips.length \u003c= 1000\ntrips[i].length == 3\n1 \u003c= numPassengersi \u003c= 100\n0 \u003c= fromi \u003c toi \u003c= 1000\n1 \u003c= capacity \u003c= 105\n```\n\n\n# Implementation : Cumulative Sum\n```java\nclass Solution {\n    public boolean carPooling(int[][] trips, int capacity) {\n        if(trips == null || trips.length == 0)\n            return true;\n        int lastDropLocation = Integer.MIN_VALUE;\n        for(int[] trip : trips)\n            lastDropLocation = Math.max(lastDropLocation, trip[2]);\n        \n        int[] journey = new int[lastDropLocation + 1];\n        for(int[] trip : trips) {\n            journey[trip[1]] += trip[0];\n            journey[trip[2]] -= trip[0];    \n        }\n        for(int i = 0; i \u003c= lastDropLocation; i++) {\n            if(i != 0)\n            journey[i] += journey[i-1];\n            if(journey[i] \u003e capacity)\n                return false;\n        }\n        return true;\n    }\n}\n```\n\n# References :\nhttps://www.youtube.com/watch?v=nO95uYKB-lo (Good explanation)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femahtab%2Fcar-pooling","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Femahtab%2Fcar-pooling","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femahtab%2Fcar-pooling/lists"}