[DAY23]Triple sum

Sherlock Chiou
1 min readNov 1, 2019

--

Solution: In python, we can use set() function to build an unordered collection of unique elements. Hence, we apply set function to input array a, b, c. For the numbers in the sorted_b array, we only need to count how many numbers in sorted_a are smaller or equivalent to them. And we also need to count how many numbers in sorted_c are smaller or equivalent to them. And by multiplying two numbers above, we could get the number of triplets. Since we have sorted the input arrays, we only need to keep updating the indexes and don’t need to traverse the whole array from head to tail.

--

--

Sherlock Chiou
Sherlock Chiou

Written by Sherlock Chiou

Be Effective and Optimize for Learning

No responses yet