Akamai Interview Question for Software Engineers

Country: United States
Interview Type: In-Person

Comment hidden because of low score. Click to expand.
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
      return num
  return -1

Test Code

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

- prudent_programmer September 14, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
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
	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

- testdata017 September 16, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
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 
                sec = val 
    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)

- SD September 20, 2018 | Flag Reply

Add a Comment

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.


is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More


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.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More