## Arang

BAN USER- 1of 1 vote

AnswersRound-3-Qn-2)

- Arang

- You are given two 4 digits prime numbers N1 and N2,

- You can change only one digit of N1 at a time.

- Resultant of changing a digit of N1 should also be a prime number.

How many number of digit changes (minimum) are required to convert N1 to N2?

Example:

Assume (8785, 8787, 8887, 9887, 9897) are prime numbers.

Lets say N1=8785 and N2 = 9897 then

change-1: 8785 => 8787

change-2: 8787 => 8887

change-3: 8887 => 9887

change-4: 9887 => 9897

So 4 digit changes are require to convert N1 to N2.| Report Duplicate | Flag | PURGE

Amazon Software Engineer / Developer Algorithm Coding Data Structures - 0of 0 votes

AnswersRound-3-Qn-1) It was repeated one. they asked the same round-1-Qn-1 question.

- Arang

At starting of round-3, I noticed that interviewer has answer sheet of all my previous rounds and so i thought she is looking for some other alternatives than what i gave in round-1.

So i took 5 minutes to think of better solution but gave the same solution as i could not find any other better solution.

I made a big mistake by answering this question without saying "it was already asked in round-1". Because she assumed "i am cheating them.."... like that.

Thoguh i answered all the questions and performed well in previous rounds, it was the major reason for my elimination :(| Report Duplicate | Flag | PURGE

Amazon Software Engineer / Developer Algorithm - 0of 0 votes

AnswersRound-2-Qn-2) Implement a data structure such that it provides push(), pop() and GetMax() operations and running time of all operations should be constant O(1).

- Arang

Note: GetMax need not remove the max from the data structure.| Report Duplicate | Flag | PURGE

Amazon Software Engineer / Developer Algorithm Coding Data Structures - 0of 0 votes

AnswersRound-2-Qn-1) Given a linked list L, we need to make a clone L'.

Note: a) Each node in the given list has an additional link called random that can point to any node (can also be null)

b) we need to make a clone of the list without using any additional space (need to allocate memory only for new nodes 1', 2', 3',...)

c) complexity should be O(n)

- Arang`-->------ | | L = 1-->2-->3-->4-->NULL | | ^ | |___|___| | | |___| | |<----------- 1->next = 2 1->random = 3 2->next = 3 2->random = 3 3->next = 4 3->random = NULL 4->next = NULL 4->random = 1 In L', the nodes should be 1'->next = 2' 1'->random = 3' 2'->next = 3' 2'->random = 3' 3'->next = 4' 3'->random = NULL 4'->next = NULL 4'->random = 1'`

| Report Duplicate | Flag | PURGE

Amazon Software Engineer / Developer Algorithm - 0of 0 votes

AnswersRound-1-Qn-2) Given a binary tree, we need to create a matrix.

Example:

- Arang`A / \ B C / \ / \ D E F G |A|B|C|D|E|F|G| ------------------ A| B|1 (B is child of A) C|1 (C is child of A) D|1 1 (D is child of A & B) E|1 1 (E is child of A & B) F|1 1 (F is child of A & C) G|1 1 (G is child of A & C)`

| Report Duplicate | Flag | PURGE

Amazon Software Engineer / Developer Algorithm Coding Data Structures - 0of 0 votes

AnswersRound-1-Qn-1) Find vertical sum of given binary tree.

Example:`1 / \ 2 3 / \ / \ 4 5 6 7`

The tree has 5 vertical lines

`Vertical-1: nodes-4 => vertical sum is 4 Vertical-2: nodes-2 => vertical sum is 2 Vertical-3: nodes-1,5,6 => vertical sum is 1+5+6 = 12 Vertical-4: nodes-3 => vertical sum is 3 Vertical-5: nodes-7 => vertical sum is 7`

We need to output: 4 2 12 3 7

- Arang| Report Duplicate | Flag | PURGE

Amazon Software Engineer / Developer Algorithm Coding Data Structures - 0of 0 votes

AnswersWritten-Qn-3) Given a binary tree and a number N, check is there any path exists in the tree such sum of the nodes in the path equals to N.

bool isPathExists(Node *root, int N)

Note: We can assume that node contains only positive integers

Example:`1 / \ 2 3 / \ / \ 4 5 6 7`

if N = 8, return TRUE

- Arang

if N = 9, return FALSE| Report Duplicate | Flag | PURGE

Amazon Software Engineer / Developer Algorithm Coding Data Structures - 0of 0 votes

AnswersWritten-Qn-2) Write complete working code (only the function) to traverse a binary tree in ZigZag order

void printTree(Node *root)

Example:`1 / \ 2 3 / \ / \ 4 5 6 7`

O/P: 1 3 2 4 5 6 7

- Arang| Report Duplicate | Flag | PURGE

Amazon Software Engineer / Developer Algorithm Coding Data Structures - 0of 0 votes

AnswersWritten-Qn-1) Write complete working code (only the function) to check whether the given char sequence is valid.

- Arang

bool isValid(char *str)

Example:

I/P: ()()().... O/P: Valid.

I/P: ())()(.... O/P: Invalid.

* We can assume that the input will have only squence of '(' and ')' chars.| Report Duplicate | Flag | PURGE

Amazon Software Engineer / Developer Algorithm Coding Data Structures

LinkedList * createList(Tree *p)

{

if (p == NULL) then return NULL:

push p and NULL in Q;

sum = 0;

while (Q != Empty)

{

Tree *t = pop element from Q;

if(t == NULL)

{

create a node for LinkedList.. Sum as data...

add the node in the list;

sum = 0

if (Q != empty) then push NULL in the Q;

}

else

{

sum = sum + t->data;

if(t->left != NULL) then push t->left in Q

if(t->right != NULL) then push t->right in Q

}

}

return the List;

}

RepHey, I am Ruth and I am working as an interviewer.I take too many Interviews For my Company and ...

Rep**lusinisa67**, Secretary at MelbourneSkilled and experienced secretary in Teiscom company. Highly organized with a strong attention to detail and the ability to monitor ...

Rep**pihupiter**, university professor at Precious MomentsExpert English literature and language university professor with more than 5 years of experience teaching at the college level. Outside ...

Rep**paytonmorrison48**, Data Scientist at ADPI am working as a date entry keyar . I have many years of experience . The data entry manager is primarily ...

**CareerCup**is the world's biggest and best source for software engineering interview preparation. See all our resources.

Open Chat in New Window

char * ftoa(float n)

- Arang February 22, 2010{

char a[256] = {0};

long int i=0,j=0,k=0;

long int x,y,z,t;

if(n<0) {

a[j++] = '-';

n = -n;

}

y = x = floor(n);

if(x == 0) a[j++] = 48;

k = j;

while(x>0) {

t = x%10;

x/=10;

a[k++]=t+48;

}

i = k--;

while(k>j) {

swap(a[j],a[k]);

j++; k--;

}

j = i;

n = n-y;

a[j++] = '.';

for(k=0;k<8;k++) {

n = n*10;

t = (long int)floor(n)%10;

a[j++] = t+48;

}

return a;

}