How to Test a simple Calculator Interview Question

This is a very common interview question and was very much expected when I appeared for my telephonic interview with Microsoft! And as expected I was asked this J “How would you test a calculator that does basic operations like addition, multiplication, division, subtraction and square root.

So here is a reasonable answer to ace this question. Testing formally is divided into two broad categories Functional testing and Non-Functional Testing.  To be very honest interviewer is NOT interested in how much you know about different types of testing rather they want to see how you’re thinking pattern works.

A model answer to this question can be as follows:

“To test a calculator it’s very important that we test both its functional aspects as well as non-functional requirements.  First I would be testing its functional aspects as follows:

a) Perform valid simple arithmetic operations on numbers and compare results with actual results

b) BODMAS: use a long string of different operations on numbers and see if it follows the BODMAS principle and calculates result accurately

c) Try dividing a number by zero and see the output

d) Calculate square root for a negative number and see the result.

e) Perform mathematical operations on very large numbers and see how it handles them.

f) Press and test the back button it should delete the last digit and update screen.

g) Clear button should reset the screen to zero.

h) Use of appropriate error messages.

i) Other aspects such as weight of the calculator should be as such as that it’s easy to carry; display screen should display the numbers big enough for proper visibility and durability of the product.

I hope it helps!

Comments (2)

H1B Visa Interview Experience Islamabad

Having received my I797 Form from Microsoft last month or so I finally scheduled an interview appointment with American Embassy this month. My Interview date for H1b Visa Application was 22nd August 2011 at American Embassy Islamabad.

The interview spanned over 10 minutes at max and the transcript of the interview is as follows:

VO (Visa Officer): Good morning sir, how are you doing today?
Me: Fine, Thank you and how are you doing today?
VO: Not bad either.
VO:  So you are going to Microsoft? I have heard about this company, sorry I forgot what do they do?
Me:  Microsoft is the world’s largest IT Company that develops and licenses a wide range of products and services in computing.  Microsoft windows being there flagship product which you might be using as well in your system right now.
VO: Oh definitely yes I am! So they are based in Redmond, Washington. Are you going there as well?
Me: Yes.
VO: So how did they hire you? Can you explain the whole recruitment cycle? How many interviews? And when did you get the offer?
Me: I answered appropriately explaining how I applied and went for interviews and then finally receiving the offer.
VO: How long is your contract with them?
Me: Stated this from my terms and conditions with Microsoft.
VO: How much would they be paying in you per annum?
Me: Stated appropriately from my offer letter.
VO: Would they renew your contract beyond X years?
Me: Hopefully Yes!
VO: So what exactly you would be doing at Microsoft?
Me:  I stated my Job Responsibilities as mentioned in my Job description.
VO: How many years of professional experience you have now in your field?
Me: Stated Appropriately.
VO: Can I please see your Microsoft Offer letter and original I797?
Me: Yes sure! and I showed him the original documents.
VO: Very Well done sir, I guess you have presented your case very well hopefully you would get your visa and passport within 7-10 days. Allah Hafiz!

Me: Ohh Thank you very much!  Pleasure meeting you. Have a good day! Allah hafiz.

I hope this visa experience helps other people who intend to apply for H1B.

Comments (5)

Ustaad.com.pk: Exclusive New Pakistani Web Portal Allows Students and Teachers to Interact

For Immediate Release

http://www.ustaad.com.pk

 

Ustaad.com.pk: Exclusive New Pakistani Web Portal Allows Students and Teachers to Interact

 

Lahore, Pakistan (8/13/2011) – A groundbreaking new web portal, exclusive to the people of Pakistan, has now been launched, allowing students and teachers to interact in a manner that offers a more meaningful educational experience.

 

USTAAD.com.pk gives both teachers and students the chance to interact in a manner that offers students the abilities to make better informed decisions regarding their education while offering teachers the ability to better manage time and resources. Across Pakistan, students and teachers often find it difficult to locate a teacher. Even more of an issue is the difficulty in locating a teacher that meets the needs of the student in the desired categories. The ability of students and parents to now search for qualified teachers and view their profiles prior to making a selection will greatly enhance the overall educational experience.

 

Upon registration, students receive the ability to review profiles of thousands of teachers available in a wide variety of categories. In addition, this state-of-the-art system also allows students to post a request for a teacher via the teacher request board. Students also have the opportunity to decide whether they wish to obtain services either monthly or on a per-lecture basis. Services may also be requested for online sessions through USTAAD as well. To facilitate the review process for everyone, students are able to rate teachers after they have acquired services or if they have a past experience with a teacher on the site. As a result, every teacher on USTAAD has a viewable rating.

 

As an example of USTAAD’s commitment to providing revolutionary services, teachers are able to respond to requests they receive by messages or even accept a teacher request as it is posted on the board. Consequently, teachers are better able to manage their resources and time. The exclusive teacher dashboard provides teachers with the ability to manage their profiles as well as their inquiries and messages. There is also a special metrics section that gives teachers the opportunity to view the popularity of their profile in regards to the number of views received, providing the chance for teachers to better understand student response to their teaching style and technique.

 

With all of the many benefits offered to both teachers and students, USTAAD is an online community for people who love to learn. All of the tools teachers and students need to better manage their educational and occupational experiences are easily accessible.  Both teachers and students can register through the site to learn more about the various services offered. For more information, visit http://www.ustaad.com.pk

 

##

Leave a Comment

How teachers will benefit from Ustaad.com.pk?

Ustaad.com.pk is an online system that would allow teachers from all disciplines to manage their teaching business more effectively. In the coming months there are a lot of planned developments for Ustaad.com.pk that would totally revolutionize how students/parents search for appropriate teachers and classes all across Pakistan. Some major benefits teacher will get by signing up for Ustaad.com.pk is as follows 1. Profile builder allowUstaad.com.pk is an online system that would allow teachers from all disciplines to manage their teaching business more effectively. In the coming months there are a lot of planned developments for Ustaad.com.pk that would totally revolutionize how students/parents search for appropriate teachers and classes all across Pakistan. Some major benefits teacher will get by signing up for Ustaad.com.pk is as follows

1. Profile builder allows a teacher to build his public profile. This would include their education, certifications, experience, profile picture, service fees and much more.

2. City wise categorization allows students to search for a teacher in a more efficient way, hence increases your chances of getting new students.

3. Full Access to our teacher request board.

4. Your current/old students can leave you reviews. Good reviews on your profile increases your chances of getting new students.

5. Ustaad.com.pk will market your profiles on all social mediums giving you increased exposure. Let us handle all your marketing and you concentrate on what you do best! That is teaching.

Leave a Comment

Microsoft SDET Interview Experience-2

A few days back I wrote down my SDET interview experience with Microsoft. The experience can be read at http://wp.me/p1pzxx-x.

Today a friend of mine who also works in Microsoft currently as SDET shared his interview experience for my blog.  Here are the questions he was asked during his interview with Microsoft.

Okey here are the questions they asked me in a total of 10 interviews :).
1. You have to play a game. You have a 4×4 matrix with random number from 1-15 in it. One box is empty. Only following moves are available you can swap top or bottom or right or left element with the empty box (no diagonal swaps). You have to sort the cube 1 – 15 in the 2D array and the hole should move to the end.
2. you have an array of 100 elements which can have numbers from 1 – 99. The array is filled one number is repeated, what is the number.
3. you have to print the list of all the files in a directory and all its sub directories.
4. you have a number, consider this number on a key pad where it has 3/4 english language alphabets associated with it, like 1 corresponds to abc and so on. Print all the possible alphabet permutations for this number.
5. develop the back functionality for internet explorer’s back button.
6. Write test cases for you FYP, for your best project and for the projet you are working on currently.
7. what is good code. test a pen. You have to make a presentation and you dont have the book what will you do.
8. There is a function which draws a line on the screen. Test the function.
9. You have a circular singly link list. Add an element at the end of the list but you cannot traverse the list.
10. Find duplicates in a string.
11. Give a lecture on memory.
12. what is process, thread.
13. Propose an algo/data struct for memory manager.
14. Propose and algo/data struct for timer manager.

I hope his interview proves beneficial for everyone who is going to appear for an interview. Good luck ! and see you soon @ Microsoft.

 

Leave a Comment

Print a tree level by level (Level Order Traversal)

Printing a tree level by level

A common interview question in which you would be asked to write a code that would print a binary tree by level. For example the below binary tree when passed to your code should print 7,6,11,3,5,13,12



 

 

 

 

 

This is also known as level order traversal. The level order traversal of a tree is also breadth first traversal of the tree. The concept of level order traversal is to visit the root and then visit all nodes 1 level away, then all nodes 2 levels away and so on. We would need a queue to perform this kind of traversal.

The psuedocode for the program would be as follows:

Create an empty queue “Q”
enqueue the root element of the tree
while queue is NOT empty
dequeue an element from the queue
print element
Get children of the dequeued element
enqueue children

Having written the psuedocode its now very straight forward to convert this into a working C++ code.

 

 

Leave a Comment

Microsoft Technical Interview tips !

Over the past weeks or so I have been asked this question a lot of times “How to approach a Microsoft Interview?”   Based on my experience I would suggest the following to anybody who is going to appear for an interview for a technical position with Microsoft in coming future.

  • Know your Data Structures & Algorithms! If you read my interview experience you would see almost every question revolved around some data structure or the other. I suggest you review all popular data structures and algorithms and see how you can solve different problems using these data structures. On top of that it goes without saying that algorithms such as post order, pre order and in order traversal of a tree, traversing a linked list, reversing a linked list, reversing a string , hash tables, binary search trees, sorting algorithms, recursion vs. iterative should be on your finger tips! You should also be able to derive the space and time complexities of your code and how could you further optimize it.
  • Practice coding on a white board: Most of us have a mindset that we can only code using our editor and compiler to be sure that we have done it correctly. However life is not that straight forward! During your interviews you would have to write a piece of code on the white board where you won’t be having the services of our old friend “compiler”. I realized it during my interview that writing code on a white board is something that needs practice. So I suggest while you prepare for your interview get a white board and practice all your codes on it. Have a friend go through them with you once you have written them down.
  • Ask questions (logical): Most of the questions that are presented in the interview are very vague and it has a purpose. The interviewer is looking at how you dissect the problem before coming up with the solution; do you have that thinking ability to properly understand the problem before coming up with a solution for example “Delete a specific node from a linked list” if you jump straight down on writing a code for deleting a node without even being sure what kind of a linked list we have you are getting yourself in trouble! You can ask your interviewer questions like “is it a singly linked list? Doubly or circular linked list?” “What kind of data does It store” etc. This gives the interviewer an impression that you have the thinking skills to properly nail down a problem so that you are sure that you understood it fully. Probe for more details !
  • Don’t panic: Even though you might have practiced a lot of common interview questions but the actual interview questions might still be different. Just ensure that you have covered all the bases by revising all core concepts and make use of them to come up with a solution. The interviewers are not looking at exact answers to a problem rather how you approach a problem when pushed in a difficult situation. There is no harm in asking the interviewer to elaborate on the question if you couldn’t understand it the first time. Be confident!

  • Think aloud: As I just mentioned above that Interviewers are not looking for an exact solution to a problem and most of the times are looking how you approach a problem. The major thing here is that even if you are bogged down by the problem on hand; talk out aloud your thought process so the interviewer knows exactly on what lines your mind is thinking. I have seen many real examples of people who failed to solve a problem yet got offers because they were clear in communication with the interviewer.  I was confident enough in all the programming questions that were thrown at me so most of the time I dived straight into coding them on the white board which lead to an interviewer giving me feedback that “most of the interviewers don’t want you to jump straight into the code rather than thinking and doing some homework on the problem talking aloud”. So in a nut shell don’t dive straight into code and talk through your algorithm with your interviewer before writing the code.

I guess that’s very much about everything that you might need when you interview with Microsoft but if you if feel I left out something please leave a comment and I will be more than glad to answer or help. Hoping to see you soon at Microsoft Campus! Best of luck!

Leave a Comment

Deleting the entire linked list

This is another common interview question. The interviewer wants to see how you tackle the problem and maintain pointers to correctly de allocate all the memory reserved by the linked list.

Suppose you start with the head element and traverse the list and delete elements as you move along…but wait a minute! Do you advance the pointer first or delete the pointer first? Suppose you advance the pointer than how would you delete the previous node? And if you delete the node than you can’t advance as your node contains the address of the next element.  So to perform this function we would need to maintain two pointers one which would hold the current node and one which would hold the next node in the linked list. Here is a sample code in C++

Void Delete (Node ** head)
{

Node* temp = *head;
while (temp) {

Node * temp1 = temp->next;
delete temp;
temp = temp1;
}

*head = NULL;

}

Updated courtesy supergokhan

 

Comments (2)

Detecting a cycle in a linked List (Floyd’s Cycle Detection)

OK here is another very interesting interview problem which I wanted to discuss today. The problem at hand is that you are given a singly linked list and (unfortunately) it contains a cycle i.e. some node points back to an earlier node in the linked list. Your task being a software engineer is to detect if  the linked list contains a cycle.

My initial brainstorming gave me an idea that I should traverse the list and mark nodes on my way so if I reach a node that has already been marked Hurrah !! Got ya !

Lets see how this approach works. So now I need to maintain a status for every node so I updated my Node Structure as follows

Struct Node {
int data;
Node * link;
bool status;
}

Firstly I would have to initialize all nodes with status value equal to “false”

Node * temp = head;
while (temp) {
temp->status = false;
temp = temp->link;

}

Having done that now my job is very simple. I can detect the cycle as follows:

Node * current = head;
bool isCycle = false;

while (current){

if(current->status ==true){
isCycle = true;

}

current->status = true;
current=current->next;

}

The approach seems to be fine but it required us to change our original Node data structure. Supposing the interviewer wants you to come up with a solution that doesn’t change the underlying data structure than you need to figure out some other way. Let’s look at a different algorithm that achieves this.

Most of us would remember the rabbit and turtle story from our childhood where the rabbit was very quick and turtle was very slow during the race. Consider they were racing on a straight track and for sometime assume the rabbit didn’t become complacent and instead kept on running he would have reached the finish line much quicker than the turtle, however consider they were racing in a circular field and there was no finish line the rabbit would have moved ahead quickly and eventually would have crossed the turtle again after some time. Can we use this story for our help? Yes we surely can ! this algorithm is a classical example of Floyd’s Cycle Detection Algorithm or also known as Tortoise and Hare Algorithm. So if we have a cycle in our linked list than some where along the traversal the faster pointer (Hare) would meet the slower pointer (turtle) indicating we have a cycle , else the hare would reach the end of the linked list if there is no cycle. Let’s see how we can code this.

//Hare moves twice the speed of the Turtle so if we have a cycle eventually Hare would meet the turtle again.

bool isCycle(Node *head) {

Node * turtle, * Hare;

turtle=Hare=head;

while (Hare){

if(Hare>link ==turtle->link){

return true;

}

turtle = turtle->link;
Hare= Hare->link->link;

}

return false;

}

Comments (1)

mth from the last element of a singly linked list

Write a program to find the mth from the last element of a singly linked list

Singly Linked List

So for the linked list shown m= 0 would return the node with information field 1203 (tail element) and m = 1 would return node with information field 1202.

Solution:

This is a very common interview question. Let’s look at a very simple solution.

  1. Traverse the list and count the number of nodes.
  2. Calculate the offset of the mth from last element from the start using  offset = (length – m)
  3. Traverse the linked list again (for int i=1 ; i <=offset; i++) and return the current node.

However there must be a better way of approaching this instead of using loops to traverse the list twice.

Another solution can be as follows:

  1. Initialize two pointers p and q both pointing to the head of the linked list.
  2. Now let’s make the distance between p and q equals to m by incrementing the q pointed m times.
  3. Now check if q-> next == NULL (means we have reached the end of the linked list and p is at m positions from the last element so we return node pointed by p) else increment both points p = p-> next and q = q-> next and repeat step 3 again.

Rough implementation in C++ would be as follows:

Node * mthfromLast(Node * head, int m){

if(head==NULL|| m < 0)
{   return NULL;
}

Node * p, *q = head;

for (int i = 0 ; i < m; i++){
if(q->next == NULL)

{ return NULL;
}

q = q-> next;
}
while(q->next!= NULL) {

p = p-> next;

q = q-> next;

}
return p;
}

Singly Linked List Image was taken from : http://www.tech-faq.com/images/singly-linked-list_clip_image002.jpg

Leave a Comment

Older Posts »