Qualcomm Interview Question for Software Engineer / Developers






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

there are many ways to do it
if memory is a don't care
then we can simply use indication array :)

string ans="";
bool used[256]; // for ascii code
memset(used, false, sizeof(used));
for(int i=0; i<str.length(); ++i) 
   if(used[str[i]]) ;
   else {
          used[str[i]]=true;
          ans+=str[i];   
       }

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

Why the used array should have the size 256? I think having the size of 128 is enough as the ascii values are from 0-127.

- RR February 14, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Why the used array should have the size 256? I think having the size of 128 is enough as the ascii values are from 0-127.

- RR February 14, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

hi,

it seems like you are adding a character to the answer string immediately after you find that it hasn't been found before. But what if a character is repeated sometime later and now it has already been added to the answer string. Aren't you supposed to remove it from the answer string. So i think this solution is wrong.

- SD October 30, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

I think it will work fine ! i don't find any bug

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

Please see this,

char str[50]="I am an Indian, which country you belong to?\0";
int i;
for(i=0; '\0' !=str[i]; i++)
{
int j;
for(j=i+1; '\0' !=str[j]; j++)
{
if(str[i] == str[j])
{
int k;
for(k=j;str[k]!='\0';k++)
{
str[k]=str[k+1];
}
}
}
}

The output is "I amndi,whcoutrybelg?", I think it is expected... :)
Please excuse if there is anything wrong in the sentence

- Rajesh Amrutha December 15, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

@Rajesh...go jump...cant u see the better solution above..u algo takes O(n2) + times to remove the duplicates..

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

How about this soln.
Read each character one by one and put it in hashtable.Here key will be alphabet itself and value will be its repetition.whenever you get the count more than 1 in hashtable delete the aplhablet from string.

Reading each character and putting in hashtable.O(n) + const time to put in hashtable.

- sourabh February 14, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Deleting one character and shifting it takes O(n) time. Deleting and shifting n characters would take n^2 time.

- Jigsaw July 04, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

@sourab thts wat the above soln does

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

void RemoveDups(char *str)
{
struct hastable *newhash=createHashtable();
int current=0,new=0;
char *str1=malloc(sizeof(str));
while(str[current]!=NULL)
{
If (!Hashpresent(newhash,str[current]))
{
Hashinsert(newhash,str[current]);
str1[new]=str[current];
new=new+1;
}
current=current+1;
}
str1[current]='\0';
}

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

This will solve purpose in fast and simple code.
It gives result in O(n)

void removeduplicate(char *str)
{
int checker = 0;
int cnt=0;
for(int i=0;i<strlen(str);i++)
{
int val =*(str+i)- (int)'a';
if ((checker & (1 << val)) > 0)
continue;
else{
*(str+cnt)=*(str+i);
cnt++;
}
checker |= (1 << val);
}
*(str+cnt)='\0';
}

- Deven November 22, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

//c# O(n)
        static char[] removeDuplicateChars(char[] _str)
        {
            bool[] charset = new bool[256];
            for (int i = 0; i < _str.Length; i++)
            {
                int val = _str[i];
                if (charset[val]) { _str[i] = ' '; }
                charset[val] = true;
            }
            return _str;
        }

- anup.h.nair December 22, 2012 | 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