Sort by

recency

|

994 Discussions

|

  • + 0 comments

    Golang Solution with recursive:

    func reversePrint(llist *SinglyLinkedListNode) {
        if llist.next != nil {
            reversePrint(llist.next)
        }
        fmt.Println(llist.data)
    }
    
  • + 0 comments

    c++ solution using stack

    void reversePrint(SinglyLinkedListNode* llist) {
        std::stack<int> stack;
        SinglyLinkedListNode* node = llist;
        while (node != NULL) {
            stack.push(node->data);
            node = node->next;
        }
        while (!stack.empty()) {
            printf("%d\n", stack.top());
            stack.pop();
        }
    }
    
  • + 0 comments

    Java Solution Using Tail Recursion

    public static void reversePrint(SinglyLinkedListNode llist) {
            SinglyLinkedListNode current = llist;
    
            if(current != null){
                    reversePrint(current.next);
                    System.out.println(current.data);
            }
    }
    

    }

  • + 0 comments

    Python 3 solution, not the most efficient:

    def reversePrint(llist):
        vals = []
        while llist:
            vals.append(llist.data)
            llist = llist.next
        if vals:    
            reversed_vals = reversed(vals)
        for t in reversed_vals:
            print(t)
    
  • + 1 comment

    To the Hackerrank Team!!!! Please fix the C# variants for SingleLinkedList problems!!! Almost all of them give compiler errors. The solutions work (adapted) in java but they won't compile in C# because of the input parsing code. Thank you!