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

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • 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 743 Discussions, By:

recency

Please Login in order to post a comment

  • soujim2
    7 days ago+ 0 comments

    def deleteNode(llist, position): if llist==None: return None else: pre=llist count=1 while pre.next is not None and count

    0|
    Permalink
  • birdmachine007
    1 week ago+ 0 comments

    Python

    def deleteNode(llist, position): if position == 0: llist = llist.next else:
    count = 1 temp = llist while temp != None and count < position: temp = temp.next count += 1

        # print(temp.data)
        temp.next = temp.next.next
        # print(temp.data)
    
    return llist
    
    0|
    Permalink
  • iscodand
    1 week ago+ 0 comments

    simple and descritive python solution

    def deleteNode(llist: SinglyLinkedListNode, position: int):
        if llist == None:
            return
        
        if position == 0:
            return llist.next
            
        position_counter: int = 0
        current: SinglyLinkedListNode = llist
        
        while current != None and position_counter < position - 1:
            position_counter += 1
            current = current.next
    
        current.next = current.next.next
        return llist
    
    0|
    Permalink
  • vidhimittal90
    1 week ago+ 0 comments

    def deleteNode(head, position): if position == 0: head = head.next else: temp = head count = 1 while temp != None and count < position: temp = temp.next count += 1 temp.next = temp.next.next return head

    0|
    Permalink
  • lucasopoka
    2 weeks ago+ 0 comments

    Python

    def deleteNode(llist, position):
        if position == 0:
            llist = llist.next
        else:
            previous = llist
            for _ in range(position - 1):
                previous = previous.next
            to_delete = previous.next
            following = to_delete.next
            previous.next = following
            del to_delete
        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