Qualcomm Interview Question for Software Engineer / Developers






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

#include <stdio.h>
#include <string.h>
void removeSpace(char *str);


void removeSpace(char *str){

	if(!str)
		return;
	int len = strlen(str);
	int src=0;
	int dest=0;
	
	
	while (src<len) {
		if(str[src] != ' '){
			str[dest++] = str[src++];
		}
		else {
			src++;
		}
	}
	str[dest] = '\0';
	printf("%s\n", str);
	
	
}

int main (int argc, const char * argv[]) {
	char str1[100]={0};
	strcpy(str1, " this_ is_  A_ test_ str ing _!!");
	removeSpace(str1);
    return 0;
}

- emge October 26, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

i=j=0;
while(j!=size){
j++;
if(arr[j]!=' '){
arr[i++]=arr[j];
}
}
arr[i]='\0';

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

void fcn(char* arr, int size)
{
int i=0;
int j=0;
while(j!=size)
{
if(arr[j]!=' ')
arr[i++]=arr[j];
j++;
}
arr[i]='\0';
}

- Fixer October 22, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int cnt1 = 0, cnt2 = 0;
for(int cnt1 = 0; str[cnt1]!='\0'; cnt1++)
{
if (str[cnt1] == ' ')
cnt1++;

str[cnt2] = str[cnt1];
}

str[cnt2] = '\0'

- S3 October 23, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int cnt1 = 0, cnt2 = 0;
for(int cnt1 = 0; str[cnt1]!='\0'; cnt1++)
{
if (str[cnt1] == ' ')
cnt1++;

str[cnt2] = str[cnt1];
}

str[cnt2] = '\0'

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

for(int cnt1 = 0; str[cnt1]!='\0'; cnt1++, cnt2++)

- S3 October 23, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

The above implementation fails if there are two spaces together, something like "Hi there wassup" , there are two spaces after "there".

- maverick11235 October 23, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

a modification in S3 implementation to remove multiple spaces:
while (str[cnt1] == ' ')

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

int read_pos, write_pos = 0, len = strlen(str);

for(read_pos = 0; read_pos < len; read_pos++){
if(str[read_pos] != " "){
str[writepos++] = str[read_pos];
}
}

- Trespasser October 24, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<stdio.h>
#include<string.h>
int main()
{
char s[]="hi guys wassup";
int i=0,j=0;
while(a[j]!='\0')
{
if(s[j]!=' ')
s[i++]=s[j];
j++;
}
s[i]='\0';
printf("%s\n",s);
return 0;
}

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

#include <stdio.h>
int main(void)
{
  char str[]="aaaaa          bbbbbbbbbbbb              ccccccccccccc";
  int read, write;

  read = write = 0;

  while(str[read] != '\0')
  {
      while(str[read] != ' ' && str[read] != '\0')
          str[write++] = str[read++];

      if(str[read] == ' ')
           str[write++] = str[read++];

      while(str[read] != '\0' && str[read] == ' ')
         str[read++];
  }
  str[write] = '\0';
  printf("%s",str);
  return 0;
}

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

void remove_space(char *pStr)
{
char *pFast, *pSlow;
pFast = pSlow = pStr;
while(*pFast != '\0')
{
if (*pFast == ' ')
{
pFast++;
continue;
}
*pSlow++ = *pFast++;
}
*pSlow = '\0';
}

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

#include <stdlib.h>
#include <stdio.h>

char* remove_spaces(char *str)
{
        char *ptr2;
        ptr2=str;
        while(*str !='\0')
        {
                if(*str == ' ')
                {
                        *str = ++*str;
                        str++;  
                }
                else
                {
                        str++;
                }
        }
        return ptr2;
}
int main()
{
char s[100];
printf("\n Enter the String:")
gets(s);
char *ans;
ans = remove_spaces(s);
printf("\n The string without spaces is %s",ans);
return 0;
}

- kalyan359 October 04, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
-2
of 2 vote

IMO this is what they are looking for, more often than not QC is more interested in your C skills rather than algorithmic skills.

char a[] = "Hi there wassup Hi there wassup";
int len = 31, i=0;
while( i < len)
{
if(a[i] == ' ')
{
memmove( (void*)&a[i], (void*)&a[i+1], len - i+1);
}
i++;
}

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

is this linear time ?

parsing through characters is fine, what about memmove ?

- peace October 23, 2009 | Flag


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