private int[] maxOneTimeProfit(int[] prices, int start, int end) {
        int bestBuy = -1, bestSell = -1, bestProfit = 0;
        int currentLow = start;

        for (int i = start; i < end; i++) {
            int price = prices[i];

            if (i < end - 1 && price < prices[i + 1]) {
                if (price <= prices[currentLow]) {
                    currentLow = i;
                }
            }

            if (i == end - 1 || price > prices[i + 1]) {
                int profit = price - prices[currentLow];

                if (profit > bestProfit) {
                    bestBuy = currentLow;
                    bestSell = i;
                    bestProfit = profit;
                }
            }
        }

        return new int[] {bestBuy, bestSell, bestProfit};
    }