Microsoft Interview Question for Software Engineer in Tests






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

What position is to be stored for repeated numbers?

- Anonymous December 29, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

In the example 13413124,

the positions of 1: 0, 3, 5
the positions of 3: 1, 4

...etc...

- Anonymous December 31, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

We need to store any repeated number only once? Or do we have to store each occurance separately along with the positions?

- Anonymous December 31, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

we could use array of structure. In this the index of the array will be the number and the structure will contain the list of all the numbers.

struct List
{
int position;
struct List *next;
};

struct List repeatedList[10];

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

Maintain a 2D array of integers: Initialize all elements to 0.The first column contains the element and the subsequent column contains the location. The location field is made up of bits. Thus, if we have a string like 111231..., do
a[0][0] = 1, a[0][1] = 0|position (0 or with position). Thus, a[0][1]=1. i.e. bits --> (0000000....1)

For the next 1 in the string, we do...
a[0][1] = 1 | position
a[0][1]=3 (bits->0000....11)

And so on...

- Swaroop January 03, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Have an array of size 10 of lists

node* digits[10];

each time you find a digit just call

insert(digits[digit], position_of_digit);

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

package com.badal.HashTable;

import java.util.*;

public class HashTable2 {

public static void main(String [] args){
Hashtable<Character,ArrayList<Integer>>hashtable=new Hashtable<Character, ArrayList<Integer>>();

String test="1234512345";

for(int i=0;i<test.length();i++){
Character s=test.charAt(i);

if(hashtable.containsKey(s)){
// update the position
hashtable.get(s).add(i);
}else{
// create the key
ArrayList<Integer> positions=new ArrayList<Integer>();
positions.add(i);
hashtable.put(s, positions);

}

}

// print the hash table
for(Character key:hashtable.keySet()){
System.out.println(key+" = "+hashtable.get(key));

}

}

}

- Java Solution January 06, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Hashtable, using linkedlist to handle conflicts

- Jackie January 07, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

i hope its again a simple thing, if we know before hand what different numbers we have otherwise we just need to take vector or some kindda thing which help us keeping information dynamically.


//for simplicity it is assumed that numbers are from 1 to n and
//and are known which all numbers are there in the given array
Now what we can do

make an 'array' of size n, initialized to '0'
for each 'number'
read the 'number'.
given_array's[current index]<-array[number]
array[number]<-current index
end for

//hey we made a link list of each number with headers in the //array[], is it okay

- kapil January 15, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Question is not clear because it was not mentioned - position counts from the right to left or left to right, and/or like 1st, 10th, 100th? I am not understanding.

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

Jackie's answer is kewl,
Hashtable = Number, linkedlist of position
so if we have 111
answer:
For first 1,
Hashtable.Add(1, 0) where 1 is number, and 0 is position
for second 1
Check 1 in hashtable
if found
Modify position, and add node to that
so it'll be Hashtable 1, 0->1
for third 1
it'll be Hashtable 1, 0->1->2

Instead of linked list, we can simply put string also
for first 1
hashtable 1, "0"
for second
hashtable 1, "0,1"
for third
hashtable 1, "o,1,2"

hope this helps

- cv May 08, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Since we have only 10 keys, we can make use of an array instead of a Hashtable.

- krishna32 February 22, 2015 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Thinking on line of bits... We just need to store the position so take an integer value for each digit and set the bits accordingly...

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

This is the best way with minimal memory except that it fails when the input string has way more numbers than number of bits in an integer

- sunku November 11, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

what to we need to achieve here? access speed or min space?

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

We need to use a linkedlist to store the positions of each number. And since we know that there are only ten numbers (1,2,3,4,5,6,7,8,9,0) we can use an array of size 10 instead of a hashtable. Hashtables are usually preferred when you do not the the number of key value pairs you would be storing. Each element in the array would be a linkedlist holding positions of the array index.

- krishna32 February 22, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Count Sort

- Neelavan April 09, 2017 | 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