Microsoft Interview Question for Software Engineer / Developers






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

Can't we use a hash table?
1) Take array 1 push all the elements into the Table.
2) Take array 2 before we push keep checking if the key already exists if it does discard the element of array 2. Else insert into the table
3) Print out values in the table.

- Anonymous March 16, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

This is the correct approach

- Anonymous March 22, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

How can i create hash table for this.. can you write pseudo code?

- Beowulf September 01, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Use Hashset...
It wont add duplicates...
And print all the elements from the hashset in the end...

- Vinay Hiwarkar December 29, 2012 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

I think if space complexity is allowed, we can go for TRIES
1. assuming that the input arrays themselves wont have duplicates, we will print all the elements of the first array..
2. Also construct a TRIE using all the elements of the first array..
3. While printing the second array check if the element you are printing now is present in the TRIE. This check will be O(l) where l is the length of the particular string for which you are doing the check.
4. Do this for all the elements in the second array. If not found in the trie, print it else skip it..

complexity: O(n1*l) + O(n2*l) where l is the avg length of a string and n1 and n2 are the number of elements in the 2 arrays resp.

- coder June 15, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

There is another way I have solved this issue. Can you please some one suggest me which is betterway and what is the alternative way to solve this problem?

string[] mergeUnsortedArrayusingHashTable(string[] array1, string[] array2)
        {
            int arr1len = array1.Length, arr2len = array2.Length;
            int i = 0;
            string[] outArray = new string[arr1len + arr2len];

            Hashtable ht = new Hashtable();
            //insert all the element from first array
            for (i = 0; i < arr1len; i++)
            {
                if (!ht.Contains(array1[i])) 
                    ht.Add(array1[i], array1[i]);
            }
            //insert all the element from second array
            for (i = 0; i < arr2len; i++)
            {
                if (!ht.Contains(array2[i]))
                    ht.Add(array2[i], array2[i]);
            }
            i = 0;
            foreach (object key in ht.Keys)
            {
                outArray[i++] = key.ToString();
            }
            return outArray;
        }

- N.M. March 16, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

sometimes i feel annoying to visit this site as every body posts only code solutions, no one posts the algo or pseudo code which makes it easy to understand the code,

anyways i think we can join to arrays and use merge sort on this and delete all the repeating values from it, the complexity will be nlogn(n+nlogn)

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

hashtable one is most effective if there is no space complexity involved..

- sriks March 17, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

if extra memory is allowed we can merge all the strings of Arr1 into str1 and Arr2 in str2.
str1 = "are you there"
str2 = "How are you".
now we can easily get
str3 = "How are you there" in one pass.
then split str3 and return.

It will not be as efficient as hash table approach but just another approach.

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

I don't understand how you get str3, can you please explain?

- airfang613 March 17, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Question is not about string concatination. Any of the list or arra need to return non duplicate data

Array1 = {1,2,3,5,6,7,8}
Array2={1,23,45,64,2,7}

Output will be {1,2,23,4,5,45,6,64,7,8}

- N.M March 18, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

If there is no space complexity, just use Hashset, and just output the result of set.

Otherwise, maybe sort two arrays, and use two indices to output the elements from these two arrays.

- Anonymous March 30, 2011 | 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