Skip to content

Commit

Permalink
Add new daily problem to README
Browse files Browse the repository at this point in the history
  • Loading branch information
7oSkaaa committed May 17, 2023
1 parent 7e3c390 commit 1abf526
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions 05- May/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
1. **[Maximize Score After N Operations](#14--maximize-score-after-n-operations)**
1. **[Swapping Nodes in a Linked List](#15--swapping-nodes-in-a-linked-list)**
1. **[Swap Nodes in Pairs](#16--swap-nodes-in-pairs)**
1. **[Maximum Twin Sum of a Linked List](#17--maximum-twin-sum-of-a-linked-list)**

<hr>
<br><br>
Expand Down Expand Up @@ -881,4 +882,49 @@ public:
}
};
```

<hr>
<br><br>

## 17) [Maximum Twin Sum of a Linked List](https://leetcode.com/problems/maximum-twin-sum-of-a-linked-list/)

### Difficulty

![](https://img.shields.io/badge/Medium-orange?style=for-the-badge)

### Related Topic

`Linked List` `Two Pointers` `Stack`

### Code


```cpp
class Solution {
public:

int pairSum(ListNode* head) {
// Create a vector to store the values of the linked list nodes
vector < int > nums;
ListNode* curr = head;

// Traverse the linked list and store the values in the vector
while (curr != nullptr) {
nums.push_back(curr -> val);
curr = curr -> next;
}

// Initialize left and right pointers, and the maximum sum
int l = 0, r = nums.size() - 1, mx_sum = INT_MIN;

// Find the maximum sum of pairs
while (l < r)
mx_sum = max(mx_sum, nums[l++] + nums[r--]);

// Return the maximum sum
return mx_sum;
}

};
```

0 comments on commit 1abf526

Please sign in to comment.