Amazon Interview Question for Software Engineer / Developers






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

start reading digits from right(lsb) to left(msb)...until u find a smaller digit than the current one..for ex consider i/p = 17365432...start reading from 2->3->4->5->6->3...this is a dip..that we are looking for.
now among the entries seen so far, select those that are greater than current val(3 in example)...so we have 4,5,6...and select the smallest one i.e. 4 in example...'4' takes place of '3' and then rest are just written out in ascending order...
so o/p is 17423356

- Anonymous June 29, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

That I don't think works.

What needs to happen is that iterate from the right to find the first two pairs of digits that are in descending order. Swap the two digits and starting from the number after the swapped higher number's current position, sort the rest of te numbers to the right in ascending order.

So 1743 would first be changed to 3741. Then starting from the digit after 3(the higher of the two swapped digits), the numbers are sorted in ascending order and the resulting number would be 3147.

The complexity is nlogn.

- Gautam August 09, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

can ny1 pls help me with the precise,or post the required link?

- seeker7 July 15, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

This is a generalization of another related problem for binary numbers, see: question id=2502

- Isaac July 18, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

first sort
then do the permutation, until you find the input.
The next one is the target.

- Anonymous August 05, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

void nextHigherPermOp(int a[], int n)
{
	int maxd = a[n - 1];
	int i = n - 2;
	while (a[i] >= maxd)
		maxd = a[i--];
	int piv = i;
	while (a[++i] > a[piv]);
	int tmp = a[piv];
	a[piv] = a[--i];
	a[i] = tmp;
	i = piv+1;
	while (i < (n - i)/2+i)
	{
		tmp = a[i];
		a[i] = a[n-i+piv];
		a[n-i+piv] = tmp;
		i++;
	}
}

O(n) time O(1) space

- fentoyal January 19, 2011 | 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