Two-pointer traversal 100%
Intuition\nBruteforce is straigt forward but is O(n^2) so i wanted to try solving it with two pointers. this approach would need the nums to be sorted.\n\n# App
# Intuition\nBruteforce is straigt forward but is $$O(n^2)$$ so i wanted to try solving it with two pointers. this approach would need the nums to be sorted.\n\n# Approach\nSort and traverse using two pointers to keep track of left and the right side.\nwhen matched:\n    - if higher, none higher will be below so we decrease the right pointer.\n    - If below\n    - - add to count all numbers below Left pointer\n    - - Increase Left pointer to see if that is also below target in next iteration\n    - Break out if Left and Right is equal.\n\n# Complexity\n- Time complexity:\n$$O(n \\log n)$$ + $$O(n)$$\n\n- Space complexity:\n$$O(1)$$\n\n# Code\n```\nimport "sort"\n\nfunc countPairs(nums []int, target int) int {\n\t// Sort so we can use a pointer for each end\n\tsort.Slice(nums, func(i, j int) bool {\n\t\treturn nums[i] < nums[j]\n\t})\n\n\t// Left and right pointers\n\tl, r := 0, len(nums)-1\n\tcount := 0\n\n\tfor l < len(nums) {\n\t\t/*\n\t\t   If the sum of nums[l] and nums[r] is less than the target, it means all elements from nums[l+1] to nums[r] paired with nums[l] will also have sums less than the target because the array is sorted. Thus, you add r - l to the count and increment the left pointer.\n\t\t   If the sum is not less than the target, decrement the right pointer to try with a smaller value.\n\t\t   The loop breaks if the left and right pointers meet to avoid unnecessary comparisons.\n\t\t*/\n\t\tif nums[r]+nums[l] < target {\n\t\t\tcount += r - l\n\t\t\tl++\n\t\t} else {\n\t\t\tr--\n\t\t}\n\t\tif l == r {\n\t\t\tbreak\n\t\t}\n\t}\n\treturn count\n}\n```
['Go']