## Booking.com Interview Question for Android Engineers

Team: Android
Country: Netherlands
Interview Type: Phone Interview

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

``````import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

public class ConvertArrayFrom3Array {

public static void main(String[] args) {
Integer[] arr1 = {2, 5, 3, 2, 8,1};
Integer[] arr2 = {7, 9, 5, 2, 4, 10, 10};
Integer[] arr3 = {6, 7, 5, 5, 3, 7};

/**
* Combine all the array and remove duplicates
*/
Set<Integer> set1 = new HashSet<>(Arrays.asList(arr1));
Set<Integer> set2 = new HashSet<>(Arrays.asList(arr2));
Set<Integer> set3 = new HashSet<>(Arrays.asList(arr3));

Set<Integer> set = new HashSet<>();

//set1.retainAll(set2);

ArrayList<Integer> list = new ArrayList<>();

for (Integer val: set) {
if(set1.contains(val) && set2.contains(val) && set3.contains(val)) {
}
else if(set1.contains(val) && set2.contains(val)) {
}
else if(set2.contains(val) && set3.contains(val)) {
}
else if(set1.contains(val) && set3.contains(val)) {
}
}

System.out.println(list);
}
}``````

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

``````public static List<Integer> generateCommonList(final List<List<Integer>> lists) {
Set<Integer> ansSet = new HashSet<>();
Set<Integer> uniqueNos = new HashSet<>();
lists.forEach(list ->
new HashSet<>(list).forEach(value -> {
if (uniqueNos.contains(value)) {
} else {
}
}));
return new ArrayList<>(ansSet);``````

}

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

``````A = {2, 5, 3, 2, 8,1}
B = {7, 9, 5, 2, 4, 10, 10}
C = {6, 7, 5, 5, 3, 7}
s1=A&B&C
s2=A&B
s3=A&C
s4=B&C
s=s1|s2|s3|s4
print(s)``````

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

Complexity seems very bad for this solution. I would just use a hash table and scan all array once.
key :- element and value will be set of id {}
for example, in above case hash table entry for 2 will be 2 -> { A, B} since its seem in two arrays.
Later just scan hash table and get result where value size is atleast 2.

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

nice sol ...but still that wont work if you have multiple duplicates
A = {2, 1,1,1,1}
B = {1,1,1, 10}
C = {1,1,1, 10, 7}
output should be {1,1,1}

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

public void extractArray(int[] a, int[] b, int[] c){
List<Integer> list = new ArrayList<Integer>();
for(int i = 0; i< a.length; i++){
int valueSearched = a[i];
System.out.println(valueSearched);
System.out.println("Loop1-----------");
boolean flag1 = false;
boolean flag2 = false;
for(int j =0; j<b.length;j++){
System.out.println(b[j]);
System.out.println("Loop2-----------");
if(!list.contains(valueSearched) && valueSearched == b[j]){
break;
}
}

for(int k=0;k<c.length;k++){
System.out.println(c[k]);
System.out.println("Loop3-----------");
if(!list.contains(valueSearched) && valueSearched == c[k]){
break;
}
}

}
System.out.println(Arrays.toString(list.toArray()));

}

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

{

public void extractArray(int[] a, int[] b, int[] c){
List<Integer> list = new ArrayList<Integer>();
for(int i = 0; i< a.length; i++){
int valueSearched = a[i];
System.out.println(valueSearched);
System.out.println("Loop1-----------");
boolean flag1 = false;
boolean flag2 = false;
for(int j =0; j<b.length;j++){
System.out.println(b[j]);
System.out.println("Loop2-----------");
if(!list.contains(valueSearched) && valueSearched == b[j]){
break;
}
}

for(int k=0;k<c.length;k++){
System.out.println(c[k]);
System.out.println("Loop3-----------");
if(!list.contains(valueSearched) && valueSearched == c[k]){
break;
}
}

}
System.out.println(Arrays.toString(list.toArray()));

}

}

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

Step 1) Sort all the n arrays in ascending order and create a set named "duplicate"
Step 2) create a heap with the first elements i.e. the smallest, of all the arrays.
Step 3) poll out the first 2 elements from heap and also insert 2 elements from the respective 2 arrays, who's elements are taken out of the heap.
Step 4) if the elements are same put it in the set. Throw away the first element, get the next element from heap and compare the current 2 elements and put in the set if same. Also insert another element from the respective array. Continue the process.

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

Integer[] A = {2, 5, 3, 2, 8, 1};
Integer[] B = {7, 9, 5, 2, 4, 10, 10};
Integer[] C = {6, 7, 5, 5, 3, 7};

List<Integer> AA = new ArrayList<>(Arrays.asList(A));
List<Integer> BB = new ArrayList<>(Arrays.asList(B));
List<Integer> CC = new ArrayList<>(Arrays.asList(C));

HashSet<Integer> total = new HashSet<>();

for (Integer s : total) {
if( (AA.contains(s) && BB.contains(s))){
System.out.println(s +" Present in arrays A & B");

} else if( (BB.contains(s) && CC.contains(s))){
System.out.println(s +" Present in arrays B & C");

} else if( (CC.contains(s) && AA.contains(s))){
System.out.println(s +" Present in arrays C & A");

}
}

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

package booking;

import java.util.*;

public class ConstructArray {

static void makeArr(int[] a, int[] b, int[] c) {
HashMap<Integer, Integer> map = new HashMap<>();
Integer[]A = removeDuplicates(a);
Integer[]B = removeDuplicates(b);
Integer[]C = removeDuplicates(c);

System.out.println(Arrays.toString(A));
System.out.println(Arrays.toString(B));
System.out.println(Arrays.toString(C));

for (int i : A)
map.put(i, 1);

for (int j : B) {
if (map.containsKey(j))
map.put(j, 1 + map.get(j));
else
map.put(j, 1);
}

for (int k : C) {
if (map.containsKey(k))
map.put(k, 1 + map.get(k));
else
map.put(k, 1);
}

for (int key : map.keySet()) {
if (map.get(key) > 1)
System.out.print(key);
}

}

static Integer[] removeDuplicates(int a[]){
HashSet<Integer> set = new HashSet<>();
for (int i:a)
return set.toArray(new Integer[set.size()]);
}

public static void main(String[] args) {
int[] A = {2, 5, 3, 2, 8, 1};
int[] B = {7, 9, 5, 2, 4, 10, 10};
int[] C = {6, 7, 5, 5, 3, 7};

makeArr(A,B,C);
}

}

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

``````fun findDuplication(A: List<Int>, B: List<Int>, C: List<Int>) : List<Int> {
val setA = A.toSet()
val setB = B.toSet()
val setC = C.toSet()
val existsIn : Int.(Set<Int>, Set<Int>) -> Boolean = { first, second -> first.contains(this) && second.contains(this) }
val filter : (Int) -> Boolean = { it.existsIn(setA, setB) || it.existsIn(setA, setC) || it.existsIn(setC, setB) }
return setA.plus(setB).plus(setC).filter { filter(it) }
}``````

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

``````public class Solution2 {

public static void main(String[] args) {

int a[] = {9,9,9,9,8,8,8,7,7,6,5,4};
int b[] = {9,9,9,8,8,7,7,6,4,4,4,3,2};
int c[] = {9,9,9,8,8,7,7,6,5};
Integer[] A = removeDuplicates(a);
Integer[] B = removeDuplicates(b);
Integer[] C = removeDuplicates(c);
HashMap<Integer,ArrayList<Integer>> map = new HashMap<>();

// for array a
ArrayList<Integer> list = (ArrayList<Integer>) Arrays.stream(a).boxed().collect(Collectors.toList());
System.out.println(list);
for(Integer i: A){
ArrayList<Integer> tSet = new ArrayList<>();
map.put(i,tSet );

}
System.out.println(map);
list.clear();

// for array b
list = (ArrayList<Integer>) Arrays.stream(b).boxed().collect(Collectors.toList());
System.out.println(list);
for(Integer i: B){
if(map.containsKey(i)){
}
else{

ArrayList<Integer> tSet = new ArrayList<>();
map.put(i,tSet );
}
}
System.out.println(map);
list.clear();

// for array c
list = (ArrayList<Integer>) Arrays.stream(c).boxed().collect(Collectors.toList());
System.out.println(list);
for(Integer i: C){
if(map.containsKey(i)){
}
else{

ArrayList<Integer> tSet = new ArrayList<>();
map.put(i,tSet );
}
}
System.out.println(map);

for(int key: map.keySet()){
if(map.get(key).size()>1){

Collections.sort(map.get(key));
int count= map.get(key).get(0);
for(int i=0; i<count; i++){
System.out.print(key+", ");
}
}
}
//end of main function
}

static Integer[] removeDuplicates(int a[]){
HashSet<Integer> set = new HashSet<>();
for (int i:a)
return set.toArray(new Integer[set.size()]);
}

}``````

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

``````public class Solution2 {

public static void main(String[] args) {

int a[] = {9,9,9,9,8,8,8,7,7,6,5,4};
int b[] = {9,9,9,8,8,7,7,6,4,4,4,3,2};
int c[] = {9,9,9,8,8,7,7,6,5};
Integer[] A = removeDuplicates(a);
Integer[] B = removeDuplicates(b);
Integer[] C = removeDuplicates(c);
HashMap<Integer,ArrayList<Integer>> map = new HashMap<>();

// for array a
ArrayList<Integer> list = (ArrayList<Integer>) Arrays.stream(a).boxed().collect(Collectors.toList());
System.out.println(list);
for(Integer i: A){
ArrayList<Integer> tSet = new ArrayList<>();
map.put(i,tSet );

}
System.out.println(map);
list.clear();

// for array b
list = (ArrayList<Integer>) Arrays.stream(b).boxed().collect(Collectors.toList());
System.out.println(list);
for(Integer i: B){
if(map.containsKey(i)){
}
else{

ArrayList<Integer> tSet = new ArrayList<>();
map.put(i,tSet );
}
}
System.out.println(map);
list.clear();

// for array c
list = (ArrayList<Integer>) Arrays.stream(c).boxed().collect(Collectors.toList());
System.out.println(list);
for(Integer i: C){
if(map.containsKey(i)){
}
else{

ArrayList<Integer> tSet = new ArrayList<>();
map.put(i,tSet );
}
}
System.out.println(map);

for(int key: map.keySet()){
if(map.get(key).size()>1){

Collections.sort(map.get(key));
int count= map.get(key).get(0);
for(int i=0; i<count; i++){
System.out.print(key+", ");
}
}
}
//end of main function
}

static Integer[] removeDuplicates(int a[]){
HashSet<Integer> set = new HashSet<>();
for (int i:a)
return set.toArray(new Integer[set.size()]);
}

}``````

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

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

public class ConvertArrayFrom3Array {

public static void main(String[] args) {
Integer[] arr1 = {2, 5, 3, 2, 8,1};
Integer[] arr2 = {7, 9, 5, 2, 4, 10, 10};
Integer[] arr3 = {6, 7, 5, 5, 3, 7};

/**
* Combine all the array and remove duplicates
*/
Set<Integer> set1 = new HashSet<>(Arrays.asList(arr1));
Set<Integer> set2 = new HashSet<>(Arrays.asList(arr2));
Set<Integer> set3 = new HashSet<>(Arrays.asList(arr3));

Set<Integer> set = new HashSet<>();

//set1.retainAll(set2);

ArrayList<Integer> list = new ArrayList<>();

for (Integer val: set) {
if(set1.contains(val) && set2.contains(val) && set3.contains(val)) {
}
else if(set1.contains(val) && set2.contains(val)) {
}
else if(set2.contains(val) && set3.contains(val)) {
}
else if(set1.contains(val) && set3.contains(val)) {
}
}

System.out.println(list);
}
}

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

``````class Array:
def get_array_map(self, array):
temp_map_ele_array = {}

for ele in array:
if ele in temp_map_ele_array:
continue
else:
temp_map_ele_array[ele] = 1
return temp_map_ele_array

def find_elements_presence(self, arrays):
map_element_occurence = {}
for array in arrays:
temp_map_ele_array = self.get_array_map(array)
for k,v in temp_map_ele_array.items():
if k in map_element_occurence:
map_element_occurence[k] += 1
else:
map_element_occurence[k] = 1

res = []
for k,v in map_element_occurence.items():
if v>=2:
res.append(k)
return res

arrays = [[2, 5, 3, 2, 8,1],[7, 9, 5, 2, 4, 10, 10],[6, 7, 5, 5, 3, 7]]

arr = Array()
print(arr.find_elements_presence(arrays))``````

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

def intersections(arrays, insresectionCount):
count = Counter()
res = set()
for array in arrays:
for k in set(array):
count[k] += 1
if count[k] >= insresectionCount:
return list(res)

arrays = [[2, 5, 3, 2, 8, 1, 1, 2, 2], [7, 9, 5, 2, 4, 10, 10], [6, 7, 5, 5, 3, 7]]
print(intersections(arrays, 2))

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

``````/**
* The idea is for each list of numbers is
* retained = intersect(list, board) ; result += retained ; board += list
*
*
* @author Omid Ghiasi Tarzi
*/
public static List<Integer> getDuplication(List<List<Integer>> lists) {
Set<Set<Integer>> board = new HashSet<>();
Set<Set<Integer>> resultSet = new HashSet<>();
List<Integer> resultList = new ArrayList<>();

for (List<Integer> list : lists) {
Map<Integer, Integer> localMap = new HashMap<>();
Set<Set<Integer>> localSet = new HashSet<>();
for (int i : list) {
localMap.put(i, localMap.getOrDefault(i, 0) + 1);
}

Set<Set<Integer>> retainedSet = new HashSet<>(localSet);
retainedSet.retainAll(board);
}
for (Set<Integer> set : resultSet) {
}
return resultList;
}``````

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

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;

public class Booking {
public static void main(String[] args) {
Integer[] A = { 2, 5, 3, 2, 8, 1 };
Integer[] B = { 7, 9, 5, 2, 4, 10, 10 };
Integer[] C = { 6, 7, 5, 5, 3, 7, 8 };

HashSet<Integer> set = new HashSet<>();
List<Integer> L1 = Arrays.asList(A);
List<Integer> L2 = Arrays.asList(B);
List<Integer> L3 = Arrays.asList(C);

List<Integer> list = new ArrayList<>();
for (int i : set) {
if ((L1.contains(i) && L2.contains(i)) || (L2.contains(i) && L3.contains(i))
|| (L1.contains(i) && L3.contains(i))) {
}
}
System.out.println(list);
}
}

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

``````import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;

public static void main(String[] args) {
Integer[] A = { 2, 5, 3, 2, 8, 1 };
Integer[] B = { 7, 9, 5, 2, 4, 10, 10 };
Integer[] C = { 6, 7, 5, 5, 3, 7, 8 };

HashSet<Integer> set = new HashSet<>();
List<Integer> L1 = Arrays.asList(A);
List<Integer> L2 = Arrays.asList(B);
List<Integer> L3 = Arrays.asList(C);

List<Integer> list = new ArrayList<>();
for (int i : set) {
if ((L1.contains(i) && L2.contains(i)) || (L2.contains(i) && L3.contains(i))
|| (L1.contains(i) && L3.contains(i))) {
}
}
System.out.println(list);
}
}``````

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

``````package it.rob.java.test;

import java.util.HashSet;
import java.util.Set;
import java.util.stream.Collectors;

public class JavaTestMain {

//	make an array from this three arrays which elements is present in at least two array
public static void main(String[] args) {
int[] a = {2, 5, 3, 2, 8, 1};
int[] b = {7, 9, 5, 2, 4, 10, 10};
int[] c = {6, 7, 5, 5, 3, 7};
giveSolution(a, b, c).forEach(i -> System.out.println(i));
}

private static Set<Integer> giveSolution(int[] a, int[] b, int[] c) {
Set<Integer> aSet = removeDuplicate(a);
Set<Integer> bSet = removeDuplicate(b);
Set<Integer> cSet = removeDuplicate(c);
Set<Integer> ab = compare(aSet, bSet);
Set<Integer> ac = compare(aSet, cSet);
Set<Integer> bc = compare(bSet, cSet);
return ab;
}

private static Set<Integer> compare(Set<Integer> a, Set<Integer> b) {
return a.stream().filter(number -> b.contains(number)).collect(Collectors.toSet());
}

private static Set<Integer> removeDuplicate(int[] arr) {
Set<Integer> setArr = new HashSet<>();
for (int i = 0; i < arr.length; i++) {
}
return setArr;
}``````

}

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

``````val a = arrayOf(2, 5, 3, 2, 8, 1)
val b = arrayOf(7, 9, 5, 2, 4, 10, 10)
val c = arrayOf(6, 7, 5, 5, 3, 7)
val merge = arrayListOf(a, b, c)
val map = mutableMapOf<Int, Int>()
val result = mutableListOf<Int>()

var size = 0
// O(3)
merge.forEach {
size = max(size, it.size)
}

// O(N * 3)
for (position in 0..size) {
merge.forEachIndexed { index, it ->
if (it.size > position + 1) {
if (map.containsKey(it[position])) {
if (map[it[position]] != index) {
}
}
map[it[position]] = index
}
}
}
print(result)``````

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

``````package com.lucasmontano.algo

import org.junit.Test
import kotlin.math.max

/**
* You have three Arrays.
*
* A = {2, 5, 3, 2, 8,1}
* B = {7, 9, 5, 2, 4, 10, 10}
* C = {6, 7, 5, 5, 3, 7}
*
* make an array from this three arrays which elements is present in at least two array.
*
* This question was followed by instead of three arrays.
* If you have a list of array then what will be the solution?
* Also what will be the time complexity?
*
*/
class Algo4 {

@Test
fun `caseA`() {
val a = arrayOf(2, 5, 3, 2, 8, 1)
val b = arrayOf(7, 9, 5, 2, 4, 10, 10)
val c = arrayOf(6, 7, 5, 5, 3, 7)
val merge = arrayListOf(a, b, c)
val map = mutableMapOf<Int, Int>()
val result = mutableListOf<Int>()

var size = 0
// O(3)
merge.forEach {
size = max(size, it.size)
}

// O(N * 3)
for (position in 0..size) {
merge.forEachIndexed { index, it ->
if (it.size > position + 1) {
if (map.containsKey(it[position])) {
if (map[it[position]] != index) {
}
}
map[it[position]] = index
}
}
}
print(result)
}
}``````

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

package com.lucasmontano.algo

import org.junit.Test
import kotlin.math.max

/**
* You have three Arrays.
*
* A = {2, 5, 3, 2, 8,1}
* B = {7, 9, 5, 2, 4, 10, 10}
* C = {6, 7, 5, 5, 3, 7}
*
* make an array from this three arrays which elements is present in at least two array.
*
* This question was followed by instead of three arrays.
* If you have a list of array then what will be the solution?
* Also what will be the time complexity?
*
*/
class Algo4 {

@Test
fun `caseA`() {
val a = arrayOf(2, 5, 3, 2, 8, 1)
val b = arrayOf(7, 9, 5, 2, 4, 10, 10)
val c = arrayOf(6, 7, 5, 5, 3, 7)
val merge = arrayListOf(a, b, c)
val map = mutableMapOf<Int, Int>()
val result = mutableListOf<Int>()

var size = 0
// O(3)
merge.forEach {
size = max(size, it.size)
}

// O(N * 3)
for (position in 0..size) {
merge.forEachIndexed { index, it ->
if (it.size > position + 1) {
if (map.containsKey(it[position])) {
if (map[it[position]] != index) {
}
}
map[it[position]] = index
}
}
}
print(result)
}
}

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

package com.lucasmontano.algo

import org.junit.Test
import kotlin.math.max

/**
* You have three Arrays.
*
* A = {2, 5, 3, 2, 8,1}
* B = {7, 9, 5, 2, 4, 10, 10}
* C = {6, 7, 5, 5, 3, 7}
*
* make an array from this three arrays which elements is present in at least two array.
*
* This question was followed by instead of three arrays.
* If you have a list of array then what will be the solution?
* Also what will be the time complexity?
*
*/
class Algo4 {

@Test
fun `caseA`() {
val a = arrayOf(2, 5, 3, 2, 8, 1)
val b = arrayOf(7, 9, 5, 2, 4, 10, 10)
val c = arrayOf(6, 7, 5, 5, 3, 7)
val merge = arrayListOf(a, b, c)
val map = mutableMapOf<Int, Int>()
val result = mutableListOf<Int>()

var size = 0
// O(3)
merge.forEach {
size = max(size, it.size)
}

// O(N * 3)
for (position in 0..size) {
merge.forEachIndexed { index, it ->
if (it.size > position + 1) {
if (map.containsKey(it[position])) {
if (map[it[position]] != index) {
}
}
map[it[position]] = index
}
}
}
print(result)
}
}

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

import java.util.*;
import java.util.stream.Collectors;

public class Main
{
public static void main(String[] args) {
System.out.println("Hello World");

Integer[] A = {2, 5, 3, 2, 8, 1};
Integer[] B = {7, 9, 5, 2, 4, 10, 10};
Integer[] C = {6, 7, 5, 5, 3, 7};

ArrayList<Integer> listA = new ArrayList(Arrays.asList(A));
ArrayList<Integer> listB = new ArrayList(Arrays.asList(B));
ArrayList<Integer> listC = new ArrayList(Arrays.asList(C));

ArrayList<Integer> output = new ArrayList<Integer>();

List<Integer> listAA = listA.stream().distinct().collect(Collectors.toList());
List<Integer> listBB = listB.stream().distinct().collect(Collectors.toList());
List<Integer> listCC = listC.stream().distinct().collect(Collectors.toList());

System.out.println(listAA);

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

for(Integer a : listAA){
map.put(a,1);
}
for(Integer a : listBB){
map.put(a,(map.containsKey(a) ? map.get(a)+1:1));
}

for(Integer a : listCC){
map.put(a,(map.containsKey(a) ? map.get(a)+1:1));
}

for(Map.Entry<Integer, Integer> e : map.entrySet()){
if(e.getValue()> 1){
}

}

System.out.println(map);
System.out.println(output);

}
}

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

``````import java.util.*;
import java.util.stream.Collectors;

public class Main
{
public static void main(String[] args) {
System.out.println("Hello World");

Integer[] A = {2, 5, 3, 2, 8, 1};
Integer[] B = {7, 9, 5, 2, 4, 10, 10};
Integer[] C = {6, 7, 5, 5, 3, 7};

ArrayList<Integer> listA = new ArrayList(Arrays.asList(A));
ArrayList<Integer> listB = new ArrayList(Arrays.asList(B));
ArrayList<Integer> listC = new ArrayList(Arrays.asList(C));

ArrayList<Integer> output = new ArrayList<Integer>();

List<Integer> listAA = listA.stream().distinct().collect(Collectors.toList());
List<Integer> listBB = listB.stream().distinct().collect(Collectors.toList());
List<Integer> listCC = listC.stream().distinct().collect(Collectors.toList());

System.out.println(listAA);

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

for(Integer a : listAA){
map.put(a,1);
}
for(Integer a : listBB){
map.put(a,(map.containsKey(a) ? map.get(a)+1:1));
}

for(Integer a : listCC){
map.put(a,(map.containsKey(a) ? map.get(a)+1:1));
}

for(Map.Entry<Integer, Integer> e : map.entrySet()){
if(e.getValue()> 1){
}

}

System.out.println(map);
System.out.println(output);

}``````

}

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

``````import java.util.*;

/**
* A = {2, 5, 3, 2, 8,1}
* B = {7, 9, 5, 2, 4, 10, 10}
* C = {6, 7, 5, 5, 3, 7}
*/

public class Main {

public static void main(String[] args) {
int[] A = {2, 5, 3, 2, 8, 1};
int[] B = {7, 9, 5, 2, 4, 10, 10};
int[] C = {6, 7, 5, 5, 3, 7};
HashMap<Integer, HashSet<String>> map = new HashMap<>();
for (int element : A) {
if (map.get(element) != null) {
map.put(element, map.get(element));
} else {
HashSet<String> set = new HashSet<>();
map.put(element, set);
}
}
for (int element : B) {
if (map.get(element) != null) {
map.put(element, map.get(element));
} else {
HashSet<String> set = new HashSet<>();
map.put(element, set);
}
}
for (int element : C) {
if (map.get(element) != null) {
map.put(element, map.get(element));
} else {
HashSet<String> set = new HashSet<>();
map.put(element, set);
}
}

// create the array
ArrayList<Integer> elements = new ArrayList<>();
for (Map.Entry<Integer, HashSet<String>> entry : map.entrySet()){
if (entry.getValue().size() > 1) {
}
}

System.out.println(elements);
}
}``````

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

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
* You have three Arrays.
*
* A = {2, 5, 3, 2, 8,1}
* B = {7, 9, 5, 2, 4, 10, 10}
* C = {6, 7, 5, 5, 3, 7}
*
* make an array from this three arrays which elements is present in at least two array.
*
* This question was followed by instead of three arrays.
* If you have a list of array then what will be the solution?
* Also what will be the time complexity?
*/
public class CommonElementsBetweenArrays {

public static void main(String[] args) {
int[] A = {2, 5, 3, 2, 8, 1};
int[] B = {7, 9, 5, 2, 4, 10, 10};
int[] C = {6, 7, 5, 5, 3, 7};

List<Set<Integer>> listsOfUniqueArrays = new ArrayList<>();

Set<Integer> processedElements = new HashSet<>();
Set<Integer> duplicateElementsBetweenArrays = new HashSet<>();

for (Set<Integer> setOfIntegers : listsOfUniqueArrays) {
for (Integer integer : setOfIntegers) {
}
}
}

int[] result = duplicateElementsBetweenArrays.stream().mapToInt(Integer::intValue).toArray();

for (int i : result) {
System.out.println(i+", ");
}
}

private static Set<Integer> intArrayToSet(int[] a) {
Set<Integer> integers = new HashSet<>();
for (int i : a) {
}
return integers;
}
}

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

``````var a1: Array<Any> = arrayOf(2, 5, 3, 2, 8, 1)
var a2: Array<Any> = arrayOf(7, 9, 5, 2, 4, 10, 10)
var a3: Array<Any> = arrayOf(6, 7, 5, 5, 3, 7)
var result = mutableSetOf<Any>()
var separator: String = "-"

// O(n)
var merged = a1.distinct().plus(separator).plus(elements = a2.distinct()).plus(separator).plus(elements = a3.distinct())

// O(n)
var repeatRate = hashMapOf<Any?, Int>()
var iv = 1
for(item in merged) {  // O(n)
if(item != separator){
val rate = repeatRate[item] // O(c)
if(rate != null) {
repeatRate[item] = rate + 1 // O(c)
}
else repeatRate[item] = 1 // O(c)
}
else iv++ // O(c)
}
println(result)``````

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

``````import java.util.HashSet;
import java.util.Set;
import java.util.Arrays;

public class Test{

public static void main(String []args){

Integer[] A = {2, 5, 3, 2, 8,1};
Integer[] B = {7, 9, 5, 2, 4, 10, 10};
Integer[] C = {6, 7, 5, 5, 3, 7};

Set<Integer> setA = new HashSet<>(Arrays.asList(A));
Set<Integer> setB = new HashSet<>(Arrays.asList(B));
Set<Integer> setC = new HashSet<>(Arrays.asList(C));

Set<Integer> full = new HashSet<>();

Set<Integer> output = new HashSet<>();

for (Integer entry : full){

int sharedCount = 0;

if (setA.contains(entry))
sharedCount++;

if (setB.contains(entry))
sharedCount++;

if (sharedCount > 0) {
if (setC.contains(entry))
sharedCount++;
}

if (sharedCount > 1)
}

System.out.println(output.toString());
}
}``````

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

``````import kotlin.math.max

fun main(args: Array<String>) {
val A = intArrayOf(2, 5, 3, 2, 8, 1)
val B = intArrayOf(7, 9, 5, 2, 4, 10, 10)
val C = intArrayOf(6, 7, 5, 5, 3, 7)

val maxValue = max(A.max()!!, max(B.max()!!, C.max()!!))
getCommonElementsInAtLeastTwoOfThree(maxValue, A, B, C)
}

fun getCommonElementsInAtLeastTwoOfThree(
maxValue: Int,
a: IntArray,
b: IntArray,
c: IntArray
) {
val A = IntArray(maxValue+1)
val B = IntArray(maxValue+1)
val C = IntArray(maxValue+1)
for (number in a) {
A[number]++
}
for (number in b) {
B[number]++
}
for (number in c) {
C[number]++
}
for (i in 0 until maxValue) {
if ((A[i] > 0 && B[i] > 0) || (B[i] > 0 && C[i] > 0) || (A[i] > 0 && C[i] > 0)) {
print("\$i ")
}
}
}``````

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

``````func atLeastInTwoArrays(_ listOfArrays: [[Int]]) -> [Int] {
var array: [Int: Int] = [:]
for i in 0..<listOfArrays.count {
for index in 0..<listOfArrays[i].count {
if let current = array[listOfArrays[i][index]] {
array[listOfArrays[i][index]] = current + 1
} else {
array[listOfArrays[i][index]] = 1
}
}
}

var newArray:[Int] = []
for (item, times) in array {
if times > 1 {
newArray.append(item)
}
}
return newArray
}``````

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

``````func atLeastInTwoArrays(_ listOfArrays: [[Int]]) -> [Int] {
var array: [Int: Int] = [:]
for i in 0..<listOfArrays.count {
for index in 0..<listOfArrays[i].count {
if let current = array[listOfArrays[i][index]] {
array[listOfArrays[i][index]] = current + 1
} else {
array[listOfArrays[i][index]] = 1
}
}
}

var newArray:[Int] = []
for (item, times) in array {
if times > 1 {
newArray.append(item)
}
}
return newArray
}``````

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

``````def two_or_more(arrs):
result = {}
for arr in arrs:
for i in arr:
result[i] = result[i] + 1 if i in result else 1
return result

result = two_or_more(x)

for (key, value) in result.items():
if value > 1:
print(key)``````

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.

### 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.