java,arrays,maximum-profit-problem

There is no need to use a nested loop, there is a linear time algorithm that can solve this problem. There is a very detailed explanation of the algorithm here. Here is how you could fix your code: public double maxProfit(double[] prices) { if (prices.length <= 1) return 0; double...

php,algorithm,logic,maximum-profit-problem

Looks like a variant of the Activity Selection Problem. Read this TopCoder Tutorial for an excellent explanation....