You are viewing a single comment's thread. Return to all comments →
c#
private static int traverse(List<List<int>> petrolpumps, int start) { int curr_pet = petrolpumps[start][0] - petrolpumps[start][1]; if (curr_pet <= 0) { return traverse(petrolpumps, start + 1); } int i = start + 1 > petrolpumps.Count - 1 ? 0 : start + 1; while (i != start) { curr_pet += (petrolpumps[i][0] - petrolpumps[i][1]); if (curr_pet <= 0) { break; } i++; if (i == petrolpumps.Count) { i = 0; } } if (i != start) { return traverse(petrolpumps, start + 1); } else { return start; } } public static int truckTour(List<List<int>> petrolpumps) { return traverse(petrolpumps, 0); }
passed all test cases
Seems like cookies are disabled on this browser, please enable them to open this website
Truck Tour
You are viewing a single comment's thread. Return to all comments →
c#
passed all test cases