Measure perfomance of Python code: There are multiple way to measure performance of a python code, one of them is using perf_counter method of time module. The perf_counter method returns the time measured in nano second. Triplet Sum function using for loop and while loop: def find_triplets(nums, target): triplets = [] nums.sort() # Sort the list for efficient two-pointer approach for i in range(len(nums) – 2): # Skip duplicates for the first element if i > 0and nums[i] == nums[i – 1]: continue left = i + 1 right = len(nums) – 1 while left < right: total = nums[i]
Read More