Ritansh Singhā€™s Post

View profile for Ritansh Singh, graphic

Software Developer | Passionate About Problem Solving | Proficient in JavaScript, TypeScript, React, Next.js, MERN Stack, C++ | Open-Source Contributor | Committed to Professional Growth

šŸ“Œ LeetCode Problem of the Day : [šŸ”„ DAY 267] šŸ“ Name: Merge Nodes in Between Zeros šŸ“ Description: You are given theĀ headĀ of a linked list, which contains a series of integersĀ separatedĀ byĀ 0's. TheĀ beginningĀ andĀ endĀ of the linked list will haveĀ Node.val == 0. ForĀ everyĀ two consecutiveĀ 0's,Ā mergeĀ all the nodes lying in between them into a single node whose value is theĀ sumĀ of all the merged nodes. The modified list should not contain anyĀ 0's. ReturnĀ theĀ headĀ of the modified linked list. Ā  Example 1: Input: head = [0,3,1,0,4,5,2,0] Output: [4,11] Explanation: The above figure represents the given linked list. The modified list contains - The sum of the nodes marked in green: 3 + 1 = 4. - The sum of the nodes marked in red: 4 + 5 + 2 = 11. Example 2: Input: head = [0,1,0,3,0,2,2,0] Output: [1,3,4] Explanation: The above figure represents the given linked list. The modified list contains - The sum of the nodes marked in green: 1 = 1. - The sum of the nodes marked in red: 3 = 3. - The sum of the nodes marked in yellow: 2 + 2 = 4. Ā  Constraints: The number of nodes in the list is in the rangeĀ [3, 2 * 105]. 0 <= Node.val <= 1000 There areĀ noĀ two consecutive nodes withĀ Node.val == 0. TheĀ beginningĀ andĀ endĀ of the linked list haveĀ Node.val == 0. šŸ”—Link: https://lnkd.in/dM9iR5m6

  • text

To view or add a comment, sign in

Explore topics