
Minimize Cash Flow Problem
You are provided with a list of 'transactions' involving 'n' friends who owe each other money. Each entry in the list contains information about a receiver, sender, and the transaction amount. Your task is to optimize and minimize the cash flow among them.
Input:
The first line of input includes an integer 'T', the number of test cases. Each test case starts with a line containing 'n', the number of friends. The following 'n' lines contain 'n' space-separated integers, where 'arr[i][j]' is the amount the 'i-th' friend should pay to the 'j-th' friend.
Output:
Output a 2-D matrix for every test case that illustrates the minimized cash flow. Each test case result should be presented on a separate line.
Example:
Example figures: In figure 1, friend-1 owes 2000$ to friend-2 and 4000$ to friend-3, and friend-2 owes 3000$ to friend-3. In figure 2, the cash flow is minimized by having friend-1 directly pay to friend-3.
Constraints:
- 1 <= T <= 5
- 1 <= N <= 1000
- 0 <= arr[i][j] <= 10^9
- Time Limit: 1 sec
Note:
There is no need to print the result as it is already handled. Focus on implementing the function that provides the solution.

AnswerBot
10d

Minimize cash flow among friends by optimizing transactions.
Create a graph where nodes represent friends and edges represent transactions.
Calculate net amount each friend owes or is owed by summing up...read more

Help your peers!
Add answer anonymously...
Top Paytm Software Developer interview questions & answers
Popular interview questions of Software Developer
Top HR questions asked in Paytm Software Developer
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app