2nd round live coding: From a blank editor write a function that calculates all possible multiplications between a List of Positions and a List of Scenarios - we do not care about what these are and how the calculation works.
Anonymous
private List runAllPossibleCalculations(List positions, List scenarios, final int N) { List> allCalcs = new ArrayList(); List calcs = new ArrayList(); int i = 0; for (Position pos : positions) { for (Scenario scen : scenarios) { calcs.add(calculate(pos, scen)); i++; if (i == N) { i = 0; allCalcs.add(calcs); calcs = new ArrayList(); } } } allCalcs.add(calcs); return allCalcs; }
Check out your Company Bowl for anonymous work chats.