Amazon Interview Question for Software Engineer / Developers






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

2 ptrs. 1 read - another write.
Read is faster than write. read reaches EOString - write a \0 in the write ptrs location.

- lord Darth Plagueis June 29, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

char * findstr(const char * str)
         {   char *p;
             while(*str)
                  {
                    if(*str=='0')str++;
                    elseif
                       (*ptr)++=(*str)++;
                }
          return p;
         }

- mastee July 01, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

OOOOps...........sorry ptr and p is same char pointer........its a just a spelling mistake...

- mastee July 01, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

'/0'  should be added to ptr after while loop

- mastee July 01, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

'\0' instead of '/0'

- Anonymous July 19, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

The question asks to retain single space, not completely rip them off

void Squeeze(char *str){
if(str==NULL)
return;
int i=0,index=0;
while(str[i]!='\0'){
while(str[i]!=' ' && str[i]!='\0'){
str[index]=str[i];
index++;i++;
}
str[index++]=str[i++];
while(str[i]==' ' && str[i]!= '\0')
i++;

}
str[index]='\0';
}

- hopebasedcoder July 25, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

i am new to programming...i've a question for hopebasedcoder..can you please check again ur solution where
index++;i++;
}
str[index++]=str[i++];

check against "abc " if u can produce "abc"..m i missing something?

- annon August 06, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

1.i am new to programming
2.correct me if i am wrong
bla bla bla ....

are these stupid formalities really necessary ehh???
just share your idea ....

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

oh sorry got it...

- annon August 06, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class DeleteSpacesFromAString {

public static void main(String args[]) {

String s = "fffg f f f f f f ffff ff";
boolean flag = true;
StringBuilder sb = new StringBuilder();
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i) == ' ' && flag) {
flag = false;
sb = sb.append(s.charAt(i));
} else if(s.charAt(i) != ' ')
{
flag = true;
sb = sb.append(s.charAt(i));
}
}

System.out.println(sb.toString());

}
}

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

Can't we remove all spaces, and put one space at the end of the string, just before the end of string character.

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

removeWhiteSpace(char a[])
{
    int tail=0; 
    while(a[tail]!=' ')
         tail++;
       
    for(int i =tail;i<a.length;i++)
    {
         if(a[i]!= ' ')
         {
           a[tail]=a[i];
            tail++;
         }
    }
}

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

What if the given string contains tabs in it ?

- Balu June 28, 2010 | 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