Oracle Interview Question for Developer Program Engineers


Country: India
Interview Type: Written Test




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

import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;

public class Metals {

	public static void main(String[] args) {
		Scanner scanner=new Scanner(new InputStreamReader(System.in));
		
		int i=1;
		int costpercut=scanner.nextInt();
		int price=scanner.nextInt();
		int n=scanner.nextInt();
		int arr[] =new int[n];
		for (int j = 0; j < n; j++) {
			arr[j]=scanner.nextInt();
		}	
		Arrays.sort(arr);
		int maxItem=arr[arr.length-1];
		int k=0;
		
		int max=1;
		while (i<=maxItem) {
			int val=0;
			for (int j = k; j < arr.length; j++) {
				val=(price*i*(arr[j]/i))-(costpercut*(arr[j]/i))+val;
			}
			i++;
			for (int j = 0; j < arr.length; j++) {
				if (i>arr[j]) {
					k=j;
				}
			}
			
			if (val>max) {
				max=val;
			}
		}
		
		System.out.println(max);
	}
}

- prasenjit June 04, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;

public class Metals {

public static void main(String[] args) {
Scanner scanner=new Scanner(new InputStreamReader(System.in));

int i=1;
int costpercut=scanner.nextInt();
int price=scanner.nextInt();
int n=scanner.nextInt();
int arr[] =new int[n];
for (int j = 0; j < n; j++) {
arr[j]=scanner.nextInt();
}
Arrays.sort(arr);
int maxItem=arr[arr.length-1];
int k=0;

int max=1;
while (i<=maxItem) {
int val=0;
for (int j = k; j < arr.length; j++) {
val=(price*i*(arr[j]/i))-(costpercut*(arr[j]/i))+val;
}
i++;
for (int j = 0; j < arr.length; j++) {
if (i>arr[j]) {
k=j;
}
}

if (val>max) {
max=val;
}
}

System.out.println(max);
}
}

- prasenjit June 04, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Can you please explain the logic you implemente I am not getting it ..

- Adil Muthukoya February 18, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Sample Input #1: 
cut_cost = 1 
unit_price = 10 
lengths = [26, 103, 59] 

Sample Output #1: 
1770

Could you please give the answer L?

- Anonymous March 21, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void main(String[] args) {
Scanner scanner=new Scanner(new InputStreamReader(System.in));
int costpercut=scanner.nextInt();
int price=scanner.nextInt();
int n=scanner.nextInt();
int arr[] =new int[n];
for (int j = 0; j < n; j++) {
arr[j]=scanner.nextInt();
}
int max = arr[0];
int maxProfit = 0;
for(int i = 0 ; i < arr.length; i++)
if(max < arr[i])
max = arr[i];
for(int size = 1 ; size <= max; size++) {
int profit = 0;
for(int i = 0 ; i < arr.length; i++) {
if(size > arr[i])
continue;
int currPrice = (arr[i] / size) * price * size; // current Rod price after cutting it.
int cuts = arr[i] % size == 0 ? (arr[i] / size) - 1 : (arr[i] / size); // Number of cuts depend on the length of rod.
int currProfit = currPrice - costpercut * cuts;
if(currProfit > 0)
profit += currProfit;
}
if(profit > maxProfit)
maxProfit = profit;
}

System.out.println(maxProfit);
}

- Piyush September 25, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void main(String[] args) {
    Scanner scanner=new Scanner(new InputStreamReader(System.in));
    int costpercut=scanner.nextInt();
    int price=scanner.nextInt();
    int n=scanner.nextInt();
    int arr[] =new int[n];
    for (int j = 0; j < n; j++) {
        arr[j]=scanner.nextInt();
    }   
    int max = arr[0];
    int maxProfit = 0;
    for(int i = 0 ; i < arr.length; i++)
        if(max < arr[i])
            max = arr[i];
    for(int size = 1 ; size <= max; size++) {
        int profit = 0;
        for(int i = 0 ; i < arr.length; i++) {
            if(size > arr[i])
                continue;
            int currPrice = (arr[i] / size) * price * size; // current Rod price after cutting it.
            int cuts = arr[i] % size == 0 ? (arr[i] / size) - 1 : (arr[i] / size); // Number of cuts depend on the length of rod.
            int currProfit = currPrice - costpercut * cuts;
            if(currProfit > 0)
                profit += currProfit;
        }
        if(profit > maxProfit)
            maxProfit = profit;
    }

    System.out.println(maxProfit);
}

- Piyush September 25, 2016 | Flag Reply


Add a Comment
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.

Learn More

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.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More