Solution of count pairs whose sum is less than target problem || two-pointer algorithm
Approach\nSolved using two-pointer algorithm\n\n# Example\nnums = [-1,1,2,3,1], target = 2\n- left, right = 0, 4\n- nums.sort() --> nums = [-1, 1, 1, 2, 3]\n- W
# Approach\nSolved using two-pointer algorithm\n\n# Example\n**nums = [-1,1,2,3,1], target = 2**\n- `left, right = 0, 4`\n- `nums.sort()` --> $$nums = [-1, 1, 1, 2, 3]$$\n- While the left pointer is less than the right pointer:\nif nums[left] + nums[right] < target:\n$$nums[left] = -1, nums[right] = 3$$ \n$$nums[left] + nums[right] = 2$$ $$== target$$ --> `False`\n- else:\n`right -= 1` --> $$right = 3 $$ --> $$nums[right] = 2$$\n- if nums[left] + nums[right] < target:\n$$nums[left] = -1, nums[right] = 2$$\n$$nums[left] + nums[right] = 1$$  $$< target$$ -> `True`\n`counter += right - left` --> as nums[left:right] will also count\n`left += 1` --> $$left = 1$$ --> $$nums[left] = 1$$\n- Continue this process until the left pointer crosses the right pointer.\n\n\n# Complexity\n- Time complexity:\n$$O(nlogn)$$ - as sorting the array takes $$O(n log n)$$ time and two-pointer\nalgorithm takes linear time, $$O(n)$$ --> $$O(nlogn + n)$$ == $$O(nlogn)$$.\n\n- Space complexity:\n$$O(1)$$ - as, no extra space is required.\n\n# Code\n```\nclass Solution:\n    def countPairs(self, nums: List[int], target: int) -> int:\n        counter = 0\n        left, right = 0, len(nums) - 1\n        nums.sort()\n        while left < right:\n            if nums[left] + nums[right] < target:\n                counter += right - left\n                left += 1\n            else:\n                right -= 1\n        return counter\n\n```
['Array', 'Two Pointers', 'Sorting', 'Python3']