Vonage interview question

1. Codility codingtest with 2 questions on algorithms 2. Code interview with lead developer on a shared board : method with two int arrays as input that return an array as output which does not have common elements in the given two arrays after you write the solution, what will be the time complexity? 2 times o(n)*o(n). How can we reduce this time comlexity or make it memory efficient? 3. Technical interview with manager : diff between Kafka and rabbit mq, some more questions about kafka how Kafka is scaled. Difference between rational and no sql databases. How relational databases are scaled. Data structure questions. Pseudo code method with a string input returns a string output with the occurrences of duplicates input: abbcccabbbb output: a2b3ca4b

Interview Answer

Anonymous

Apr 18, 2023

two int arrays as input that return an array as output which does not have common elements in the given two arrays public Integer[] solution(Integer[] a, Integer[] b){ List list1 = Arrays.asList(a); List list2 = Arrays.asList(b); List itemInANotPresentInB = list1.stream().filter(itemInA -> l. list2.stream().noneMatch(itemInB -> itemInA == itemInB) ).collect(Collectors.toList()); List itemInBNotPresentInA = list2.stream().filter(itemInB -> list1.stream().noneMatch(itemInA -> itemInA == itemInB) ).collect(Collectors.toList()); itemInANotPresentInB.addAll(itemInBNotPresentInA); Integer[]arr = new Integer [itemInANotPresentInB.size()]; return itemInANotPresentInB.toArray(arr); } Time complexity o(n) * o(n) for this line List itemInANotPresentInB = list1.stream().filter(itemInA -> l. list2.stream().noneMatch(itemInB -> itemInA == itemInB) ).collect(Collectors.toList()); o(n) * o(n) for this lines List itemInBNotPresentInA = list2.stream().filter(itemInB -> list1.stream().noneMatch(itemInA -> itemInA == itemInB) ).collect(Collectors.toList()); Total time complexity : 2 times o(n) * o(n) Next question how can you make this faster with less time complexity. i do not have an answer? lets not convert array to list and if we perform the same operation on arrays what will be the time complexity ans) either its array or list the time complexity is the same 2 times o(n)* o(n)

1