Ebay Interview Question for Software Engineer Interns


Country: United States
Interview Type: Phone Interview




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

examples?

which company interviewed you?

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

Here we take comma, number and space as separators between words? If so, the thought would be: find out each word' front and back, then reverse it. Code in C:

int isSeparator(char c)
{
	return c == ',' || isdigit(c) || isspace(c);
}
void reverse(char* s, char* e)
{
	char c;
	for(; s < e; ++s, --e){
		c = *s;
		*s = *e;
		*e = c;
	}
}
char* reverseWord(char* s)
{
	if(s == NULL || *s == '\0') return s;

	char *head = s, *tail = s;
	while(1){
		//skip continuous separators till next word's front
		for(head = tail; *head != '\0' && isSeparator(*head); ++head) ;
		if(*head == '\0') break;
		//now head points to a word's front, we go on to find out the word's back
		for(tail = head + 1; *tail != '\0' && !isSeparator(*tail); ++tail) ;
		//now *tail == '\0' or *tail is a separator, so we reverse s[head,tail)
		reverse(head, tail - 1);
	}
	return s;
}

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

Please give one example?

- Ankit Garg April 21, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

String SentenceReversal(String sentence)
{
String newString = new String(null);
String tempString = new String(null);
for(int i = 0; i<sentence.length; i++){

if((sentence.charAt(i) == ' ')||sentence.charAt(i) >= '0' && <=9) )
{
if (tempString!=null){
newString.append(WordReversal(tempString));
tempString=null;}
newString.append(sentence.charAt(i))
}
else
{
tempString.append(sentence.charAt(i));
}
return newString;
}


String WordReversal(String word){
String reverseWord = new String(null);
for (int i = word.length-1 i>=0;i--){
reverseWord.append(word.charAt(i))
}
return word;
}

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

String SentenceReversal(String sentence)
{
String newString = new String(null);
String tempString = new String(null);
for(int i = 0; i<sentence.length; i++){

if((sentence.charAt(i) == ' ')||sentence.charAt(i) >= '0' && <=9) )
{
if (tempString!=null){
newString.append(WordReversal(tempString));
tempString=null;}
newString.append(sentence.charAt(i))
}
else
{
tempString.append(sentence.charAt(i));
}
return newString;
}


String WordReversal(String word){
String reverseWord = new String(null);
for (int i = word.length-1 i>=0;i--){
reverseWord.append(word.charAt(i))
}
return word;
}

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

public class ReverseSentence {
    public static void main(String argv[]) {
        String sentence = "1 My name is rachana, but I like name rajashree, 234 I like 123456cooking";
        System.out.println(reverseSentence(sentence));
    }

    private static String reverseSentence(String sentence) {
        StringBuffer reversed = new StringBuffer();
        char[] chars = sentence.toCharArray();
        for(int i =0; i<chars.length-1;i++) {
            if(!isChar(chars[i])) {
                reversed.append(chars[i]);
            } else {
                int j = i;
                StringBuffer word = new StringBuffer();
                while(isChar(chars[j]) && j < chars.length-1) {
                    word.append(chars[j]);
                    j++;
                }
                String wordR = reverse(word.toString());
                reversed.append(wordR);
                i=j-1;
            }
        }
        return reversed.toString();
    }

    private static boolean isChar(char c) {
        if((c > 64 && c<90) || (c>96 && c<122)) {
            return true;
        }
        return false;
    }
    private static String reverse(String word) {
        char[] A = word.toCharArray();
        int max = word.length() - 1;
        int min = 0;

        while (min < max) {
            char temp = A[max];
            A[max] = A[min];
            A[min] = temp;
            max--;
            min++;
        }
        return new String(A);
    }
}

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

It could ez solve by using the functions of StringBuilder:

insert(offset,char)
        append(char)

static String reverseWords(String s) {
		if (s==null||s.length()==0)
			return "";
		StringBuilder result = new StringBuilder();
		int j=0;	// position of last [comma,space,numbers]
		for (int i=0;i<s.length();i++) {
			char c = s.charAt(i);
			if (c==' '||Character.isDigit(c)||c==','){
				result.append(c);
				j=i+1;
			} else result.insert(j, c);
		}
		return result.toString();
	}

}

- wyu277 August 05, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class StringReverse
{
public static void main(String args[])
{
String s = "1 My name is rachana, but I like name rajashree, 234 I like 123456cooking";

reverse(s);

}

public static void reverse(String s)
{
int m=0;
char b[]= new char[s.length()];

for(int i=0; i<s.length(); i++)
{
char c = s.charAt(i);
if(Character.isDigit(c) || c == ',' || c == ' ')
{
b[i] = c;
}
}

for(int i=s.length()-1; i>=0; i--)
{
char c = s.charAt(i);
if(Character.isDigit(c) || c == ',' || c == ' ')
{
continue;
}
else
{
while(b[m] !='\u0000')
{
m++;
}
b[m] = c;
m++;
}
}

System.out.println(new String(b));
}
}

- Moksha April 18, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

The output for the string "I love, driving 5 cars" is "I evol, gnivird 5 racs"

public class reverseWord {
	public void revWord(String str){		
		int flag=0;
		String word="";
		String finalString="";
		char[] charArray = str.toCharArray();
		for(int i=0;i<charArray.length;i++){
			if(charArray[i]!=' '&&charArray[i]!=','&&!Character.isDigit(charArray[i])){				
				flag=1;
			}
			else if(flag==1&&(charArray[i]==' '||charArray[i]==','||Character.isDigit(charArray[i])))
				flag=2;
			if(flag==1&&i==str.length()-1){
				flag=2;
			}
			if(flag==1){
				word=word+charArray[i];
			}
			else if(flag==2){
				word= new StringBuffer(word).reverse().toString();
				finalString=finalString+word;
				flag=0;
				word="";
			}
			if(flag==0){System.out.println("final else");
				finalString=finalString+charArray[i];
			}
		}
		System.out.println(finalString);
	}
	public static void main(String args[]){
		reverseWord list1=new reverseWord();
		list1.revWord("I love, driving 5 cars");
	}
}

- Saikrishnan January 07, 2016 | 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