## Akamai Interview Question for Software Engineers

Country: United States
Interview Type: In-Person

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

Use Hashmap while traversing through array, first element already present in hashmap is the duplicate. Sharing my solution in Python below.

``````def secondDuplicate(nums):
counterMap = {}
for num in nums:
if num not in counterMap:
counterMap[num] = 0
else:
return num
return -1``````

Test Code

``print(secondDuplicate([1,2,3,4,5,3,7,2])) # Prints 3``

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

Instead of Using Hashmap we can sort the list and count the second number.

``````func secondNumber(arr []int) int {
var sec_count int
var same_num int
sort.Ints(arr)
for i := 0; i < len(arr)-1; i++ {
fmt.Println(arr[i], sec_count, arr[i])
if arr[i] == arr[i+1] {
if sec_count == 1 && arr[i] != same_num {
return arr[i]
} else {
sec_count += 1
same_num = arr[i]
}
}
}
return -1
}``````

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

``````def secDuplicate(li):
first = None
sec = None
for i, val in enumerate (li):
if val in li [i+1:]:
if first == None:
first = val
else:
sec = val
break
return (first, sec)

testCases = {"no_dups": [1,7,19,8,6,5,9,2, 3], "one_dup": [5,6,3,2,1,1,9], "two_dups": [2,1,3,1,5,2,7]}
for k, li in testCases.items():
print (k, li, secDuplicate (li))``````

no_dups [1, 7, 19, 8, 6, 5, 9, 2, 3] (None, None)
one_dup [5, 6, 3, 2, 1, 1, 9] (1, None)
two_dups [2, 1, 3, 1, 5, 2, 7] (2, 1)

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

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

public class DuplicateValues {

public static void main(String[] args) {
int[] arr={2,3,4,5,7,2,4,7};
Integer c=1;
HashMap hp =new HashMap();
for (int i =0;i<arr.length;i++){
if(hp.containsKey(arr[i])){
c= (Integer) hp.get(arr[i]);
hp.put(arr[i], c+1);
} else
hp.put(arr[i], c);
}

Set s = hp.entrySet();
Iterator it = s.iterator();
while (it.hasNext()) {
Map.Entry mp = (Map.Entry)it.next();
Integer i =(Integer) mp.getValue();
if(i>1){
System.out.println(mp.getKey()+"--"+mp.getValue());
}

}
}

}

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.