Bus Conductor Coding Solution Geeks for Geeks Problem of the Day 21 May 2023
Gfg problem of the day solution with explanation
You are conductor of a bus ... Return the minimum number of moves required
GFG POTD Solution Today
C++
class Solution {
public:
int findMoves(int n, vector<int> chairs, vector<int> passengers) {
sort(chairs.begin(), chairs.end());
sort(passengers.begin(), passengers.end());
int ans=0;
for(int i=0;i<n;i++){
ans=ans+abs(passengers[i]-chairs[i]);
}
return ans;
}
};
Input:
chairs = [3,1,5]
passengers = [2,7,4]
Output: 4
Input:
chairs = [2,2,6,6]
passengers = [1,3,2,6]
Output: 4
GFG POTD Answer in C++
Gfg problem of the day in python
Gfg problem of the day in java
Comments
Post a Comment