I took the online assesment for Amazon for SDE-1 position yesterday, and here are the questions that I got in the test. Hope it helps someone.
Q1. Given a list of item association relationships, write an algorithm that outputs the largest item association group. If two groups have the same number of items then select the group which contains the item that appears first in lexicographic order.
Input :
[[Item1, Item2], [Item3, Item4], [Item4, Item5]]
Output :
[Item3, Item4, Item5]
Function Signature :
class Solution {
public List<String> largestItemAssociation(List<PairString> itemAssociation) {
// write your code here
}
}
public class PairString {
String first;
String second;
public PairString(String first, String second) {
this.first = first;
this.second = second;
}
}Q2. Given a string s, and a const k, return all substrings of length k such that there are k-1 distinct characters in each substring.
Input :
S = "awaglk", k = 4
Output :
[awag]
Explanation :
All possible substrings of length k from the given string are [awag, wagl, aglk]. And only "awag" has k-1 distinct characters.
Function Signature :
class Solution {
public List<String> subStringsLessKDist(String inputstring, int k) {
// write your code here
}
}