Two City Scheduling | LeetCode 1029 | C++, Java, Python

preview_player
Показать описание

**** Best Books For Data Structures & Algorithms for Interviews:**********
*****************************************************************************

June LeetCoding Challenge | Problem 3 | Two City Scheduling | 3 June,
Facebook Coding Interview question,
google coding interview question,
leetcode,
Two City Scheduling,
Two City Scheduling c++,
Two City Scheduling Java,
Two City Scheduling python,
Two City Scheduling solution,
1029. Two City Scheduling,

#Facebook #CodingInterview #LeetCode #JuneLeetCodingChallenge #Google #Amazon #TwoCityScheduling
Рекомендации по теме
Комментарии
Автор

Good Video, I Just optimized the two for loops in the end to sum the values
int n = costs.length/2;

for(int i = 0; i<n; ++i) {
total += costs[i][0] + costs[i+n][1];
}

pmulchandani
Автор

Thank you for such a clear & descriptive solution! I just watched 45sec and understood the gist of the problem & solved it.

srishtikumar
Автор

Love the way you explain things! Thanks a lot.

wcemkfd
Автор

Why do we need "-" instead of "<" for the Java solution?

andreigabor
Автор

Sir what is a[0]-a[1]&b[0]-b[1]?
please reply

manishpanwar
Автор

I wrote the solution this way can anyone tell me my mistake

class Solution {
public:
int costs) {
int sum = 0;
map<int, pair<int, int> > mp;
for(int i=0;i<costs.size();i++){
mp.insert({costs[i][0]-costs[i][1], {costs[i][0], costs[i][1]}});
}
int i = 0;
for(auto it =
if(i<costs.size()/2){
sum+=costs[i][0];
}
else{
sum+=costs[i][1];
}
i++;
}

return sum;
}
};

shivanktripathi
welcome to shbcf.ru