public int maxProfitRange(int startIndex, int endIndex, int[] prices) {
		int maxProfit = 0;

		if (endIndex == startIndex) {
			return maxProfit;
		}

		// only two numbers in range
		if (endIndex - startIndex == 1) {
			int curProfit = prices[endIndex] - prices[startIndex];
			if (curProfit > maxProfit)
				maxProfit = curProfit;
			return maxProfit;
		}

		for (int i = startIndex; i < endIndex; i++) {
			for (int j = i + 1; j <= endIndex; j++) {
				int curProfit = prices[j] - prices[i];
				if (curProfit > maxProfit)
					maxProfit = curProfit;
			}
		}

		return maxProfit;
	}