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.
/*Q1.- Written exam (Amazon, Bangalore)
- neelabhsingh100 May 18, 2012Given a singly link list and a number 'K', swap the Kth node from the start with the Kth node from the last. Check all the edge cases.
Sample Input: 1->2->3->4->5->6->7->8 and K = 3
Sample Output : 1->2->6->4->5->3->7->8
Sample Input: 1->2->3->4->5->6->7->8 and K = 10
Sample Output: print error "LIST IS OF LESSER SIZE"*/
#include<stdio.h>
#include<malloc.h>
struct node *recursion(struct node *,int );
/*
void append(struct node **,int );
void display(struct node *);
here is problem is that void you will get warning
warning: ‘struct node’ declared inside parameter list [enabled by default]
amazon1.c:12:20: warning: its scope is only this definition or declaration, which is probably not what you want [enabled by default]
amazon1.c:13:21: warning: ‘struct node’ declared inside parameter list [enabled by default]
*/
struct node
{
int data;
struct node *link;
};
int main()
{
struct node *start;
start=NULL;
int n,i=0,item,k;
printf("Enter the no of node\n");
scanf("%d",&n);
while(i++<n)
{
printf("Enter node value\n");
scanf("%d",&item);
append(&start,item);
}
display(start);
printf("Enter the number k for swaping kth from the fast and kth from last\n");
scanf("%d",&k);
swap(start,k,n);
printf("\n");
display(start);
}
append(struct node **t,int b)
{
struct node *r,*temp;
r=*t;
if(r==NULL)
{
r=(struct node*)malloc(sizeof(struct node));
*t=r;
}
else
{
while(r!=NULL)
{
temp=r;
r=r->link;
}
temp->link=(struct node *)malloc(sizeof(struct node));
r=temp->link;
/*
If you write like this r=(struct node *)malloc(sizeof(struct node)); then you are creating indepent node which are not connected
to it's previous node.r=NULL then r(struct node *)malloc(sizeof(struct node)); it will not link to the previous node .
*/
}
r->data=b;
r->link=NULL;
}
display(struct node *q)
{
while(q!=NULL)
{
printf("%d-> ",q->data);
q=q->link;
}
}
swap(struct node *fast,int k,int n)
{
struct node *Kth_fast,*Kth_last;
int temp;
if(k>n)
printf("Swaping is not possible you enter the number greater than number of element of linklist\n");
else
{
Kth_fast=recursion(fast,k);
Kth_last=recursion(fast,n-k+1);
}
temp=Kth_last->data;
Kth_last->data=Kth_fast->data;
Kth_fast->data=temp;
}
struct node *recursion(struct node *p,int K)
{
int i=1;
while(i++<K)
{
p=p->link;
}
return p;
}