@@ -0,0 +1,1811 @@
+import java.util.Arrays;%0Aimport java.util.Comparator;%0Aimport java.util.stream.IntStream;%0A%0Apublic class StockMarket %7B%0A%0A    static class Trade %7B%0A        double buy;%0A        double sell;%0A%0A        Trade(double buy, double sell) %7B%0A            this.buy = buy;%0A            this.sell = sell;%0A        %7D%0A%0A        @Override%0A        public String toString() %7B%0A            return buy + %22 %22 + sell;%0A        %7D%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        System.out.println(new StockMarket().run(%2219.35 19.30 18.88 18.93 18.95 19.03 19.00 18.97 18.97 18.98%22));%0A        System.out.println(new StockMarket().run(%229.20 8.03 10.02 8.08 8.14 8.10 8.31 8.28 8.35 8.34 8.39 8.45 8.38 8.38%5Cn%22 +%0A                %228.32 8.36 8.28 8.28 8.38 8.48 8.49 8.54 8.73 8.72 8.76 8.74 8.87%5Cn%22 +%0A                %228.82 8.81 8.82 8.85 8.85 8.86 8.63 8.70 8.68 8.72 8.77 8.69 8.65%5Cn%22 +%0A                %228.70 8.98 8.98 8.87 8.71 9.17 9.34 9.28 8.98 9.02 9.16 9.15 9.07%5Cn%22 +%0A                %229.14 9.13 9.10 9.16 9.06 9.10 9.15 9.11 8.72 8.86 8.83 8.70 8.69%5Cn%22 +%0A                %228.73 8.73 8.67 8.70 8.69 8.81 8.82 8.83 8.91 8.80 8.97 8.86 8.81%5Cn%22 +%0A                %228.87 8.82 8.78 8.82 8.77 8.54 8.32 8.33 8.32 8.51 8.53 8.52 8.41%5Cn%22 +%0A                %228.55 8.31 8.38 8.34 8.34 8.19 8.17 8.16%22));%0A    %7D%0A%0A    Trade run(String stockPrices) %7B%0A        return run(Arrays.stream(stockPrices.split(%22%5C%5Cs%22)).mapToDouble(Double::parseDouble).toArray());%0A    %7D%0A%0A%0A    Trade run(double%5B%5D stockPrices) %7B%0A        return IntStream.range(0, stockPrices.length - 1)%0A                .boxed()%0A                .flatMap(i -%3E IntStream.range(i + 2, stockPrices.length)%0A                        .mapToObj(j -%3E new Trade(stockPrices%5Bi%5D, stockPrices%5Bj%5D)))%0A                .max(Comparator.comparingDouble(t -%3E t.sell - t.buy))%0A                .orElse(null);%0A    %7D%0A%7D%0A

Add StockMarket