354. Identical Linked Lists Check (Recursive)

EasyLinked ListLinked ListRecursionComparison

Given two singly linked lists, use recursion to determine if they are identical (same length and same values at every position). Return true if identical, false otherwise.

Input: Heads of two singly linked lists.

Output: Boolean true if identical, false otherwise.

Examples

Example 1
Input: [1,2,3], [1,2,3]
Output: true
Explanation: All values match recursively.
Example 2
Input: [1,2,3], [1,2,4]
Output: false
Explanation: 3rd values differ: 3 vs 4.
Example 3
Input: [1,2],   [1,2,3]
Output: false
Explanation: Different lengths.

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →