Amazon Interview Question for Software Engineer / Developers






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

create a new array and insert the one in the middle if no space left in the original array

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

It does not look like we need to move pointers its an array random access is possible. It seems all one has to do is either sift elements by one position either towards left or right depending upon the vacant space (i.e. upon encountering the occupied middle one needs to look for the first empty slot in both directions and sift the elements accordingly). Correct me if i am wrong.

- hary March 11, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Programming languages assigns 0 as default value for integers. In this case there is no vacant element, unless you want to treat 0 as vacant.

- prasad.adss June 28, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<stdio.h>

void insert_at(int* arr, int size, int inx, int* obj)
{
    if ( size <= inx )
        return;
    int i = 0;
    for ( i = size - 1; i > inx; i--)
    {
        arr[i] = arr[i-1];
    }
    arr[i] = *obj;
}
int main()
{
    int arr[10] = {0,1,2,3,4,5};
    int obj = 55;
    insert_at(arr, 10, 8, &obj);
    int i = 0;
    for ( i = 0 ; i < 10; i++ )
    {
        printf("%3d ",arr[i]);
    }
    printf("\n");
}

- becga March 11, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

what if you declared array size 6 . you need to reallocate the memory right..?

- sathiyanannauniversity April 14, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

Problem:
================
How would you add an element in the middle of the array...

Example:
================
A[123567]

N= 4

ALGO:
================
1. Run two pointers when Increment second pointer twice and when second reaches the end then 1st reached middle
Insert the element and rearrange the rest of array
2. Get size of array
take size/2
check if odd or even
insert an element and rearragen the array

CODE:
================

public InsertMiddle(Array A[], int N)

{

For (i=0,J=0 ; A[i]<0 ; i++) \\USED A[I]<0 FOR OUT OF ARRAY ADDRESS
{
IF(A[J]<0)
{
iNSERT(I,N)
}
J += 2
}

INSERT(INT I,INT N)
{
FOR(;A[I]<0;I++)
{
TEMP=A[I+1]
A[I+1]=N
A[I+2]=TEMP
}

}


}



ORDER:
================
O(N^2)

- Tarun Phaugat March 08, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

I think after finding the middle of array we can simply shift middle value at last and add new value at middle.

- Anonymous March 21, 2010 | Flag


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