Two-Sum - Pre-sort Optimization Algorithm Design
The Two Sum solution can be optimized for runtime performance given the input Array is pre-sorted in ascending or descending order.
If Binary Search is used to find the targetCapacity above, it will run in logarithmic, $O(logn)$, average runtime. This is faster than the pseudocode above that runs in linear, $O(n)$, runtime using iteration and hashing.
If sorting was not provided in the input then it would not be possible to sort and search faster than $O(n)$. The best that could be done would be $O(nlogn)$ with a strategy such as Quicksort and Binary Search.
See: Stanford - Two Sum Explanation