Amazon Interview Question for Software Engineer in Tests






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

is this problem solved?

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

That solution won't actually work. You can't compare Strings with ==, you must use a .equals() comparison. Also, what happens if the String isn't in the array? You need a default return value.

This is one solution, although there are many others:

public static boolean containsValue(String[] arr, String value) {
for(int i = 0; i < arr.length; i++) {
if(arr[i].equals(value)) {
return true;
}
}
return false;
}

Returning the index is a good notion, just depends on what the code is for.

- Anonymous May 25, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

the program also needs to check sub-strings within a string.
for instance
containsValue("Good morning Universe","verse")
should return true
Here is the algorithm
// store the elements of the first array into a hash table
// for every element in the second array, check in the hash table and retrieve the index.
// if the index, forms a sequence, return true.
// else return false.

Time complexity is O(n+m)
To do in O(n)

Step 1: find the occurence of the first character of second array in first array
Step 2: starting from that index, check for each subsequent characters whether they match.
Step 3: if they do not match, go to step 1
Step 4: else, return true

- kavin February 01, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

i didnt understand the questn...can you please give me an example...

- any August 03, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.util.Scanner;

public class StringComparisionArray
{
public static void main(String[] a)
{
String[] strings = {"one", "two", "three", "four"};
String str;
Scanner scanner = new Scanner(System.in);
System.out.print("Enter the search keyword:");
str = scanner.nextLine();

for (int i = 0; i < strings.length; i++)
{
if (strings[i].equals(str))
{
System.out.println("String is present");
break;
}else
{
System.out.println("String is not present");
}
}
}
}

- sunisunil007 February 06, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

the easy way is
public static void _check(String[] array, String comparison)
{
for(int i=0;i<array.length;i++)
{

}
}

- Anonymous May 02, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

the easy way is
public static void _check(String[] array, String comparison)
{
for(int i=0;i<array.length;i++)
{

}
}

- Anonymous May 02, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

the easy way is
public static int _check(String[] array, String comparison)
{
for(int i=0;i<array.length;i++)
{
if(array[i]==comparison)
{
return i;
}
}
}

- Anonymous May 02, 2011 | 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