Remove all Occurences of Duplicates in a Linked List | GFG POTD | C++ | Java | Code Kar Lo

Поділитися
Вставка
  • Опубліковано 16 лип 2024
  • Given a sorted linked list, delete all nodes that have duplicate numbers (all occurrences), leaving only numbers that appear once in the original list, and return the head of the modified linked list.
    0:00 Introduction
    0:13 Problem Statement
    1:00 Explanation
    6:19 C++ Code
    10:22 Java Code
    My DSA Journey:- • How Did I Learn Data S...
    How to Earn By GFG Articles:- • How to Write Article o...
    Infosys Coding Questions:- • Infosys Coding Questions
    Pattern Playlist: • Patterns
    Problem Link:-www.geeksforgeeks.org/problem...
    Code Link:-github.com/ShubhamKashyap138/...
    Playlist Link:- • Geeks for Geeks POTD
    Linkedin:- / shubham-kashyap-65a29a218
    Instagram:- im_shubham_kash...
    My GFG Profile:- auth.geeksforgeeks.org/user/s...
    gfg potd
    gfg potd today
    gfg problem of the day
    potd gfg
    potd
    potd today
    gfg
    #dsa #datastructures #algorithm #gfg #potd #coding #array #strings #tree #binarysearchtree #codekarlo #dynamicprogramming

КОМЕНТАРІ • 6

  • @devlpr-nitish
    @devlpr-nitish 13 днів тому

    legend bro

    • @code_kar_lo
      @code_kar_lo  13 днів тому

      Thanks bro. Do not say legend because i am not🙏.

  • @lucifercoxi8324
    @lucifercoxi8324 13 днів тому

    time limit exceeded for both C++ and Java code of yours, i used this:
    if (!head || !head->next) return head;
    // Create a dummy node to handle edge cases
    Node* ans = new Node(-1);
    Node* temp = ans;
    Node* prev = head;
    head = head->next;
    int count = 1;
    while (head) {
    if (prev->data == head->data) {
    // Increase count if current node is same as previous
    count++;
    } else {
    // If count is 1, add previous node to the result
    if (count == 1) {
    temp->next = prev;
    temp = temp->next;
    }
    // Reset count and update previous pointer
    count = 1;
    prev = head;
    }
    head = head->next;
    }
    // Handle the last set of nodes
    if (count == 1) {
    temp->next = prev;
    } else {
    temp->next = nullptr;
    }
    return ans->next;

    • @code_kar_lo
      @code_kar_lo  13 днів тому

      This is not my code you have modified it so it may be breaking somewhere. Please try the code from code link.

    • @lucifercoxi8324
      @lucifercoxi8324 13 днів тому

      @@code_kar_lo this is the modified code that worked, the code I copied from you said time limit exceeded.

    • @code_kar_lo
      @code_kar_lo  13 днів тому

      I have checked both the codes again you must have done some mistake in coping the code as only you have faced the problem