Blackrock | Online coding test| target sum
Anonymous User
4696

Recently I have attended an online coding assesment. Able to solve using brute force solution.
Problem is as follows
From a list of numbers need to find numbers that are greater than target sum
pair that equal to target sum
and triplet that equal to target sum
If any number greater than or equal to target sum consider that a valid case
Can't use same number twice
All the below cases for target sum 1000
Input: [12000, 300, 500, 600, 700]
Output: [[12000], [300, 700]]
Input: [100,100,100,200,200,200,300]
Output: []
Input: [200, 300, 200, 300, 300,700]
Output: [[300, 700]]
Input: [200, 300,200, 300, 600,300,700]
Output: [[200,200,600],[300, 700]]

My solution approach is as follows:
Sorted input array
Converted that to a list
Searched from end of list and record indexes
Delete from list

Searched through list for pair matching target sum
if matched recorded indexes
After loop deleted indexes

Repeat same for triple sum

Please post if any better solution is solution.

Comments (2)