## Oracle Interview Question for Senior Software Development Engineers

• 0

Country: India
Interview Type: In-Person

Comment hidden because of low score. Click to expand.
0
of 0 vote

``````int A[] = {100, 180, 260, 310, 40,40, 535, 695};
//int A[] = {100, 90, 80, 70, 60, 30, 20,21};

int min = A; // Lets assume first element is minimum
int maxProfit = 0; // 0 profit, if we buy & sell on same day.
int profit = 0;
int minIndex = 0; // Index of buy date
int maxIndex = 0; // Index of sell date

//Run the loop from next element
for (int i = 1; i < A.length; i++) {
//Keep track of minimum buy price & index
if (A[i] <= min) {
min = A[i];
minIndex = i;
}
//System.out.println("min: " + min);
profit = A[i] - min;
//If new profit is more than previous profit, keep it and update the max index
if (profit > maxProfit) {
maxProfit = profit;
maxIndex = i;
}
//System.out.println("max: " + A[maxIndex]);
}
if(maxProfit>0){
System.out.println("maxProfit is "+maxProfit);
System.out.println("buy @ "+ (minIndex+1) + " day");
System.out.println("sell @ "+ (maxIndex+1) + " day");
}
else{
System.out.println("No day where we can earn profit!");
}``````

Comment hidden because of low score. Click to expand.
0
of 0 vote

``````int A[] = {100, 180, 260, 310, 40,40, 535, 695};
//int A[] = {100, 90, 80, 70, 60, 30, 20,21};

int min = A; // Lets assume first element is minimum
int maxProfit = 0; // 0 profit, if we buy & sell on same day.
int profit = 0;
int minIndex = 0; // Index of buy date
int maxIndex = 0; // Index of sell date

//Run the loop from next element
for (int i = 1; i < A.length; i++) {
//Keep track of minimum buy price & index
if (A[i] <= min) {
min = A[i];
minIndex = i;
}
//System.out.println("min: " + min);
profit = A[i] - min;
//If new profit is more than previous profit, keep it and update the max index
if (profit > maxProfit) {
maxProfit = profit;
maxIndex = i;
}
//System.out.println("max: " + A[maxIndex]);
}
if(maxProfit>0){
System.out.println("maxProfit is "+maxProfit);
System.out.println("buy @ "+ (minIndex+1) + " day");
System.out.println("sell @ "+ (maxIndex+1) + " day");
}
else{
System.out.println("No day where we can earn profit!");
}``````

Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

### Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

### Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.