We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • Hackerrank Home
  • Prepare
    NEW
  • Certify
  • Compete
  • Career Fair
  • Hiring developers?
  1. Prepare
  2. Data Structures
  3. Linked Lists
  4. Delete a Node
  5. Discussions

Delete a Node

Problem
Submissions
Leaderboard
Discussions
Editorial

Sort 721 Discussions, By:

recency

Please Login in order to post a comment

  • augustoribeiro_1
    1 day ago+ 0 comments
    public static SinglyLinkedListNode deleteNode(SinglyLinkedListNode llist, int position) {
            
            if (position == 0) {
                return llist.next;
            }
            
            SinglyLinkedListNode n = llist;
            
            int counter = 0;
            while(counter <= position) {
    
                if(counter == position -1) {
                
                    if(n.next == null) {
                        return llist;
                    }
                    
                    n.next = n.next.next;
                    return llist;
                }
                
                n = n.next;
                counter++;
            }
        
            return llist;
        }
    
    0|
    Permalink
  • klu_2200030358
    1 week ago+ 0 comments

    c lang

    SinglyLinkedListNode* deleteNode(SinglyLinkedListNode* llist, int position) { if((position) == 0) { return llist->next; } llist->next = deleteNode(llist->next, position-1); return llist; }

    0|
    Permalink
  • turlakonda_pooja
    2 weeks ago+ 0 comments

    c language

     SinglyLinkedListNode* deleteNode(SinglyLinkedListNode* llist, int position) {
          int count=0;
          if(llist==NULL){
              return NULL;
          }
          if(position==0){
              return llist->next;
          }
          SinglyLinkedListNode* temp=llist;
          SinglyLinkedListNode* prev=NULL;
          while (temp!=NULL) {
              if(count==position){
                  prev->next=temp->next;
                  free(temp);
              }
              count++;
              prev=temp;
              temp=temp->next;
          }
          return llist;
    }
    
    0|
    Permalink
  • 20131a0550
    3 weeks ago+ 0 comments
    def deleteNode(llist, position):
        if position==0:
                return llist.next
        if llist==None:
            return None
        else:
            temp =llist
            temp2=llist.next
            for i in range(position-1):
                
                temp=temp.next
                temp2=temp2.next
            temp.next=temp2.next
            return llist
    
    0|
    Permalink
  • ritikkumawat140
    1 month ago+ 0 comments

    INCLUDE INCLUDE SinglyLinkedListNode* deleteNode(SinglyLinkedListNode* llist, int position) {

    SinglyLinkedListNode*ptr=llist; if (position==0) { return llist->next; } position=position-1; if (llist==NULL) { return llist;

    } while (position--){ ptr=ptr->next; } SinglyLinkedListNode*privious=ptr; ptr=ptr->next; privious->next=ptr->next; // free(ptr); delete ptr; return llist; }

    0|
    Permalink
Load more conversations

Need Help?


View editorial
View top submissions
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy