← Akuna Capital Interview Insights
Start by sorting the array, then use two pointers from both ends to greedily pair the smallest available element with the largest. If their sum meets the threshold, count the pair and move both pointers inward; otherwise, discard the smallest element by moving the left pointer. This yields the maximum number of disjoint pairs in O(n log n) time.
Pro tip: Emphasize that the greedy choice is safe because pairing the smallest element with the largest possible partner never reduces the number of future pairs—this is the key exchange argument that proves optimality.
Confirm the problem constraints (disjoint pairs, threshold T) and sort the array in ascending order. Sorting is the first step of the O(n log n) algorithm.
Initialize left = 0, right = n-1, count = 0. While left < right, if profits[left] + profits[right] >= T, increment count and move both pointers inward; else move left forward. This greedily forms pairs.
Use an exchange argument: if an optimal solution pairs the smallest element with some element other than the largest possible, swapping to pair it with the largest cannot decrease the number of pairs. Thus the greedy choice is safe.
Sorting takes O(n log n) time, and the two-pointer scan takes O(n) time, so overall O(n log n) time. Space is O(1) extra if sorting in place, or O(n) if a copy is used.
Discuss odd n (one element left unpaired), negative values (sums can be negative, but the greedy still works), extreme T (T very large yields 0 pairs; T very small yields floor(n/2) pairs), and empty array.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.