Category : algorithm

This code makes a subarray out of given vector and checks whether all elements are appeared even number of times in the subarray we are taking range as an input to create new subarray #include <bits/stdc++.h> #include <iostream> using namespace std; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin>>n; int v[n]; for(int i=0;i<n;i++){ cin>>v[i];} int q; ..

Read more

This code makes a subarray out of given vector and checks whether all elements are appeared even number of times in the subarray we are taking range as an input to create new subarray #include <bits/stdc++.h> #include <iostream> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; int v[n]; for (int ..

Read more

So there’s an algorithm to find the minimum cash flow among people (ie: to find the minimum number of transactions among people ) (source :https://www.geeksforgeeks.org/minimize-cash-flow-among-given-set-friends-borrowed-money/) But the algorithm isn’t completely accurate Consider the following test case : enter image description here When you input this the output says that there must be 5 transactions however ..

Read more

There are r red balls, g green balls and b blue balls. Also there are infinite number of packets given to you. Each packet must be filled with only 3 balls and should contain balls of at least 2 different colors. Find the maximum number of packets that can be filled? Here is my approach ..

Read more