Question DSA-TP-0069
HardHow do you count pairs with sum less than a target in a sorted array in O(n)?
- A.
Nested loops
- B.
Binary search for each element only
- C.
Sign up free to see the answer and a step-by-step explanation.
Popular companies
Prepare company by company
Hiring pattern, syllabus, past questions and mocks for each company.
All companiesPractice by subject
Two Pointers and Sliding Window question
How do you count pairs with sum less than a target in a sorted array in O(n)?
Nested loops
Binary search for each element only
Sign up free to see the answer and a step-by-step explanation.
A hash map
With l at the start and r at the end: if a[l] + a[r] < target, add r − l and move l; otherwise move r