Amazon Interview Question for Testing / Quality Assurances


Country: United States




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

String [] strArray = new String [] {"Om", "Om","Shankar","Tripathi", "Tom", "Jerry", "Jerry"};

HashMap<String, Integer> map = new HashMap<String, Integer>();

for(String arrVal: strArray)
{
map.put(arrVal, map.containsKey(arrVal) ? map.get(arrVal)+1 : 1);
}

for (Map.Entry<String, Integer> entry : map.entrySet()) {
if(entry.getValue()>1){
String key = entry.getKey();
Object value = entry.getValue();

System.out.println(key + ":"+value);
}
}

- Anonymous September 29, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

String [] strArray = new String [] {"Om", "Om","Shankar","Tripathi", "Tom", "Jerry", "Jerry"};

HashMap<String, Integer> map = new HashMap<String, Integer>();

for(String arrVal: strArray)
{
map.put(arrVal, map.containsKey(arrVal) ? map.get(arrVal)+1 : 1);
}

for (Map.Entry<String, Integer> entry : map.entrySet()) {
if(entry.getValue()>1){
String key = entry.getKey();
Object value = entry.getValue();

System.out.println(key + ":"+value);
}
}

- Om Shankar Tripathi September 29, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

// ZoomBA
mset ( array_of_strings )

- NoOne October 06, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

import java.util.HashSet;

public class NumberOfDuplicateChars {

	public static void main(String[] args) {
		String [] strArray = new String [] {"Om", "Om","Shankar","Tripathi", "Tom", "Jerry", "Jerry"};
		
		int count = 0;
		
		HashSet<String> hs = new HashSet<String>();
		
		for(String s : strArray)
		{
			if(!hs.add(s))
				count++;
		}
		
		System.out.println(strArray.length - hs.size());
		//OR
		System.out.println(count);

	}

}

- ank.bst March 17, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Stunning logic

- Sukumar November 03, 2018 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

So this depends on whether or not you're finding the duplicates of one substring in a longer string sentence, or finding any substring in the sentence that has duplicates and how many. This is the latter way in Python from my experience.

def dupeStrings(arr):
	counts = {}
	for each in arr:
		if arr.count(each) > 1:
			counts[each] = arr.count(each)
	return counts

Passing any array of strings will return a dictionary with the word name and the number of duplicates found.

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

String [] strArray = new String [] {"Om", "Om","Shankar","Tripathi", "Tom", "Jerry", "Jerry"};

HashMap<String, Integer> map = new HashMap<String, Integer>();

for(String arrVal: strArray)
{
map.put(arrVal, map.containsKey(arrVal) ? map.get(arrVal)+1 : 1);
}

for (Map.Entry<String, Integer> entry : map.entrySet()) {
if(entry.getValue()>1){
String key = entry.getKey();
Object value = entry.getValue();

System.out.println(key + ":"+value);
}
}

- Om Shankar Tripathi September 29, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

void CountString(vector<string> strings) {
std::map<string, int> data;
for(auto& v : strings)
{
	if(data.find(v) != data.end())
	{
		data[v] += 1;
	}
	else
	{
		data[v] = 1;
	}
 }
}

Complex: O(n)

- fangmingrrn September 29, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public int getDuplicateCount(T[] arr){
		if(arr == null) return 0;
		boolean[] grid= new  boolean[arr.length] ;
		int count=0; int nullcount=0;
		for (T t : arr) {
			if(null == t){
				nullcount++; 
				continue;
			}
			int idx = t.hashCode()%arr.length;
			if(grid[idx]){
				count++;
			}else{
				grid[idx]= true;
			}
		}		
		return count;		
	}

- Sourav Mohanty October 06, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public int getDuplicateCount(T[] arr){
		if(arr == null) return 0;
		boolean[] grid= new  boolean[arr.length] ;
		int count=0; int nullcount=0;
		for (T t : arr) {
			if(null == t){
				nullcount++; 
				continue;
			}
			int idx = t.hashCode()%arr.length;
			if(grid[idx]){
				count++;
			}else{
				grid[idx]= true;
			}
		}		
		return count;

}

- Ashis Kumar October 06, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

package com.test;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

public class Count_CharMap {
public static void main(String[] args) {
try
{
FileInputStream file = new FileInputStream("D:\\trial.txt");
DataInputStream dis = new DataInputStream(file);
BufferedReader br = new BufferedReader(new InputStreamReader(dis));
// System.out.println(br.readLine());
String Contents="";
String str="";

while ((Contents = br.readLine()) != null) {
str+=Contents;
}

char[]char_array =str.toCharArray();
System.out.println(char_array);
// int count = 0;


Map<Character,Integer> charCounter=new HashMap<Character,Integer>();
for(int i=0;i<str.length();i++)
{
System.out.print(char_array[i]);
char ch = char_array[i];
if(charCounter.containsKey(char_array[i]))
{
charCounter.put(ch, charCounter.get(ch)+1);
// count++;
}
else
{
charCounter.put(ch, 1);
// count++;
}
}

System.out.println(charCounter);
for(Character key:charCounter.keySet())
{
System.out.println(key+""+charCounter.get(key));
}
System.out.print("\n");
new File("D:/Java").mkdir();
File statText = new File("D:/Java/statsTest.txt");
FileOutputStream is = new FileOutputStream(statText);
OutputStreamWriter osw = new OutputStreamWriter(is);
Writer w = new BufferedWriter(osw);
for(Character key:charCounter.keySet())
{
w.write(key+"="+charCounter.get(key)+"\n");
w.append(System.lineSeparator());

// w.write("\n");
}
// w.write("POTATO!!!"+ new Date());
// w.write(h);
w.close();
}
catch(IOException e1){
System.out.println(e1);
}

}
}

- himanshutime@gmail.com October 11, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

// Written in javascript

var arr = ['ab', 'cd', 'ab', 'drj', 'jr', 'jr'];

Array.prototype.contains = function(obj){
   for(let i=0; i<this.length; i++){
      if(this[i]===obj)
         return true;
   }
   return false;
}

var dupStr = function(arr){
   let temp = [];
   for(let i=0; i<arr.length; i++){
      if(!temp.contains(arr[i]))
         temp.push(arr[i]);
   }
   console.log(arr.length - temp.length);
}

dupStr(arr);

- Rocky October 14, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Set<String> uniquUsers = new HashSet<String>();
        int count = 0;
        for (int i = 0; i < users.length; i++) {
            if (!uniquUsers.add(users[i]))
                count++;                         
        }

- bhag November 16, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

String [] strArray = new String [] {"Om", "Om","Shankar","Tripathi", "Tom", "Jerry", "Jerry"};
int counter=0;
for (int i = 0; i < strArray.length; i++) {
for (int j = i+1; j < strArray.length; j++) {
if(strArray[i].equals(strArray[j])){
counter++;
break;
}
}

}

System.out.println(counter);

- Elshan March 05, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

String [] strArray = new String [] {"Om", "Om","Shankar","Tripathi", "Tom", "Jerry", "Jerry"};
		int counter=0;
		for (int i = 0; i < strArray.length; i++) {
			for (int j = i+1; j < strArray.length; j++) {
				if(strArray[i].equals(strArray[j])){
					counter++;
					break;
				}
			}
			
		}
		
		System.out.println(counter);

- Elshan March 05, 2017 | 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