Qualcomm Interview Question for Software Engineer / Developers






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

One of many possible implementations.

template<class T>
void swap(T& a, T& b)
{
    a^=b;
    b^=a;
    a^=b;
}

char* reverseString(char* pStr, int size)
{
    if( !pStr ) return 0;
    char* pBeg=pStr;
    char* pEnd=pStr+size-1;
    while( pBeg < pEnd )
    {
        swap(*pBeg++,*pEnd--);
    }
    return pStr;
}

- Michael September 20, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

No temporary memory needed,

char* reverse(char* str)
{
int i=0,len=strlen(str);
while(i<len/2)
{
str[i]=str[i]+str[len-i-1];
str[len-i-1]=str[i]-str[len-i-1];
str[i]=str[i]-str[len-i-1];
i++;
}
std::cout<<str;
return str;
}

void main()
{
char s[12]= "hello world";
reverse(s);
}

- T September 21, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Generic method to swap 2 vars w/o using a temp var.

a = a + b
b = a - b
a = a - b

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

Your method has a potential issue. a=a+b can overflow a. Using ^ is the best option.

- kar November 29, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

we're not asked to use C/Java etc so this is my take in python in a single line,

reversedString = givenString[::-1]

and you are done!

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

#include<stdio.h>
#include<string.h>
main()
{
char a[10],temp;
scanf("%s",a);
int l=strlen(a),i;
int k=l-1;
for(i=0;i<l/2;i++)
{
temp=a[i];
a[i]=a[k];
a[k]=temp;
k--;
}
printf("%s\n",a);
}

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

#include <stdio.h>
#include <string.h>


void reverseString(char *str);


void reverseString(char *str){
int len=0;
if (!str || (len=strlen(str))<2)
return;
int i;
for(i=0; i<len>>1; i++)
{
str[i]=str[i]+str[len-1-i];
str[len-1-i]=str[i]-str[len-1-i];
str[i]=str[i]-str[len-1-i];
}

}

int main (int argc, const char * argv[]) {

char str1[100]={0};
char str2[100]={0};

strcpy(str1, "Hello World");
strcpy(str2, str1);
reverseString(str1);
printf("in:%s\t\t out:%s\n", str2, str1);

strcpy(str1, "abc");
strcpy(str2, str1);
reverseString(str1);
printf("in:%s\t\t out:%s\n", str2, str1);

strcpy(str1, "ab");
strcpy(str2, str1);
reverseString(str1);
printf("in:%s\t\t out:%s\n", str2, str1);

//strcpy(str1, NULL);
//strcpy(str2, str1);
reverseString(NULL);
printf("in:%s\t\t out:%s\n", NULL, NULL);

strcpy(str1, "a");
strcpy(str2, str1);
reverseString(str1);
printf("in:%s\t\t out:%s\n", str2, str1);

return 0;
}

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

#include <stdio.h>
#include <string.h>


void reverseString(char *str);


void reverseString(char *str){
int len=0;
if (!str || (len=strlen(str))<2)
return;
int i;
for(i=0; i<len>>1; i++)
{
str[i]=str[i]+str[len-1-i];
str[len-1-i]=str[i]-str[len-1-i];
str[i]=str[i]-str[len-1-i];
}

}

int main (int argc, const char * argv[]) {

char str1[100]={0};
char str2[100]={0};

strcpy(str1, "Hello World");
strcpy(str2, str1);
reverseString(str1);
printf("in:%s\t\t out:%s\n", str2, str1);

strcpy(str1, "abc");
strcpy(str2, str1);
reverseString(str1);
printf("in:%s\t\t out:%s\n", str2, str1);

strcpy(str1, "ab");
strcpy(str2, str1);
reverseString(str1);
printf("in:%s\t\t out:%s\n", str2, str1);

//strcpy(str1, NULL);
//strcpy(str2, str1);
reverseString(NULL);
printf("in:%s\t\t out:%s\n", NULL, NULL);

strcpy(str1, "a");
strcpy(str2, str1);
reverseString(str1);
printf("in:%s\t\t out:%s\n", str2, str1);

return 0;
}

- emge October 26, 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[30]="utam",t;
int i,j;
i=0;j=strlen(s)-1;
while(!((i==j)||(i>j)))
{
//printf("hi\n");
t=s[i];
s[i]=s[j];
s[j]=t;
i++;j--;
}
printf("%s\n",s);
}

- uttam.tiwary December 25, 2009 | 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