## Microsoft Interview Question for Software Engineer in Tests

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

Logic:
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;
}

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

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

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);
}

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

good solution...simple and elegant

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;
}

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;
};

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

this is not right

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;
}

}

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);

}

}

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);
}

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;

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.

### 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.