Pages

Showing posts with label leetcode. Show all posts
Showing posts with label leetcode. Show all posts

Sunday, September 14, 2025

Delete N Nodes After M Nodes in a Linked List (Leetcode Premium Problem)

 

Delete N Nodes After M Nodes in a Linked List

Difficulty Level: Rookie

In this problem, you are given a linked list and two integers, M and N. You need to traverse the linked list such that you:

  1. Retain M nodes, then

  2. Delete the next N nodes, and

  3. Repeat this process until the end of the linked list.


Problem Statement

  • Input: A linked list and two integers M and N

  • Output: The modified linked list after deleting N nodes after every M nodes

Saturday, September 13, 2025

Intersection of Two Linked List (Leetcode-160)

 /**

 * Definition for singly-linked list.
 * public class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode(int x) {
 *         val = x;
 *         next = null;
 *     }
 * }
 */
public class Solution {
    public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
        // if either list are null, return null since no intersection
        if(headA == null || headB == null) {
            return null;
        }

        // set up two runners
        ListNode pA = headA;
        ListNode pB = headB;

        while(pA != pB) {
            pA = (pA == null) ? headB : pA.next;
            pB = (pB == null) ? headA : pB.next;
        }
        return pA;
    }
} OUTPUT: All cases are true.

how to become red on codeforces by Errichto Algorithms | explained simply in a blog

 Yes. I found an available transcript of the video and summarized it simply. The video is “How To Become Red Coder? (codeforces.com)” by Err...