Microsoft Interview Question for Software Engineer / Developers






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

1.store each remainder in linked list while num>0
num/=10;
2. reverse list

- anon November 27, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

num=12345
while ( num ! = 0)
{
mod = num % 10
num = num / 10
Append the num to linked list
}

- Anonymous November 28, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

I guess you want to insert mod to your linked list

- scarlettmd March 06, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

num=12345
while ( num ! = 0)
{
mod = num % 10
num = num / 10
Append the num to linked list
}

- Anonymous November 28, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

struct node* createLinkList(int x){
	node* first=NULL;	
	int temp;
	while(x>0){
		temp=x%10;		
			node* a=(node*)malloc(sizeof(struct node));
			a->x=temp;
			if(first==NULL)
				a->next=NULL;
			else
				a->next=first;
			first=a;		
		x=x/10;
	}
	return first;
}

- Anonymous December 02, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

typedef struct nodeT
{
int data;
nodeT *next;
}node;

void createLinkedList(int number)
{
int temp;
node *first = NULL;
while(x>0)
{
temp = x%10;
node *newNode = (node *)malloc(sizeof(node));
newNode->data = temp;
if(first == NULL)
{
newNode->next = NULL;
}else{
newNode->next = first;
}
first = newNode;
x = x/10;
}
return first;
}

- Anonymous December 03, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Doesn't the question mention that the function to form a linked list is already given and the requirement is to design test cases?

- KBSorter December 04, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Some test cases i could think of are:
1) when the value is 0
2) reprinting to value to check the answer is the same as the input
3) giving the maximum number that the system is able to handle and then give max value+1

- Rohit December 08, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

1)Input float number.
2)The link list is terminated with NULL.

- Gajanan December 14, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

16 node * getlist(unsigned n)
 17 {
 18     node * head = NULL;
 19     do
 20     {
 21         unsigned digit = n%10;
 22         n = n/10;
 23         node * p = (node *)malloc(sizeof(node));
 24         if(!p)
 25         {
 26             delete_list(head);
 27             return NULL;
 28         }
 29         p->data = digit;
 30         p->next = head;
 31         head = p;
 32     }while(n);
 33     return head;
 34 }
 35 
 36 void delete_list(node * head)
 37 {
 38     node * curr = head;
 39     while(curr)
 40     {
 41         node * next = curr->next;
 42         free(curr);
 43         curr = next;
 44     }
 45 }
 46

- Kyra February 12, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

algo

get the least significant digit by using successive modulo and / operator and keep pushing at the head end of the list.

Test cases
1. what to do when the number is negative...where to store the - sign
2. what if the value is 0. no need to perform the % and / operator. create a single node with data value equal to 0
3.what if the number is out of range
4. what if the number is float (given it is an unsigned int, but does your logic handle for a wrong input??)
5.check for memory allocation of the node, can be a failure sometimes
6.similarly check for a wrong input of characters instead of digits

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

its already mentioned as unsigned int..then why there is a need to store negative sign ?

- Anonymous August 11, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

item *top=NULL,*curr;
while(num%10)
{

printf("%d",num%10);

curr = (item *)malloc(sizeof(item));
curr->val=num%10;
curr->next=top;
top=curr;

num=num/10;
}

printf("\n");

while(curr)
{
printf("-->%d",curr->val);
curr=curr->next;
}

- mitesh April 19, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

class Node
{
public:
int val;
Node* next;
};

void Append(int val,Node** head)
{

if(*head == NULL)
{
Node* newn = new Node();
newn->val = val;
newn->next = NULL;
*head = newn;
}
else
{
Node* temp = *head;
Node* newn = new Node();
newn->val = val;
newn->next = temp;

*head = newn;
}



}
Node* Convertlist(int num)
{

Node* Head = NULL;
if(num<=0)
return NULL;

else

while(num)
{

int x = num%10;
Append(x,&Head);
num = num/10;

}
return Head;
}

- Ashish November 02, 2010 | 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