Amazon Interview Question
Software Engineer / DevelopersCountry: United States
Interview Type: In-Person
is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.
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.
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.
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.
static void generate_sequence(int A)
- nitin May 11, 2012{
int seq[]=new int[100];
for(int i=0;i<100;++i)
seq[i]=0;
int k,j=0;
while(A>=2 && j<100)
{
if(A%2==0)
{
seq[j++]=A/2;
A/=2;
}
else
{
seq[j++]=A-1;
A=A-1;
}
}
System.out.println("Shortest Possible sequence will be as:");
for(k=0;seq[k]!=0;++k)
System.out.print(seq[k]+" ");
System.out.println("\nnumber of factors used will be as:"+k+"");
}
Here the idea is that we have to consider two cases :
1) if the number n is odd then i am dividing it as (n-1) and 1 as 1 is anyhow there in the sequence so only an even factor (n-1) is introduced.
2) if the number n is even then simply divide it as (n/2) and (n/2) so in this too effectively one factor will be introduced.
Complexity of it will be O(lgA)
Please suggest if any improvement is possible