We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Electronics Shop
Electronics Shop
Sort by
recency
|
2369 Discussions
|
Please Login in order to post a comment
Here is my c++ solution, you can find the video here : https://youtu.be/yC-TXToDbD0
//Golang Solution func getMoneySpent(keyboards []int32, drives []int32, b int32) int32 {
}
O(nlogn)+O(mlogm)+O(n+k) solution
The logic is simple, we sort both the arrays, then put pointer 1 on the end of 1 array and pointer 2 at the start of the other. Then just like doing 2 pointer problems, if the sum of value at pointer 1 + pointer 2 is less or equal than our target value, we store the result and increment pointer 2, if its greater then we decrement pointer 1, thereby only traversing both arrays only once.
`int getMoneySpent(vector keyboards, vector drives, int b) { int n{static_cast(keyboards.size())}; int m{static_cast(drives.size())};
}