Amazon Interview Question for Software Engineer in Tests






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

suffix trees and keep count

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

public class NumSubString {

public static int numSubString(String subStr, String inputStr) {

if(subStr.length() == 0) return 0;

String newStr = inputStr.replaceAll(subStr, "");

return (inputStr.length() - newStr.length())/subStr.length();
}


public static void main(String[] args) {
System.out.println(NumSubString.numSubString("bc", "abcabcxbcabc"));
System.out.println(NumSubString.numSubString("abc", "abcabcxbcabcbc"));
}
}

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

Using Java String's replaceAll method to get rid of the subStr. That is replace all occurrences of the given substr with an empty string. Then, simply calculate the difference between the length of the input string and the newly formed string. This difference when divided by the substr's length gives us the number of occurrences of the given substr.

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

string = "abcabcxbcabc"
string1 = "abc"
len1 = len(string1)
count = 0
for i in range(len(string)):
if i > len(string) or string[i:i+len1] == string1:
count += 1


print count

- naini2020 January 05, 2018 | 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