Problem 60341. Family Savings Analysis
Given the bank accounts of individuals defined by a list of tuples containing the last name, first name, and savings:
accounts = {
'Smith', 'John', 2500;
'Johnson', 'Fred', 5000;
'Williams', 'Nicolas', 10000;
'Brown', 'Phillip', 1250;
'Jones', 'Alice', 4530;
'Garcia', 'Ahmed', 2200;
'Brown', 'Bernard', 0;
'Johnson', 'Steven', 1670;
'Brown', 'Sylvia', 3;
'Williams', 'Bernard', 300000
};
we consider that individuals with the same last name (first entry of each tuple) are from the same family. If an individual has no attributed income, we consider their savings as zero (as for Bernard Brown).
Write a function that returns the name of the family with the highest strictly positive savings along with the amount of their savings.
Special cases to consider:
- If multiple families have the same highest positive savings, the function should return all these families (test 6).
- If no family has strictly positive savings, the function should return an empty string for the family name(s) and 0 for the savings (test 5).
Solution Stats
Problem Comments
-
1 Comment
Dyuman Joshi
on 16 Jun 2024
IMO, it would be better to use strcmp() to compare for text data, instead of isequal().
Otherwise, data type conversion has to be performed, which is unnecessary (for a lack of a better word).
Solution Comments
Show commentsProblem Recent Solvers6
Suggested Problems
-
3093 Solvers
-
9078 Solvers
-
184 Solvers
-
47 Solvers
-
Edges of a n-dimensional Hypercube
82 Solvers
More from this Author53
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!