Morgan Stanley Interview Question

2-sum problem with a few variations