Amazon Interview Question for Software Engineer / Developers






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

swap vowels by comparing leftmost and right most vowel in the string, then compare next leftmost and right most vowel and swap, continue until reach the middle of the string.

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

I read out and send him in memory. First I thought it's simple and I made a mistake for the for-loops and then I send another version with a for and while loop. I don't what 's gonna happend, but I have no regret if they don't want bring me on site. I feel it's too much algorthms thing that I am not good at it anymore. and I don't want spend a lot time to review something you seldom get the chance to use it in future.

- bl December 21, 2006 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Hmmm, The point is not to give an extremely difficult question that requires cleverness and a flash of insight, but rather to give a moderately difficult question that requires being organized and thorough in your approach. It is easy enough for a good candidate to write up a correct solution in 15 minutes or so, but hard enough to trip up someone who is not familiar enough with the language they are writing in or someone who codes first and thinks second.

Another thing that might help is to practice communicating clearly.

- Jack November 07, 2007 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Jack, very helpful

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

package reverseVowels;

public class ReverseVowels {
static String sentence = "united states";

public static void main(String[] args) {
System.out.println(sentence);
char[] letters = sentence.toCharArray();
int left = 0;
int right = letters.length - 1;
char temp;
boolean left_visit = false;
boolean right_visit = false;
for(int i=0; i<letters.length; i++) {
if(letters[left] == 'a' ||
letters[left] == 'e' ||
letters[left] == 'i' ||
letters[left] == 'o' ||
letters[left] == 'u') {
left_visit = true;
} else {
if(left_visit == false) {
left++;
}
}

if(letters[right] == 'a' ||
letters[right] == 'e' ||
letters[right] == 'i' ||
letters[right] == 'o' ||
letters[right] == 'u') {
right_visit = true;
} else {
if(right_visit == false) {
right--;
}
}

if(left_visit == true && right_visit == true && left <= right) {
temp = letters[right];
letters[right] = letters[left];
letters[left] = temp;
left++;
right--;
left_visit = false;
right_visit = false;
}
}

System.out.print(new String(letters));

}

}

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

//Store index of each vowel in List
// Traverse through the set using two pointers - one at the beginning (incIndex)and second at the last(decIndex)

// Sway values in the input array arr[incIndex] <=> arr[decIndex]
// Increase 'incIndex' by 1 and decrease the 'decIndex' by 1

//Comment on:
//Time complexity
// Space Complexity

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;


public class ReverseVowels {

		
	public static void main(String args[]){
				
		Scanner in = new Scanner(System.in);
		ReverseVowels rv = new ReverseVowels();
		String input = in.next();
		String result = rv.reverseVowels(input);
		System.out.println(result);		
	}
	
	public String reverseVowels(String input){

		@SuppressWarnings("rawtypes")
		ArrayList vowels = new ArrayList();
		char[] arr = input.toCharArray();

		int sizeOfarr = input.length();

		for(int i=0 ; i< sizeOfarr; i++){
			if(arr[i] == 'a'|| arr[i] == 'e' || arr[i] == 'i'||arr[i] == 'o'||arr[i] == 'u'){
				vowels.add(i);				
			}	
		}

		int sizeOfVowels = vowels.size();
		for(int j=0 ; j< sizeOfVowels/2; j++){
			
			//index for (last - curr) value  in the set 'vowels'
			int k = sizeOfVowels - 1 - j;
			
			int incIndex = (int)vowels.get(j);
			int decIndex = (int)vowels.get(k);
			
			char temp = arr[incIndex];
			arr[incIndex] = arr[decIndex];
			
			arr[decIndex] = temp;
			//System.out.println(Arrays.toString(arr));

		}	
		
		return Arrays.toString(arr);	
	}
}

- krunalpuri March 26, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;


public class ReverseVowels {
	
	public static void main(String args[]){
				
		Scanner in = new Scanner(System.in);
		ReverseVowels rv = new ReverseVowels();
		String input = in.nextLine();
		String result = rv.reverseVowels(input);
		System.out.println(result);	
		in.close();
	}
	
	public String reverseVowels(String input){

		List<Integer> vowels = new ArrayList<>();
		char[] arr = input.toCharArray();
		int sizeOfarr = input.length();
		for(int i=0 ; i< sizeOfarr; i++){
			if(arr[i] == 'a'|| arr[i] == 'e' || arr[i] == 'i'|| arr[i] == 'o'|| arr[i] == 'u'){
				vowels.add(i);				
			}	
		}

		int sizeOfVowels = vowels.size();
		for(int j=0 ; j< sizeOfVowels/2; j++){
			int k = sizeOfVowels - 1 - j;
			int incIndex = (int)vowels.get(j);
			int decIndex = (int)vowels.get(k);
			
			char temp = arr[incIndex];
			arr[incIndex] = arr[decIndex];
			arr[decIndex] = temp;
		}	
		
		return String.valueOf(arr);	
	}

}

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

import java.util.ArrayList;

import java.util.List;

import java.util.Scanner;

public class ReverseVowels {

public static void main(String args[]){

Scanner in = new Scanner(System.in);

ReverseVowels rv = new ReverseVowels();

String input = in.nextLine();

String result = rv.reverseVowels(input);

System.out.println(result);

in.close();

}

public String reverseVowels(String input){

List<Integer> vowels = new ArrayList<>();

char[] arr = input.toCharArray();

int sizeOfarr = input.length();

for(int i=0 ; i< sizeOfarr; i++){

if(arr[i] == 'a'|| arr[i] == 'e' || arr[i] == 'i'|| arr[i] == 'o'|| arr[i] == 'u'){

vowels.add(i);

}

}

int sizeOfVowels = vowels.size();

for(int j=0 ; j< sizeOfVowels/2; j++){

int k = sizeOfVowels - 1 - j;

int incIndex = (int)vowels.get(j);

int decIndex = (int)vowels.get(k);

char temp = arr[incIndex];

arr[incIndex] = arr[decIndex];

arr[decIndex] = temp;

}

return String.valueOf(arr);

}

}

- Krishna Chaitanya Sripada April 15, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

String vowels = "aeiou";


Stack<String> stack = new Stack<String>();


char[] array = s.toCharArray();



for(char ch : array){


if(vowels.contains(String.valueOf(ch))){

stack.add(String.valueOf(ch));
}
}


StringBuilder builder = new StringBuilder();


for(char ch : array){

if(vowels.contains(String.valueOf(ch))){

String pop = stack.pop();
builder.append(pop);

}
else{
builder.append(ch);
}
}

return builder.toString();

- Sayooj April 27, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static String reverseString(String s){

String vowels = "aeiouAEIOU";


Stack<String> stack = new Stack<String>();


char[] array = s.toCharArray();



for(char ch : array){


if(vowels.contains(String.valueOf(ch))){

stack.add(String.valueOf(ch));
}
}


StringBuilder builder = new StringBuilder();


for(char ch : array){

if(vowels.contains(String.valueOf(ch))){

String pop = stack.pop();
builder.append(pop);

}
else{
builder.append(ch);
}
}

return builder.toString();
}

- Sayooj April 27, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static String reverseString(String s){

String vowels = "aeiouAEIOU";


Stack<String> stack = new Stack<String>();


char[] array = s.toCharArray();



for(char ch : array){


if(vowels.contains(String.valueOf(ch))){

stack.add(String.valueOf(ch));
}
}


StringBuilder builder = new StringBuilder();


for(char ch : array){

if(vowels.contains(String.valueOf(ch))){

String pop = stack.pop();
builder.append(pop);

}
else{
builder.append(ch);
}
}

return builder.toString();
}

- Sayooj April 27, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

//Copied from my Solution on LeetCode.com
class Solution {
public:
//Scans string for next Vowel starting from the front. Returns index of vowel. Returns -1 for failure
	int findNextVowel(string s)
	{
		static int current = -1;
		for (int i = current + 1; i < s.length(); ++i)
		{
			if (s[i] == 'a' || s[i] == 'e' || s[i] == 'i' || s[i] == 'o' || s[i] == 'u' 
			 || s[i] == 'A' || s[i] == 'E' || s[i] == 'I' || s[i] == 'O' || s[i] == 'U')
			{
				current = i;
				return current;
			}

		}
		return (current = -1);
	}
//Scans string for next Vowel starting from the last element.Returns index of vowel. Returns -1 for failure.
	int findVowelback(string s)
	{
		static int current = s.length();
		for (int i = current - 1; i > 0 ; --i)
		{
			if (s[i] == 'a' || s[i] == 'e' || s[i] == 'i' || s[i] == 'o' || s[i] == 'u'
			|| s[i] == 'A' || s[i] == 'E' || s[i] == 'I' || s[i] == 'O' || s[i] == 'U')
			{
			    current = i;
				return current;
				
			}

		}
		return (current = -1);
	}
	void swap(char& c, char&d)
	{
		char temp = c;
		c = d;
		d = temp;
	}
//Given a string, it reverses all the vowels
	string reverseVowels(string s) {
		for (int i = findNextVowel(s), j = findVowelback(s); i < j; i = findNextVowel(s), j = findVowelback(s))
		{
			swap(s[i], s[j]);

		}
		return s;
	}
	
};

- XnakelX June 02, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

def reverse_vowels(str_):
    """
    Given a string, returns a string with the order of the vowels reversed but all other chars 
    unchanged
    """
    tmp = list(str_)
    positions_and_vowels = [(index, char) for index, char in enumerate(tmp) if char in 'aeiou']
    positions, vowels = [x[0] for x in positions_and_vowels], [x[1] for x in positions_and_vowels]
    vowels.reverse()
    for index, char in zip(positions, vowels):
        tmp[index] = char
    print tmp

- mkdivis07 September 03, 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