Back to course home
0% completed
Vote For New Content
This solution giving incorrect result on its respective leetcode problem.
Biruk
Apr 7, 2022
This solution giving incorrect result on its respective leetcode problem.
0
0
Comments
Comments
B
Biruk 4 years ago
And, even after I fixed the incorrect result, it gives TLE ( Time Limite Exceeded)
B
Biruk 4 years ago
Better approach
def kSmallestPairs(self, nums1: List[int], nums2: List[int], k: int) -> List[List[int]]:
minHeap = []
res = []
# Iterate upto k because the result will not be out of this range
for i in range(min(k, len(nums1))):
heappush(minHeap, (nums1[i] + nums2[0...
Design Gurus4 years ago
Can you share a result where the given algorithm produces wrong output? Also, please do share the leetcode problem link?
B
Biruk 4 years ago
Oh..sorry, I misunderstood the problem. This one is largest sum where as the leetcode problem is smallest sum. https://leetcode.com/problems/find-k-pairs-with-smallest-sums/
On this page