Amazon Interview Question
SDE1sCountry: India
Interview Type: In-Person
public class AIQ {
public static void main(String args[]) {
int process[] = {3,5,7};
int core[] = {1,3,5};
System.out.println(findMaxProcessAllocation(process,core));
}
public static int findMaxProcessAllocation(int[] process,int[] core){
int maxCore = findMaxCore(core);
int result = 0;
for(int i=0;i<process.length;i++){
if(process[i] <= maxCore){
result++;
}
}
return result;
}
public static int findMaxCore(int[] core){
int max = 0;
for(int i=0;i<core.length;i++){
if(core[i] > max){
max = core[i];
}
}
return max;
}
}
public class AIQ {
public static void main(String args[]) {
int process[] = {3,5,7};
int core[] = {1,3,5};
System.out.println(findMaxProcessAllocation(process,core));
}
public static int findMaxProcessAllocation(int[] process,int[] core){
int maxCore = findMaxCore(core);
int result = 0;
for(int i=0;i<process.length;i++){
if(process[i] <= maxCore){
result++;
}
}
return result;
}
public static int findMaxCore(int[] core){
int max = 0;
for(int i=0;i<core.length;i++){
if(core[i] > max){
max = core[i];
}
}
return max;
}
}
public class AIQ {
public static void main(String args[]) {
int process[] = {3,5,7};
int core[] = {1,3,5};
System.out.println(findMaxProcessAllocation(process,core));
}
public static int findMaxProcessAllocation(int[] process,int[] core){
int maxCore = findMaxCore(core);
int result = 0;
for(int i=0;i<process.length;i++){
if(process[i] <= maxCore){
result++;
}
}
return result;
}
public static int findMaxCore(int[] core){
int max = 0;
for(int i=0;i<core.length;i++){
if(core[i] > max){
max = core[i];
}
}
return max;
}
}
and
public class AIQ {
public static void main(String args[]) {
int process[] = {3,5,7};
int core[] = {1,3,5};
System.out.println(findMaxProcessAllocation(process,core));
}
public static int findMaxProcessAllocation(int[] process,int[] core){
int maxCore = findMaxCore(core);
int result = 0;
for(int i=0;i<process.length;i++){
if(process[i] <= maxCore){
result++;
}
}
return result;
}
public static int findMaxCore(int[] core){
int max = 0;
for(int i=0;i<core.length;i++){
if(core[i] > max){
max = core[i];
}
}
return max;
}
}
and
public class AIQ {
public static void main(String args[]) {
int process[] = {3,5,7};
int core[] = {1,3,5};
System.out.println(findMaxProcessAllocation(process,core));
}
public static int findMaxProcessAllocation(int[] process,int[] core){
int maxCore = findMaxCore(core);
int result = 0;
for(int i=0;i<process.length;i++){
if(process[i] <= maxCore){
result++;
}
}
return result;
}
public static int findMaxCore(int[] core){
int max = 0;
for(int i=0;i<core.length;i++){
if(core[i] > max){
max = core[i];
}
}
return max;
}
}
and
It seems were trying to optimally allocate CPU given a multiple tasks.
public class AllocateCPU{
public static void main(String []args){
int[] cpu = new int[] {1, 3, 5};
int[] task = new int[] {3, 5, 7};
int match = 0;
for(int i = 0; i < cpu.length; i++) {
for(int j = 0; j < task.length; j++) {
if(cpu[i] >= task[j]) {
match++;
break;
}
}
}
System.out.println(match);
}
}
The idea is to accommodate "cheapest" tasks first using a cpu with the least free cores.
- adr July 23, 2018