Google Interview Question for Software Engineers


Country: United States




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

is it [a,b] common in first three set ?

- Anonymous January 03, 2020 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

is it a,b common in first three set?

- no January 03, 2020 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

var y = [["a","b","c","d"], ["a", "b", "f", "g"], ["a", "b", "h", "i"], ["j", "k", "l", "m"]];
var x = new Map(y);
var foundOutlier;
forLoop: for(var key of x.keys()) {
var index = 0;
for(var index = 0, j = y.length; index < j; index++) {
if(y[index].indexOf(key) < 0) {
foundOutlier = y[index];
break forLoop;
}
}
}

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

var y = [["a","b","c","d"], ["a", "b", "f", "g"], ["a", "b", "h", "i"], ["j", "k", "l", "m"]];
var x = new Map(y);
var foundOutlier;
forLoop: for(var key of x.keys()) {
    var index = 0;
    for(var index = 0, j = y.length; index < j; index++) {
        if(y[index].indexOf(key) < 0) {
            foundOutlier = y[index];
            break forLoop;
        }
    }
}

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

var y = [["a","b","c","d"], ["a", "b", "f", "g"], ["a", "b", "h", "i"], ["j", "k", "l", "m"]];
var x = new Map(y);
var foundOutlier;
forLoop: for(var key of x.keys()) {
    var index = 0;
    for(var index = 0, j = y.length; index < j; index++) {
        if(y[index].indexOf(key) < 0) {
            foundOutlier = y[index];
            break forLoop;
        }
    }

}

- novoice January 06, 2020 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 2 vote

public String[] predictItemBasedSimilarity(List<String[]> list){

        if(list == null) throw new IllegalArgumentException("List Null");

        Map<String, Integer>  ItemBasedSimilarityMap = new LinkedHashMap<>();

        for(int i =0; i < list.size(); i++){ // evaluate score
            String[] words = list.get(i);
            if(words!= null)
                for(int j =0; j < words.length; j++){
                    Integer count =
                            ItemBasedSimilarityMap.getOrDefault(words[j], new Integer(0));
                    count = count+1;
                    ItemBasedSimilarityMap.put(words[j],count );
                }
        }

        String[] leastAppeared = null;
        int min = Integer.MAX_VALUE;

        for(int i =0; i < list.size(); i++) { //rank by score
            String[] words = list.get(i);
            int sum =0;
            if(words!= null){
                for (int j = 0; j < words.length; j++) {
                    Integer count = ItemBasedSimilarityMap.get(words[j]);
                    sum += count;
                }
            }
            if(min > sum) {
                min = sum;
                leastAppeared = words;
            }

            System.out.println(" sum "+ sum + " min "+ min +" i "+  i);
        }
        return leastAppeared;
    }

- Ashis Kumar Chanda January 08, 2020 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

public static String[] detectOutlier(String [][] list)
{
Map<Integer, String[]> scores = new LinkedHashMap<Integer, String[]>();
for(String [] s : list)
{
int score = 0;
for (String element: s)
{
char c = element.toCharArray()[0];
score+=Character.getNumericValue(c);
}
scores.put(score, s);
}

int max = Collections.max(scores.keySet());
return scores.get(max);
}

- Anonymous January 17, 2020 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;

public class LeastCommonList {
	public static void main(String[] args) {
		int n = 3;

		// Here aList is an ArrayList of ArrayLists
		List<ArrayList<Integer>> aList = new ArrayList<ArrayList<Integer>>(n);

		// Create n lists one by one and append to the
		// master list (ArrayList of ArrayList)
		ArrayList<Integer> a1 = new ArrayList<Integer>();
		a1.add(1);
		a1.add(2);
		aList.add(a1);

		ArrayList<Integer> a2 = new ArrayList<Integer>();
		a2.add(5);
		aList.add(a2);

		ArrayList<Integer> a3 = new ArrayList<Integer>();
		a3.add(1);
		a3.add(2);
		a3.add(2);
		aList.add(a3);

		System.out.println(getUncommon(aList));


	}

	public static ArrayList<Integer> getUncommon(List<ArrayList<Integer>> list) {

		Map<ArrayList<Integer>, AtomicInteger> rank = new HashMap<>();

		for (int i = 0; i < list.size(); i++) {

			ArrayList<Integer> innerList = list.get(i);

			Set<Integer> seen = new HashSet<>();
			
			for (int j = 0; j < innerList.size(); j++) {
				Integer aElement = innerList.get(j);
				
				if(seen.contains(aElement)) {
					continue;
				}else {
					seen.add(aElement);
				}
				
				int counter = 0;
				for (int k = 0; k < list.size(); k++) {

					List<Integer> nextList = list.get(k);

					if (nextList == innerList) {
						continue;
					}

					for (int l = 0; l < nextList.size(); l++) {

						
						Integer bElement = nextList.get(l);

						if (aElement.equals(bElement)) {
							counter++;
							break;
						}
					}
					
					
				}
				rank.putIfAbsent(innerList, new AtomicInteger(0));
				rank.get(innerList).addAndGet(counter);
				
			}
		}

		List<ArrayList<Integer>> keylist = new ArrayList<ArrayList<Integer>>(rank.keySet());

		Collections.sort(keylist, new Comparator<ArrayList<Integer>>() {
			@Override
			public int compare(ArrayList<Integer> x, ArrayList<Integer> y) {
				return rank.get(y).get() - rank.get(x).get();
			}
		});

		System.out.println(rank);

		return keylist.get(keylist.size()-1);

	}

}

- Anonymous January 12, 2020 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static String[] detectOutlier(String [][] list)
	{
		Map<Integer, String[]> scores = new LinkedHashMap<Integer, String[]>();
		for(String [] s : list)
		{
			int score = 0;
			for (String element: s)
			{
				char c = element.toCharArray()[0];
				score+=Character.getNumericValue(c);
			}
			scores.put(score, s);
		}
		
		int max = Collections.max(scores.keySet());
		return scores.get(max);
	}

- Sreeni January 17, 2020 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static String[] detectOutlier(String [][] list)
	{
		Map<Integer, String[]> scores = new LinkedHashMap<Integer, String[]>();
		for(String [] s : list)
		{
			int score = 0;
			for (String element: s)
			{
				char c = element.toCharArray()[0];
				score+=Character.getNumericValue(c);
			}
			scores.put(score, s);
		}
		
		int max = Collections.max(scores.keySet());
		return scores.get(max);
	}

- nagara January 17, 2020 | 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