Oracle Interview Question
Senior Software Development EngineersCountry: India
Interview Type: In-Person
class MaxProfit{
public static int maxProfit(int[] stockPrices){
int profit = 0;
for(int i=0; i<stockPrices.length-1; ++i)
for(int j=i+1; j<stockPrices.length; ++j)
if(profit < stockPrices[j] - stockPrices[i])
profit = stockPrices[j] - stockPrices[i];
return profit;
}
public static void main(String[] args) {
int[] stockPrices = {8, 6, 3, 1, 10, 6, 20, 7};
// int[] stockPrices = {8, 6, 3, 2, 1};
System.out.println(maxProfit(stockPrices));
}
}
I think Question 2 would be like this-
- Deval Mehta August 05, 2018Prove that complexity for searching in arraylist is o(1) and adding is o(n).
Please make sure question is correct or not