Amazon Interview Question for Quality Assurance Engineers


Country: United States
Interview Type: Phone Interview




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

from collections import Counter
def frequency(array):
	print(Counter(array))

- subhasispatra94 September 25, 2020 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

public class Frequency{
public static void main(String[] args){
List<String> list = Arrays.asList("A", "B", "C", "A", "A", "B", "C", "A");

//create a SET to identify unique values
Set<String> unique = new HashSet<String>(list);

Map<String, Integer> result = new HashMap<String, Integer>();

//iterate through your unique values
for(String s : unique){
//result set is optional if you like to find out which is highest or lowest count
result.put(s, Collections.frequency(list, s));
System.out.println(s+" : "+Collections.frequency(list, s));
}

//if need to display for the specific item
System.out.println(result.get("A"));



}

}

- kartik December 06, 2020 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class Frequency {
public static void main(String[] args) {
//Initialize array
int [] arr = new int [] {1, 2, 8, 3, 2, 2, 2, 5, 1};
//Array fr will store frequencies of element
int [] fr = new int [arr.length];
int visited = -1;
for(int i = 0; i < arr.length; i++){
int count = 1;
for(int j = i+1; j < arr.length; j++){
if(arr[i] == arr[j]){
count++;
//To avoid counting same element again
fr[j] = visited;
}
}
if(fr[i] != visited)
fr[i] = count;
}

//Displays the frequency of each element present in array
System.out.println("---------------------------------------");
System.out.println(" Element | Frequency");
System.out.println("---------------------------------------");
for(int i = 0; i < fr.length; i++){
if(fr[i] != visited)
System.out.println(" " + arr[i] + " | " + fr[i]);
}
System.out.println("----------------------------------------");
}}




Output :
----------------------------------------
Element | Frequency
----------------------------------------
1 | 2
2 | 4
8 | 1
3 | 1
5 | 1
----------------------------------------

- anonymous August 25, 2020 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I think there is more optimum approach to this question and in the question your said string but in the solution you used array on numbers .
More optimum approach would be using a hashmap and make the character of string as key and its no of occurance as value.Hence you can find the count of each character.
Time complexity wound be o(n) and space complexity as o(1)

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

It will take o(n) space according to your approach because you are using hashmap.

- A D September 23, 2020 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

# Python 3
from collections import Counter
def solve(arr):
arr1=Counter(arr)
print(arr1)

- mausam15171098 September 18, 2020 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Gave this a try - not sure how many syntax errors could be there. We could get the ASCII values and mark the counts at the index.

Class Findfreq
{
Public static void main(String [] args)
{
String str = “hellohowdoyoudo”;
Int [] arr = scanstring( string str );

For (k=0; k<arr.length ; k++)
{
system.out.println( str.charAt(i) + “ “ + arr(str.charAt(i) - ‘a’) );
}
}
Int[] scanstring (String str)
{
Int countarr [] = new int [26];
Int index = 0;
For (int i = 0; i<str.length(); i++)
{
index = str.charAt(i) - ‘a’ ;
countarr(index) ++;
}
Return countarr;
}
}

- Manoj December 10, 2020 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Thought we could use ASCII values and mark the count at that index location in a separate array

Class Findfreq 
{ 
Public static void main(String [] args)
{
		String str = “hellohowdoyoudo”;
		Int [] arr = scanstring( string str );
	
		For (k=0; k<arr.length ; k++)
		{
system.out.println( str.charAt(i) + “ “ + arr(str.charAt(i) - ‘a’) );
}
}
Int[] scanstring (String str) 
{
		Int countarr [] = new int [26];
	Int index = 0;
For (int i = 0; i<str.length(); i++)
{
		index = str.charAt(i) - ‘a’ ;
	countarr(index) ++;
}
Return countarr;
}
}

- Manoj December 10, 2020 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

this answer is true/false
tell me plzz

- aroojnoor August 05, 2021 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Ruby: Solution 1 using array
Input
a=[11,22,33,22,44]

a.uniq.each do |k,v|
v = a.count(k)
puts "#{k} appears #{v} times"
end

Output:
11 appears 1 times
22 appears 2 times
33 appears 1 times
44 appears 1 times

Solution 2 using Hash
a=[11,22,33,22,44]
# make the hash default to 0 so that += will work correctly
b = Hash.new(0)

# iterate over the array, counting duplicate entries
a.each do |v|
b[v] += 1
end

b.each do |k, v|
puts "#{k} appears #{v} times"
end

- anjalimutha10 February 21, 2021 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I have used a hash map to find the occurrence of each number
Here is my solution:
public static void occurrenceArray(){

int[] aList = new int[]{1, 2, 8, 3, 2, 2, 2, 5, 1};
Arrays.sort(aList);
int count = 1;

HashMap<Integer,Integer> hmap = new HashMap<Integer, Integer>();

for(int i=0;i<aList.length-1;i++){

if(aList[i]==aList[i+1]){
count ++;
hmap.put(aList[i],count);
}
else{
count=1;
hmap.put(aList[i+1],count);
}
}
System.out.println("Hash Map" +hmap);
}

- Aditi June 10, 2021 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Excellent solution!

- Anonymous March 21, 2022 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Javascript

const a = [1, 1, 2, 2, 3, 4];

let m = new Map();

a.forEach(function(b) {
if(m.has(b)) {
m.set(b, m.get(b)+1);
} else {
m.set(b, 1);
}
});

console.log(m);

- Kai January 14, 2022 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Here is my python solution without using any inbuilt functions

def findFrequency(string:str)->dict:
    char_freq = {}
    for char in string:
        if char in char_freq:
            char_freq[char] += 1 
        else:
            char_freq[char] = 1 
    return char_freq

If the given input is an array

def findFrequency2(nums:list)->dict:
    num_freq = {}
    for num in nums:
        if num in num_freq:
            num_freq[num] += 1 
        else:
            num_freq[num] = 1 
    return num_freq

- Shravani91 April 13, 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