Skip to content

Commit 54e011a

Browse files
Update 1679-max-number-of-k-sum-pairs.md
1 parent 098da13 commit 54e011a

File tree

1 file changed

+2
-7
lines changed

1 file changed

+2
-7
lines changed

dsa-solutions/lc-solutions/1600-1699/1679-max-number-of-k-sum-pairs.md

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@
22
id: max-number-of-k-sum-pairs
33
title: Max Number of K-Sum Pairs (Leetcode)
44
sidebar_label: 0082-MaxNumberofK-SumPairs
5-
description: You are given an integer array nums and an integer k.
6-
7-
In one operation, you can pick two numbers from the array whose sum equals k and remove them from the array.
8-
9-
Return the maximum number of operations you can perform on the array.
5+
description: You are given an integer array nums and an integer k.In one operation, you can pick two numbers from the array whose sum equals k and remove them from the array.Return the maximum number of operations you can perform on the array.
106
---
117

128
## Problem Description
@@ -55,7 +51,6 @@ There are no more pairs that sum up to $6$, hence a total of $1$ operation.
5551

5652
The code finds the maximum number of pairs in nums that sum to $k$ by first sorting the array and then using the two-pointer technique. Pointers start and end check pairs: if their sum equals $k$, the count is incremented and both pointers move inward. If the sum is greater than $k$, end moves left; if less, start moves right. This approach efficiently identifies pairs with a sum of $k$ in $O(nlog⁡n)$ time due to sorting and $O(n)$ time for the two-pointer traversal.
5753

58-
5954
### Approach
6055

6156
1. **Sorting the Array:**
@@ -159,4 +154,4 @@ public:
159154

160155
### Conclusion
161156

162-
The code effectively calculates the maximum number of pairs in an array nums that sum up to the given value $k$ using the two-pointer technique. It first sorts the array in ascending order, which enables efficient pair finding. The two pointers start and end traverse the sorted array, checking pairs. If the sum of elements at these pointers equals $k$, a valid pair is found, and both pointers move inward. If the sum is greater than $k$, end moves left to reduce the sum; if less, start moves right to increase the sum. This approach optimally identifies pairs with a sum of $k$, with a time complexity of $O(n log n)$ due to sorting and $O(n)$ for the two-pointer traversal, making it efficient for large arrays.
157+
The code effectively calculates the maximum number of pairs in an array nums that sum up to the given value $k$ using the two-pointer technique. It first sorts the array in ascending order, which enables efficient pair finding. The two pointers start and end traverse the sorted array, checking pairs. If the sum of elements at these pointers equals $k$, a valid pair is found, and both pointers move inward. If the sum is greater than $k$, end moves left to reduce the sum; if less, start moves right to increase the sum. This approach optimally identifies pairs with a sum of $k$, with a time complexity of $O(n log n)$ due to sorting and $O(n)$ for the two-pointer traversal, making it efficient for large arrays.

0 commit comments

Comments
 (0)