1. Given a list of transactions, group by name and currency.
Sample Input
| Id | Name | Amount | Currency |
| 1 | Puneet | 200 | INR |
| 2 | Puneet | 3000 | USD |
| 3 | Puneet | 20 | INR |
| 4 | Puneet | 50 | USD |
| 5 | Sahil | 40 | USD |
| 6 | Sahil | 30 | USD |
| 7 | Sahil | 230 | INR |
| 8 | Sahil | 520 | INR |
Sample Output
| Puneet | 220 | INR |
| Puneet | 3050 | USD |
| Sahil | 750 | INR |
| Sahil | 70 | USD |
Java Code
// Grouping by name and currency, then summing amounts
Map<String, Map<String, Integer>> grouped = transactions.stream()
.collect(Collectors.groupingBy(
Transaction::getName,
Collectors.groupingBy(
Transaction::getCurrency,
Collectors.summingInt(Transaction::getAmount)
)
));
// Printing the result
grouped.forEach((name, currencyMap) -> {
currencyMap.forEach((currency, totalAmount) -> {
System.out.println(name + "\t" + totalAmount + "\t" + currency);
});
});




