Find K Pairs with Smallest Sums with M pointers?

Revision en1, by nonme, 2023-06-27 16:36:37

Hello everyone! Today's LeetCode Daily problem is Find K Pairs with Smallest Sums.

Problem description

This problem is commonly solved with with priority queue. Here's a C++ solution for reference.

Solution with PQ

Many users — and me in particular — initially tried to solve this problem with two pointers — and failed. But is there a way to solve this without priority queue anyway? Using three or more pointers? If not, why? Can it be proved?
Thanks for your attention in advance.

Tags priority queue, leetcode, two pointers

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English nonme 2023-06-27 16:36:37 2629 Initial revision (published)