Amazon Interview Question for Software Engineer / Developers






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

Call Rev for the entire string and then call Rev for each word.

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

I believe this depends on the implementation of the function. If the function is implemented by reversing the entire sentence (taken as word) and each words thereafter, calling "Rev" for the entire string and thereafter for each word will solve the problem.

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

To change the word in place, we can change the space (' ') with line ending character (\0). this way we can change each word.

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

i think sameerud is right

- nunnu December 19, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

@smareeud how do you pass each word into the function without '/0' in the end and if you concatenate it and pass , you wud have to change it back to space character. Instead we can maintain start and end of each word and jus swap the letters between them after first reversing the entire string.

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

void reverseWords(char *str)
{int start=0,end=0,length;
char temp;
length=strlen(str);
str=Rev(str);
while(end<length)
{if(str[end]!=' ')
{start=end;
while(end <length && str[end]!=' ')
end++;

end--;
while(end>start)
{temp=str[start];
str[start]=str[end];
str[end]=temp;
start++;end--;
}
}end++;
}
return;
}

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

okay my bad...i missed the using only Rev() part..
Here goes...

void reverseWords(char *str)
{int start=0,i=0,end=0,length;
char *temp;length=strlen(str);
str=Rev(str);
while(end<length)
{if(str[end]!=' ')
{start=end;
for(i=0;end <length && str[end]!=' ';i++)
{
temp[i++]=str[end++];
}
temp[i]='\0';
temp=Rev(temp);
end--;

for(i=0;start<=end;i++)
{str[start++]=temp[i];
}
}
end++;
}return;
}

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

void rev(char *str)
{
	int len = strlen(str);
	int cur = 0;
	int start = 0;
	itn end = len-1;
	while(start < end)
	{
		char temp = str[start];
		str[start] = str[end];
		str[end] = temp; 
	}

	start = 0;
	end = 0;
	while(cur < len)
	{
		while(str(cur) != ' ' && cur < len)
		{
			cur++;
			end++;
		}
		end--;
		while(start < end)
		{
			char temp = str[start];
			str[start] = str[end];
			str[end] = temp; 
			end--; start++;
		}
		start = end = ++cur;		
	}

}

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

void reverse(char *str)
{
	rev(str);
	int start = 0;
	int end = 0;
	int cur = 0;
	int len = strlen(str);
	while(cur < length)
	{
		if(str[cur] != ' ' && cur < length)
		{
			cur++;
		}
		else
		{
			str[cur] = '\0';
			rev(&str[start]);
			str[cur++] = ' ';
			start = cur;
		}
	}
}

void *rev(char *str)
{
	int len = strlen(str);
	int start = 0;
	itn end = len-1;
	while(start < end)
	{
		char temp = str[start];
		str[start] = str[end];
		str[end] = temp; 
	}

}

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

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

void reverse(char str[])
{
int end=0,start=0,cur=0,len;
char temp;

while(str[end] != NULL) end++;
end--;

len = end;


while(end>start) {

temp = str[start];
str[start] = str[end];
str[end] = temp;

start++;
end--; 
}
puts(str);


start = 0;
end = 0;
	while(cur < len)
	{
		while(str[cur] != ' ' && cur <= len)
		{
			cur++;
			end++;
		}
		end--;
		while(start < end)
		{
			char temp = str[start];
			str[start] = str[end];
			str[end] = temp; 
			end--; start++;
		}
		start = end = ++cur;		
	}
puts(str);


}


int main()
{
char arr[] = "my name is tom";

puts(arr);
reverse(arr);

return 0;
}

- chummi March 19, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

select replace(wm_concat(reverse(substr(' '||reverse('my name is sandeep') ||' ',
level,instr(' '||reverse('my name is sandeep') ||' ',' ',level+1)-
instr(' '||reverse('my name is sandeep') ||' ',' ',level)))),',','')
from dual connect by level<=length(' '||reverse('my name is sandeep') ||' ')

- shaibya sandeep dwivedi August 12, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int j=0;
String reversed = " ";
for(int i=0;i<string.length();i++){
if(string.charAt(i)==' '){
reversed =string.substring(j, i)+" "+reversed;
j=i;

}
}

- RohitDumbre86 March 21, 2012 | 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