Approach to Answering AI/Data Science Interview Coding Questions
Vimarsh Karbhari
1731

Quick correction:

Example: Given nums = [2, 7, 11, 15], target = 18,

nums[0] + nums[2] = 7+ 11= 18, return [0, 2].

  • shouldn’t this be: [1,2], not [0,2]?

A python version if anyone is interested (returns NONE if there is no match)

def twosum(lstnum,target):
    for index,value in enumerate(lstnum):
      if target-value in lstnum[index+1:]:
           return [index,lstnum.index(target-value)]
    return "NONE"