Sort by

recency

|

983 Discussions

|

  • + 0 comments

    Kotlin:

    fun reversePrint(llist: SinglyLinkedListNode?): Unit {
        val list=ArrayList<Int>()
        var current=llist
        while(current!=null){
            list.add(current.data)
            current=current.next
        }
        list.reverse()
        list.forEach{
            println(it)
        }
    }
    
  • + 0 comments

    Here is my c++ solution, you can watch the vidéo explanation here : https://youtu.be/WO7Uz7sQML4

    void reversePrint(SinglyLinkedListNode* llist) {
        if(llist == nullptr) return;
        reversePrint(llist->next);
        cout << llist->data << endl;
    }
    
  • + 0 comments

    This is the perfect way to understand recursive

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

  • + 0 comments

    Third issue with C# template here... hackerrank, what's up with that? You need good C# coders to fix up your templates????

    Solution:

    Same as prior problem

    remove class Result, but keep its guts. change function to be non-public -- remove public keyword.

  • + 0 comments

    solution with javascript

    function reversePrint(llist) {
        var i =0;
        var arr = []
            let currentNode = llist
            while(currentNode!==null){
                i++;
               currentNode = currentNode.next;
            }
             currentNode = llist;
            for(let j = 0;j<i;j++){
                arr.unshift(currentNode.data);
                currentNode = currentNode.next;
            }
           for(let j=0;j<i;j++){
            console.log(arr[j])
           }
        // Write your code here
    
    }