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
  • Apply
  • Hiring developers?
  1. Prepare
  2. Data Structures
  3. Linked Lists
  4. Compare two linked lists
  5. Discussions

Compare two linked lists

Problem
Submissions
Leaderboard
Discussions
Editorial

Sort 954 Discussions, By:

recency

Please Login in order to post a comment

  • dream101221
    1 day ago+ 0 comments

    Here is the solution of Compare two linked lists Click Here

    0|
    Permalink
  • mdrobiussanysiam
    1 week ago+ 0 comments
       if(head1==NULL && head2!=NULL){
            return false;
        }
        else if(head1!=NULL && head2==NULL){
            return false;
        }
        else if(head1== NULL && head2== NULL){
            return true;
        }
    
        while(head1!=NULL && head2!=NULL){
            if(head1->data!=head2->data){
                return false;
            }
            head1=head1->next;
            head2=head2->next;
        }
    
        if(head1==NULL && head2!=NULL){
            return false;
        }
        else if(head1!=NULL && head2==NULL){
            return false;
        }
        else{
            return true;
        }
    
    0|
    Permalink
  • kiranrr_45
    2 weeks ago+ 0 comments

    All test case passed

    static boolean compareLists(SinglyLinkedListNode head1, SinglyLinkedListNode head2) {

        boolean flag = true;
    
        while (head1 != null && head2 != null){
             if(head1.data != head2.data){
                 flag = false;
                 break;
             }
             head1 = head1.next;
             head2 = head2.next;
        }
    
        if(flag == false || head1 != null || head2 != null){
            return false;
        }
    
        return true;
    
    
    }
    
    0|
    Permalink
  • wbt
    1 month ago+ 0 comments

    The TypeScript language option seems to be missing the compare_lists function described in the problem statement; the same is true for some of the subsequent challenges.

    0|
    Permalink
  • deepanhalder2003
    1 month ago+ 0 comments
    bool compare_lists(SinglyLinkedListNode* head1, SinglyLinkedListNode* head2) {
        if (head1 == NULL && head2 == NULL) {
            return 1;
        } 
        else if (head1 == NULL || head2 == NULL) {
            return 0;
        }
    
        if (head1->data == head2->data) {
            return compare_lists(head1->next, head2->next);
        }
        else {
         return 0;
        }
    
    }
    
    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