I applied to cisco through a referal. I got interview call after 3 weeks. The process has total 3 rounds. 2 rounds went well both rounds asked questions related to sorting. The third round is a managerial round but I was asked a coding question

Question:

Write a function which takes 2 inputs - array of integers and a target. It should output a list of tuples that adds to target.
I wrote the below code.

output = []
def targetSum(arr,target,ind,currSum,templist,output):
    if ind>=len(arr):
        return
    if currSum>target:
        return
    if currSum==target:
        output.append(tuple(templist))
        return 
         
    templist.append(arr[ind])
    targetSum(arr,target,ind+1,currSum+arr[ind],templist,output)
    templist.pop()
    targetSum(arr,target,ind+1,currSum,templist,output)

targetSum([ 3, 5, 7, 2, 6, 4, 0 ],9,0,0,[],output)
print(output)

Input : ([ 3, 5, 7, 2, 6, 4, 0 ], target : 9
Output : [(3, 2, 4), (3, 6), (5, 4), (7, 2)]
The interviewer was telling that I have not understand the question and at the end he provided his expected output [(3, 6), (5, 4), (7, 2)] teelling that its not matching my output and asked for any question I have and left the call.

Later I have serched the question online and I have found the question was the below one

Given an array arr[] of n integers and a target value, the task is to find whether there is a pair of elements in the array whose sum is equal to target. This problem is a variation of 2Sum problem.

In the question he did not specify that the tuple should have pair of values or tuple with length 2. I wonder how can a person know without giving right description. I don't want to blame the interviewer. Writing this just to understand did I miss anything in the question.
Please guide me If I miss anything about understanding the question.

Comments (2)