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
4mo
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...
Paytm Software Developer interview questions & answers
A Software Developer was asked 3mo agoQ. Given a sorted array of integers nums and an integer target, write a function to...read more
A Software Developer was asked 7mo agoQ. Given a 2D grid map of '1's (land) and '0's (water), count the number of islands...read more
A Software Developer was asked 8mo agoQ. Given a binary tree, return the vertical order traversal of its nodes' values. (...read more
Popular interview questions of Software Developer
A Software Developer was asked 7mo agoQ1. Given a 2D grid map of '1's (land) and '0's (water), count the number of islands...read more
A Software Developer was asked 8mo agoQ2. Given a binary tree, return the vertical order traversal of its nodes' values. (...read more
A Software Developer was asked 9mo agoQ3. Given a graph and a source node, find the shortest path from the source to all o...read more
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

