Qualcomm Interview Question for Testing / Quality Assurances


Country: United States




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

private static char[] reverseString_in_Char_Array(String string) {
		char[] str = string.toCharArray();
		boolean isPalindrom = true;
		int j = str.length - 1;
		for (int i = 0; i < (str.length) / 2; i++) {
			if (str[i] == str[j]) {
				j--;
				continue;
			} else {
				isPalindrom = false;
				char temp = str[i];
				str[i] = str[j];
				str[j] = temp;
				j--;
			}
		}
		System.out.println("Palindrom" + isPalindrom);
		return str;
	}

	/**
	 * 1
	 * 
	 * @param str
	 * @return
	 */
	private static StringBuilder reverseString(String str) {
		StringBuilder sb = new StringBuilder();
		for (int i = str.length() - 1; i >= 0; i--) {
			sb = sb.append(str.charAt(i));
		}
		return sb;

}

- sylvia.laurel.oak September 24, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

Code in C#

static void swap(ref char c1,ref char c2)
        {
            char t=' ';
            t = c1;
            c1 = c2;
            c2 = t;
        }
        static void Main(string[] args)
        {
            string _sample = "Suchit";
            char[] ar=_sample.ToCharArray();
            bool ispalin = true;
            for (int i = 0, j = ar.Length - 1; i <= j; i++, j--)
            {
                if (ar[i] != ar[j])
                    ispalin = false;
                swap(ref ar[i], ref ar[j]);
            }
            string s = new string(ar);
            _sample = s;
            Console.WriteLine(ispalin +" "+_sample);
            
        }

- Suchit April 15, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Typo in the for loop, the for loop must be
. . .
for (int i = 0, j = ar.Length - 1; i < j; i++, j--)
{
. . .

- Suchit April 15, 2012 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

private static char[] reverseString_in_Char_Array(String string) {
char[] str = string.toCharArray();
boolean isPalindrom = true;
int j = str.length - 1;
for (int i = 0; i < (str.length) / 2; i++) {
if (str[i] == str[j]) {
j--;
continue;
} else {
isPalindrom = false;
char temp = str[i];
str[i] = str[j];
str[j] = temp;
j--;
}
}
System.out.println("Palindrom" + isPalindrom);
return str;
}

/**
* 1
*
* @param str
* @return
*/
private static StringBuilder reverseString(String str) {
StringBuilder sb = new StringBuilder();
for (int i = str.length() - 1; i >= 0; i--) {
sb = sb.append(str.charAt(i));
}
return sb;
}

- sylvia.laurel.oak September 24, 2012 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

#include<iostream>
#include<string>
#include<algorithm>
using namespace std;

bool check(string str)
{
	int len = str.length();
	int start = 0;
	int end = len-1;
	bool flag = 1;
	while(start < end)
	{
		if(str[start] != str[end])
		{
			flag = 0;
		}
		swap(str[start], str[end]);
		start++;
		end--;
	}
	if(flag != 0)
	{
		flag = 1;
	}
	cout << "Reversed string: " << str << endl;
	return flag;
}
int main()
{
	string str;
	cout << "Enter string:" << endl;
	cin >> str;

	if(!check(str))
	{
		cout << "Not a palindrome" << endl;
	}
	else
	{
		cout << "Palindrome" << endl;
	}
	return 0;
}

- warrior June 20, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Check this blog (nobrainer.co.cc) for the working code and explanation of this algorithm.

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

for(i=0;i<=n-1;i++)
{
a[i]=b[j];
}

for(i=0;i<=n-1;i++)
{for(j=n-1;j>=0;j--)
{a[i]=a[j];}}

for(i=0;i<=n-1;i++)
{

if(a[i]=b[j])
{
print reversed is palindrome
}
else
{
print not a palin
}

}

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

public class palindrome {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		String word = "ABCDEDCBA";
		
		int count =0;
		for(int i =0;i<word.length();i++)
		{
			if(word.charAt(i)==word.charAt(word.length()-1-i))
			{
				count++;
			}
		}
if(word.length()==count)
{
	System.out.println("string is palindrome ");
}
else
{
	System.out.println("string is not palindrome");
}

	}

}

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

public static boolean reverseWord(String foo)
{
    String bar = "";
    for (int i = foo.length(); i > 0; --i)
        bar += foo.substring(i-1, i);
    System.out.println(foo + " reversed is " + bar);
    return foo.equals(bar);    //True if palindrome

}

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

Improving the above code , Here I am just iterating upto middle of the string

public class Palindrome
{
public static void main(String[] args)
{
String str= "asdasdlkalsdkasakdslakldsadsa",revstr = "";
int count=0;

for(int i=1;i<=(str.length()/2)+1;i++)
{
if(str.charAt(i)==str.charAt(str.length()-i-1))
{
count++;
}
}

if(count==(str.length()/2)+1)
{
System.out.println("String is the palindrome!!! No need to reverse the string");
}
else
{
System.out.println("String is not palindrome: Reversing it ");

for(int i=str.length();i>0;i--)
{
revstr+=str.substring(i-1,i);
}
System.out.println(revstr);
}
}


}

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

C++ code to reverse as well as check if string is palindrom

int main()
{
void reverse(char *str, int length);
char arr[] = "mohhom";
reverse(arr, 6);
cout<<arr<<endl;
}
void reverse(char *str, int length)
{
int startIndex = 0;
int endIndex = length -1;
int palindromchecklength = 0;
for(startIndex , endIndex; startIndex<endIndex ; startIndex++, endIndex --)
{
if(str[startIndex] == str[endIndex])
{
palindromchecklength++;
}
else
{
str[startIndex] ^= str[endIndex];
str[endIndex] ^= str[startIndex];
str[startIndex] ^= str[endIndex];
}
}
if(palindromchecklength == length/2)
cout<<"palindrom";
}

- mohitsachan April 09, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

String rev = "";
String oldString = str;
StringBuilder strb= new StringBuilder(str);
rev =strb.reverse().toString();

if(rev.equals(oldString))
{
//System.out.println("Palindrome");
}
else
System.out.println("No Palindrome");
System.out.println("Reverse of "+ str +" is = "+rev);
return rev;

- Deepshikha July 20, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<stdio.h>
#include<string.h>
main()
{ int i,j,k,n,s=0;
char str[20],str1[30],tmp;
printf("Enter the string\n");
gets(str);
int l=strlen(str);
for(i=0;i<l;i++)
{ str1[i]=str[l-i-1];
if(str[i]!=str1[i])
s++;
}
str1[i]='\0';
if(s==0)
printf("The string is pallindrome\n");
else
printf("The string is not pallindrome\n");
printf("The output string is %s\n",str1);
}

- @123 September 22, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

bool PalindromeReverse(char* inputstr)
{
char* start = inputstr;
char* end = inputstr;
char temp;
bool IsPalindrone = true;
while(*end) end++;

end--;

while(start < end) {
if (*start != *end){
temp = *end;
*end = *start;
*start = temp;

IsPalindrone = false;
}
start++;
end--;
}

return IsPalindrone;
}

- Hashy May 01, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

bool PalindromeReverse(char* inputstr)
{
	char* start = inputstr;
	char* end = inputstr;
	char temp;
	bool IsPalindrone = true;
	while(*end) end++;

	end--;

	while(start < end) {
		if (*start != *end){
			temp = *end;
			*end = *start;
			*start = temp;

			IsPalindrone = false;
		}
		start++;
		end--;
	}

	return IsPalindrone;		
}

- Hashy May 01, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

a=String.new
b=String.new
print "Please provide string:"
a=gets.chomp
j=0
l=a.length
i=l-1

while i>=0 
 
 b[j]=a[i]
 j=j+1
 i=i-1
end 

puts "Reverse of string is: #{b}"

if a.eql?(b)
 puts "String is Palindrome"
else
  puts "String is Not Palindrome"
end

- Nitin May 29, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

str=input("enter the string")
str=.casefold()
rev=reversed(str)
if(str==rev):
print("palimdrome")
else:
print(("not palindrome")

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

str=input("enter the string")
str=.casefold()
rev=reversed(str)
if(str==rev):
print("palimdrome")
else:
print(("not palindrome")

- palidrome October 05, 2015 | 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