Amazon Interview Question for Quality Assurance Engineers


Team: Ring
Country: United States




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

Both chars present in the string and both unique
Both absent
Unique, one present and one absent
Same chars
Unique and first occurs after second -> Test for absolute distance

- anaghgg September 24, 2020 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Can you write their implementation, preferably in Python3?

- Shivam Thaman February 25, 2021 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Can you write their implementation, preferably in python3?

- Shivam Thaman February 25, 2021 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

str='Ajay is here'
res =str.index('A')
res2=str.index('h')
print(res)
print(res2)
if( res2>res):
resf=res2-res
print(resf)

- Athmika July 22, 2021 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

str='Ajay is here'
res =str.index('A')
res2=str.index('h')
print(res)
print(res2)
if( res2>res):
resf=res2-res
print(resf)

- Athmika July 22, 2021 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Here is my python solution

def findDistance(sentence:str,start:str,end:str)->int:
    if len(sentence) == 0:
        return 0 
    elif start not in sentence or end not in sentence:
        return -1
    elif start == end and start in sentence and sentence.count(start) > 1:
        s_index = sentence.find(start)
        e_index = sentence.find(end,s_index+1,len(sentence))
        return abs(e_index - s_index)
    elif start != end:
        return abs(sentence.index(start)-sentence.index(end))
    else:
        return -1

s = "Ajay is here"
st,en = 'A','h'
print(findDistance(s,st,en))

st,en = 'e','k'
print(findDistance(s,st,en))

st,en = 'g','z'
print(findDistance(s,st,en))

- Shravani91 April 13, 2022 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Another Python solution

def findDistance(sentence:str, s:str,e:str)->int:
    if s in sentence and e in sentence:
        return abs(sentence.index(s)-sentence.index(e))
    return -1

- Shravani91 April 13, 2022 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void findCharDistance(String str, char a, char b) {


if(str == null ||
!str.contains(Character.toString(a)) ||
!str.contains(Character.toString(b)) ||
str.isBlank()) {
System.out.println("-1");
}else if(a != b){
System.out.println(Math.abs(str.indexOf(a) - str.indexOf(b)));
}else {
System.out.println(Math.abs(str.indexOf(a) - str.lastIndexOf(b)));
}

}

test data:
FindDistance.findCharDistance(null, 'a', 'b');
FindDistance.findCharDistance(" ", 'a', 'b');
FindDistance.findCharDistance("Ajay is here", 'A', 'z');
FindDistance.findCharDistance("Ajay is here", 'z', 'h');
FindDistance.findCharDistance("Ajay is here", 'A', 'h');
FindDistance.findCharDistance("Ajay is here", 'z', 'y');
FindDistance.findCharDistance("Ajay is here", 'A', 'a');
FindDistance.findCharDistance("Ajay is here", 'A', 'A');
FindDistance.findCharDistance("Ajay is here", 'e', 'e');

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

public class FindDistance {
	public static void findCharDistance(String str, char a, char b) {
		if(str == null || 
				!str.contains(Character.toString(a)) || 
				!str.contains(Character.toString(b)) ||
				str.isBlank()) {
			System.out.println("-1");
		}else if(a != b){
			System.out.println(Math.abs(str.indexOf(a) - str.indexOf(b)));
		}else {
			System.out.println(Math.abs(str.indexOf(a) - str.lastIndexOf(b)));
		}
	}
}

test data :
FindDistance.findCharDistance(null, 'a', 'b');
FindDistance.findCharDistance(" ", 'a', 'b');
FindDistance.findCharDistance("Ajay is here", 'A', 'z');
FindDistance.findCharDistance("Ajay is here", 'z', 'h');
FindDistance.findCharDistance("Ajay is here", 'A', 'h');
FindDistance.findCharDistance("Ajay is here", 'z', 'y');
FindDistance.findCharDistance("Ajay is here", 'A', 'a');
FindDistance.findCharDistance("Ajay is here", 'A', 'A');
FindDistance.findCharDistance("Ajay is here", 'e', 'e');

- debghosal92 August 06, 2022 | 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