## Interview Question for Android Engineers

Country: India
Interview Type: Phone Interview

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

``````// ZoomBA
symmetric_diff = list1 ^ list2``````

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

``````package com.eb.corealgo;

import java.util.ArrayList;

public class FindUnCommon {

public ArrayList<Integer> getUnCommon(ArrayList<Integer> list1,ArrayList<Integer> list2){

int indexOfElement=-1;
if(list1.size()==0){
return list2;
}
if(list2.size()==0){
return list1;
}

ArrayList<Integer> returnList=new ArrayList<Integer>();
//if not find form both
for(int i=0;i<list1.size();i++){

if(!list2.contains(list1.get(i))){
}
if(list2.contains(list1.get(i))){
indexOfElement=list2.indexOf(list1.get(i));
list2.remove(indexOfElement);
}

}

return returnList;
}

//test Application
public static void main(String args[]){

FindUnCommon un=new FindUnCommon();

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

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

System.out.println(un.getUnCommon(l1, l2));

}

}``````

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

Take both the lists as a string. Then take two frequency counters f1[10] and f2[10]. Initialise all the 10 elements of both the arrays to 0. Now traverse the two strings from left to right. Increment the counter like- f1[ a [ i ] - ' 0 ' ]++ and f2[ b[i] - '0']++. Now take a loop from 0 to 9 and check whether f1[i]==f2[i] or not. Time complexity- O(list size)*10.

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

Using hashmap
firstly, if we use list related api Running time will be O(mn). Because, contains() in list is O(n)
Secondly, if we use set related api it maintains only unique elements but not how many times it repeated
To solve these two things we use hash map. It contains unique elements and maintains as value how many times each element is repeated. Also, we are using linkedhashmap to preserve the order in which elements occurred
Importantly, add/contains/remove methods are O(1)

// Time : O(m+n), Space : O(max(m,n))

``````public static List<Integer> findUncommonElements(Integer a1[], Integer a2[]) {
if (null == a1 && null == a2) {
return null;
}
if (null == a1 || a1.length == 0)
return Arrays.asList(a2);
if (null == a2 || a2.length == 0)
return Arrays.asList(a1);

List<Integer> result = new ArrayList<>();
Map<Integer, Integer> countMap = new LinkedHashMap<>();
for (int i : a2) {
countMap.compute(i, (key, value) -> {
if (null == value)
return 1;
return value + 1;
});
}

for (int i : a1) {
if (countMap.containsKey(i)) {
countMap.remove(i);
} else {
}
}
for (int key : countMap.keySet()) {
for (int i = 0; i < countMap.get(key); i++) {
}
}
return result;
}``````

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

1. Use Hashing O(n)
2. Use Sorting O(nlogn)

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

I/P :
List 1 : 1, 2, 3, 1, 5
List 2 : 3, 4, 5, 6, 7
O/P : 1, 1, 2, 6, 7
Shouldn't the output be 1,2,4,6,7

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

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace careercup
{
class Program
{
static void Main(string[] args)
{
List<int> l1 = new List<int>(){1,5,6,3,2};
List<int> l2 = new List<int>() { 1, 7, 2, 9, 5 };

IList<int> uniqueNumbers = new List<int>();

foreach (var item in l1)
{
if (!action.CheckIfElementIsPresent(item, l2)) { uniqueNumbers.Add(item);

Console.WriteLine(item);
}

}
foreach (var item in l2)
{
if (!action.CheckIfElementIsPresent(item, l1))
{

Console.WriteLine(item);
}
}

}
}
class action
{

public static bool CheckIfElementIsPresent(int a, ICollection<int> collection)
{

return collection.Where(x => x == a).Any();
}
}

}

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

class Program
{
static void Main(string[] args)
{
List<int> l1 = new List<int>(){1,5,6,3,2};
List<int> l2 = new List<int>() { 1, 7, 2, 9, 5 };

IList<int> uniqueNumbers = new List<int>();

foreach (var item in l1)
{
if (!action.CheckIfElementIsPresent(item, l2)) { uniqueNumbers.Add(item);

Console.WriteLine(item);
}

}
foreach (var item in l2)
{
if (!action.CheckIfElementIsPresent(item, l1))
{

Console.WriteLine(item);
}
}

}
}
class action
{

public static bool CheckIfElementIsPresent(int a, ICollection<int> collection)
{

return collection.Where(x => x == a).Any();
}
}

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

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace careercup
{
class Program
{
static void Main(string[] args)
{
List<int> l1 = new List<int>(){1,5,6,3,2};
List<int> l2 = new List<int>() { 1, 7, 2, 9, 5 };

IList<int> uniqueNumbers = new List<int>();

foreach (var item in l1)
{
if (!action.CheckIfElementIsPresent(item, l2)) { uniqueNumbers.Add(item);

Console.WriteLine(item);
}

}
foreach (var item in l2)
{
if (!action.CheckIfElementIsPresent(item, l1))
{

Console.WriteLine(item);
}
}

}
}
class action
{

public static bool CheckIfElementIsPresent(int a, ICollection<int> collection)
{

return collection.Where(x => x == a).Any();
}
}

}

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

``````using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace careercup
{
class Program
{
static void Main(string[] args)
{
List<int> l1 = new List<int>(){1,5,6,3,2};
List<int> l2 = new List<int>() { 1, 7, 2, 9, 5 };

IList<int> uniqueNumbers = new List<int>();

foreach (var item in l1)
{
if (!action.CheckIfElementIsPresent(item, l2)) { uniqueNumbers.Add(item);

Console.WriteLine(item);
}

}
foreach (var item in l2)
{
if (!action.CheckIfElementIsPresent(item, l1))
{

Console.WriteLine(item);
}
}

}
}
class action
{

public static bool CheckIfElementIsPresent(int a, ICollection<int> collection)
{

return collection.Where(x => x == a).Any();
}
}

}``````

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

is changing the original list allowed?
any constrain with time complexity

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

``````private void solution(int[] input1, int[] input2)
{
HashMap<Integer,Integer> hm = HashMap<Integer,Integer>();
for(int i=0,int j=0;i<input1.length ||j<input2.length;i++;j++)
{

if(i<input1.length && hm.containsKey(input1[i]))
{
int count = hm.get(input1[i]);
if(count == 0 || count >0)
{
// Do nothing, its either both or only A
}
else
{
// its there in both the lists
hm.put(input1[i],0);
}

}
else
hm.put(input[i],1);

if(j<input2.length && hm.containsKey(input2[j]))
{
int count = hm.get(input2[i]);
if(count == 0 || count <0)
{
// Do nothing, its either both or only B
}
else
{
// its there in both the lists
hm.put(input2[i],0);
}

}
else
hm.put(input[i],-1);

}

Iterator it = hm.entrySet().iterator();

while(it.hasNext())
{
Map.Entry pair = (Map.Entry) it.next();
if(it.getValue()!=0)
System.out.println(it.getValue());

}``````

}

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

import java.util.Map;
import java.util.Map.Entry;
import java.util.TreeMap;

public class UnCommonCharacters {

/**
* @param args
*/
public static void main(String[] args) {

String str1= "characters";
String str2= "alphabets";
char[] c1= str1.toLowerCase().toCharArray();
char[] c2= str2.toLowerCase().toCharArray();

Map<Character, Integer> countMap = new TreeMap<>();
for(char i : c1){
countMap.put(i, 1); // Present in 1st String
}

for(char i : c2){
if(countMap.containsKey(i)){
countMap.put(i,-1); // Common to both the strings
}
else {
countMap.put(i,2); // Present in 2nd String
}
}

for(Entry<Character, Integer> ent : countMap.entrySet())
if(!(ent.getValue() == -1)){
System.out.println(ent.getKey());
}

}

}

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

// Python
def find_uncommon(list1, list2):

uncommon_elements = []

for item in list1:
if item not in list2:
uncommon_elements.append(item)
for item in list2:
if item not in list1:
uncommon_elements.append(item)

return uncommon_elements

find_uncommon([1, 2, 3, 1, 5], [3, 4, 5, 6, 7])

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

``````// Python
def find_uncommon(list1, list2):

uncommon_elements = []

for item in list1:
if item not in list2:
uncommon_elements.append(item)
for item in list2:
if item not in list1:
uncommon_elements.append(item)

return uncommon_elements

find_uncommon([1, 2, 3, 1, 5], [3, 4, 5, 6, 7])``````

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.