Microsoft Interview Question for Software Engineer in Tests






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

Logic:
Read each charecter,
Hash it to a bitmap with each character being hashed to its corresponding bit position.

assumption:
all values in lower case

char * remDuplicate(char * str){

   int d;
   char *c = (char *)malloc(strlen(str) + 1);
   
   int d = 0;
   int i = 0, j = 0;
   while ( *(str+i) != '\0'){
      if (isSet(*(str+i) , &d)) {
         i++;
      } else {
         *(c+j) = *(str+i);
         i++; j++;
         setBit(*(str+i), &d);
     }
   } 
  *(c+j) = '\0';
  return c;

}

void setBit(char c, int *d){
    int bitpos = c - 97;
    int n = 1; 
    while (bitpos > 0) {
       n = n << 1; bitpos--;
     }    
     *d = (*(d))|n;
}

int isPresent(char c, int *d) {
     int bitpos = c - 97;
     int n = 1; 
     while (bitpos > 0){
        bitpos--; 
        n = n<<1;
     }
    if ( (*d)&n)
       return 1;
    else 
       return 0;
}

Please point out if i have made any pointer mistakes

- saurabh.comps November 08, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

get each character, add it to Set & display results from Set

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

#include <string.h>


typedef char bool;
#define true 1
#define false 0

void removeDup(char * str) {
int tgt = 0, i = 0;
bool charTable[256] = {false};
if(!str) return;
for(i = 0; str[i]; i++) {
if(!charTable[str[i]]) {
charTable[str[i]] = true;
str[tgt++] = str[i];
}
}
str[tgt] = 0;
return;
}

int main() {
char * str = (char *);
strcpy(str,"hello world!");
removeDup(str);
}

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

good solution...simple and elegant

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

void removeduplicates(char *str)
{
char *str1;
int hash[256];
int j=0,index=0;
for(i=0;i<255;i++)
hash[i]=0;
for(i=0;i<strlen(str);i++)
hash[str[i]]++;
while(str[j])
{
if(hash[str[j]]>1)
continue;
else
str1[index++]=str[j];
}
str1[index]='\0';
cout<<"the unduplicated string is "<<str1;
}

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

char* RemoveDuplicates(char* inputString)
{
if(!inputString)
return NULL;
int len = strlen(inputString);
int src=0;
int dest=0;

while (src<len) {
if(inputString[src] != inputString[src+1]){
inputString[dest++] = inputString[src++];
}
else {
src++;
}
}
inputString[dest] = '\0';
return inputString;
};

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

this is not right

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

Here is simple solution for this..
public static void removeDup(char[] str)
{
if (str==null) return;
int len=str.lenght()l
if(len<2) return;
int tail=1;
for(int i=1;i<len;i++)
{
for(int j=0;j<tail;j++)
{
if (str[i]==str[j]) break;
}
if (j==tail)
{
str[tail]=str[i];
++tail;
}
}
str[tail]=0;
}

}

- Sanju February 26, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class RemoveDup {

    public static void main(String[] args) {

        String str=new String();

        System.out.println("Enter the String");

        Scanner s=new Scanner(System.in);

        str=s.nextLine();

        int[] ch=new int[256];

        String str1 = new String();

        for(int i=0;i<str.length();i++){

            if(ch[str.charAt(i)]==0)
            {
                ch[str.charAt(i)]=1;
                str1=str1 + str.charAt(i);
            }

            else{

                ch[str.charAt(i)]++;
            }

        }

         System.out.print(str1);

    }

}

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

Brute Force

public static void maintainOrder(String str) {

		String finalStr=new String();
		for(int i=0;i<str.length();i++){
			if(!finalStr.contains(""+str.charAt(i))){
				finalStr=finalStr+str.charAt(i);
			}
		}
		System.out.println(finalStr);
	}

- Sachdefine January 23, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

$input = $_POST['name'];		
		$output = explode( " " , $input );
		$output = array_unique( $output );
		$input = implode(" " , $output);
		
		print $input;

- Anonymous March 14, 2014 | 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