Question
Smallest Negative Balance You are working on a new application for recording debts. This program allows users to create groups that show all records of
Smallest Negative Balance You are working on a new application for recording debts. This program allows users to create groups that show all records of debts between the group members. Given the group debt records (including the borrower name, lender name, and debt amount), who in the group has the smallest negative balance? Notes: -10 is smaller than-1 If multiple people have the smallest negative balance, return the list in alphabetical order. If nobody has a negative balance, return the string "Nobody has a negative balance". Example n = 6 debts = ['Alex Blake 2', 'Blake Alex 2, 'Casey Alex 5, 'Blake Casey 7', 'Alex Blake 4', 'Alex Casey 4'] There are 6 debt records, as shown in the table below: borrower lender Alex Blake N Blake Alex 2 Carou borrower lender Alex Blake Blake Alex Casey Alex Blake Casey Alex Blake Alex Casey The first, fifth, and sixth entries decrease Alex's balance because Alex is a borrower in them. The second and third entries increase it because Alex is a lender. So, Alex's balance is (2+5) - (2+4+4) = 7-10 = -3. Blake is a lender in the first and fifth entries and a borrower in the second and fourth entries. Thus, Blake's balance is (2+4) - (2+7) = 6 -9 = -3. Casey is a lender in the third entry and a borrower in the fourth and sixth entries. Thus, Casey's balance is (7+4) - 5 = 6. . The answer (in alphabetical order) is ["Alex". Blake"] because both of them have a balance of 3, which is the minimum among all members. Sunction the debt amount Returns string(): an array of strings denoting an alphabetically ordered list of members with the smallest negative balance, or an array containing the string "Nobody has a negative balance" Constraints . 1sns 2x105 debts[1][2] represents an integer between 1 and 1000 inclusively. 1 s length of debts[0][0), length of debts[0][1]* 20 The first character of debts[00) and debts[0][1] is capital English letter. Every character of debts[0]) and debts[i[1] except the first one is lowercase English letter. debts[ilo] # debts[0[1]. . Input Format For Custom Testing Sample Case 0 Sample Input For Custom Testing STDIN Function 5 3 Alex Blake Is Blake Alex 3 Casey Alex 7 debts[] size n = 5 debts[i] size = 3 (al debts = [['Alex', 'B1 ['Casey', #include using namespace std; string ltrim(const string &); string rtrim(const string &); vector split(const string &); I * Complete the smallestNegativeBalance' function below. * * The function is expected to return a STRING_ARRAY. * The function accepts 2D_STRING_ARRAY debts as parameter. */ 7 vector smallestNegativeBalance (vector debts) { 9 } 22 > int main() -
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started