Saurabh
BAN USER 0of 0 votes
AnswersInput : 4 jars and 50 balls of different colors (Red, Green, Yellow, Blue) where each jar can contain a maximum of 100 balls.
 Saurabh in India
Problem : When a user draws a red ball he looses his money while if he draws a ball of some other color his money is doubled. Arrange the balls in such a way that the user has highest probability to loose. Report Duplicate  Flag  PURGE
Flipkart Software Engineer / Developer Probability  0of 0 votes
AnswersGiven a Binary tree and a pointer to some node in the tree, find the left and right neighbors of the input node. The neighbor nodes are on the same level/depth as of input node.
 Saurabh in India
Don't use BFS/level order traversal.
There is no parent pointer. Report Duplicate  Flag  PURGE
Flipkart Software Engineer / Developer Trees and Graphs
Time Complexity : O(n)
Space Complexity : O(n)
public void transformArray(int in[]) {
Stack<Integer> stack = new Stack<Integer>();
int out[] = new int[in.length];
stack.push(0);
for (int i = 1; i < in.length; i++) {
if (in[stack.peek()] <= in[i])
stack.push(i);
else {
while (in[stack.peek()] > in[i]) {
out[stack.pop()] = in[i];
}
stack.push(i);
}
}
for (int i = 0; i < out.length; i++) {
System.out.print(out[i] + " ");
}
}
mynode *temp= NULL; // declare a temporary variable named count.
The function mynode *reverse_recurse_n(mynode *start, int n, int count) takes the pointer of the start node of a linked list and a number n as the block size.
count is used to keep the count of node for internal logic while reversing the linked list.
# include <stdio.h>
# include <stdlib.h>
typedef struct node
{
int data;
struct node *next;
}mynode;
void printlist ( struct node *p )
{
printf("\nThe data values in the list are\n");
while (p!= NULL)
{
printf("%d\t",p> data);
p = p> next;
}
}
mynode *reverse_recurse_n(mynode *start, int n, int count)
{
if(start>next != NULL)
{
mynode *head=reverse_recurse_n(start>next, n, count+1);
if(count % n !=0)
{
start>next>next=start;
start>next = NULL;
}else{
temp = head;
head = start ;
}
if(count % n == 1)
{
start>next = temp;
}
return(head);
}else{
return start;
}
}
int main()
{
struct node *start = NULL ;
start = insert ( start, 1 ); start = insert ( start, 2 );
start = insert ( start, 3 ); start = insert ( start, 4 );
start = insert ( start, 5 ); start = insert ( start, 6 );
start = insert ( start, 7 ); start = insert ( start, 8 );
start = insert ( start, 9 ); start = insert ( start, 10 );
start = insert ( start, 11 );
printf("The created list is\n");
printlist (start);
start = reverse_recurse_n(start,5,1);
printlist (start);
getch();
return 0;
}

Saurabh
March 27, 2010
Yes. 200 in total.
 Saurabh October 15, 2011