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
Solution Comments
Show comments
Loading...
Problem Recent Solvers6
Suggested Problems
-
Extract leading non-zero digit
2246 Solvers
-
6714 Solvers
-
432 Solvers
-
Sum of diagonal of a square matrix
1637 Solvers
-
Calculate the Hamming distance between two strings
346 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!
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).