Pergunta de entrevista da empresa Amazon

Abstract class vs interface in Java

Resposta da entrevista

Sigiloso

12 de jan. de 2014

/* this answers the question regarding intersection of two arrays */ /* Time complexity = O(m+n) where m and n are lengths of the two arrays Space complexity = O(m + n), if n > m; or O(2m) ~ O(m), if m > n. */ List Intersect(int[] arr1, int[] arr2) { Dictionary hashMap1 = new Dictionary(); List intersection = new List(); foreach(int n in arr1) { hashMap[n] = true; } foreach(int n in arr2) { if(hashMap1.ContainsKey(n)) { intersection.Add(n); hashMap1.Remove(n); } } return intersection; }