## Akamai Interview Question for Computer Scientists

Country: India
Interview Type: Phone Interview

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

which algorithm i have to used ?? for this problem ???

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

import java.util.Scanner;
class Shil_Treasure {

private static Scanner scan;

static long LCM(long x, long y)
{
long a;
a = (x > y) ? x : y; // a is greater number
while(true)
{
if(a % x == 0 && a % y == 0)
return a;
++a;
}
}

public static void main(String [] args) {
int n,i,nq;
scan = new Scanner(System.in);
n=scan.nextInt();
int[] a=new int[n];
int[] q1=new int[n];
int[] q2=new int[n];
int[] q3=new int[n];
for(i=0;i<n;i++)
{
a[i]=(int) scan.nextLong();
}
nq=(int) scan.nextLong();
for(i=0;i<nq;i++)
{
q1[i]=(int) scan.nextLong();
q2[i]=(int) scan.nextLong();
q3[i]=(int) scan.nextLong();
}
for(i=0;i<nq;i++)
{
if(q1[i]==1)
{
a[q2[i]-1]=q3[i];
}
else if(q1[i]==2)
{
System.out.println(LCM(a[q2[i]-1],a[q3[i]-1]));
}

}
}
}

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

import java.util.Scanner;
class Shil_Treasure {

private static Scanner scan;

static long LCM(long x, long y)
{
long a;
a = (x > y) ? x : y; // a is greater number
while(true)
{
if(a % x == 0 && a % y == 0)
return a;
++a;
}
}

public static void main(String [] args) {
int n,i,nq;
scan = new Scanner(System.in);
n=scan.nextInt();
int[] a=new int[n];
int[] q1=new int[n];
int[] q2=new int[n];
int[] q3=new int[n];
for(i=0;i<n;i++)
{
a[i]=(int) scan.nextLong();
}
nq=(int) scan.nextLong();
for(i=0;i<nq;i++)
{
q1[i]=(int) scan.nextLong();
q2[i]=(int) scan.nextLong();
q3[i]=(int) scan.nextLong();
}
for(i=0;i<nq;i++)
{
if(q1[i]==1)
{
a[q2[i]-1]=q3[i];
}
else if(q1[i]==2)
{
System.out.println( LCM(a[q2[i]-1],a[q3[i]-1])%1000000007 );
}

}
}
}

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