Geeksforgeeks

Error

×

Leaderboard

Showing:

Handle | Score |
---|---|

@Ibrahim Nash | 6420 |

@blackshadows | 6380 |

@mb1973 | 5704 |

@Quandray | 5245 |

@akhayrutdinov | 5111 |

@saiujwal13083 | 5046 |

@sanjay05 | 3762 |

@kirtidee18 | 3673 |

@marius_valentin_dragoi | 3523 |

@mantu_singh | 3510 |

@sushant_a | 3459 |

Complete Leaderboard | |

Handle | Score |

@cfwong8 | 1134 |

@gurshehzadsingh | 676 |

@nithinreddy3210 | 610 |

@Run_for_life | 570 |

@divyagupta221100 | 557 |

@jha8768 | 553 |

@AkashLahoty | 537 |

@aayushdesai01 | 526 |

@riyakumaribkj | 524 |

@amansinha74458 | 503 |

@dreamerdreamer | 488 |

Complete Leaderboard |

Given two string, represented as linked lists (every character is a node->data in the linked list). Write a function compare() that works similar to strcmp(), i.e., it returns 0 if both strings are same, 1 if first linked list is lexicographically greater, and -1 if second is lexicographically greater.

**Input:**

First line of input contains number of testcases T. For each testcase, there will be 4 lines of input. First line of which contains length of first linked list and next line contains the linked list, similarly next two lines contains length and linked list respectively.

**Output:**

Comapare two strings represented as linked list.

**User Task:**

The task is to complete the function **compare**() which compares the strings through linked list and returns 0, 1 or -1 accordingly.

**Constraints:**

1 <= T <= 100

1 <= N, M <= 100

**Example:
Input:**

2

5

a b a b a

4

a b a a

3

a a b

3

a a b

**Output:**

1

0

**Explanation:
Testcase 1**: String consisting of nodes of first linked list is lexicographically greater than the second one. So, the result is 1.

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

YesLoading...

Compare two linked lists

...