I believe that the solution in the book (2015 edition) is incomplete:
Solution in the book
This yields “2 -> 3 -> 5 -> 7 -> null” for L1 = “2 -> 5 -> 7 -> null” and L2 = “3 -> 11 -> null” which is wrong
More test results:
Merging 1 -> 3 -> 5 -> null and 2 -> 4 -> 6 -> null
<<< Merge result : 1 -> 2 -> 3 -> 5 -> null
Merging 1 -> 3 -> null and 2 -> 4 -> 6 -> null
<<< Merge result : 1 -> 3 -> null
Merging 1 -> null and 2 -> 4 -> 6 -> null
<<< Merge result : 1 -> null
Merging 3 -> null and 2 -> 4 -> 6 -> null
<<< Merge result : 3 -> null
Merging 7 -> null and 2 -> 4 -> 6 -> null
<<< Merge result : 7 -> null
I’ve added what I think is necessary and got the tests to pass, in Kotlin, wdyt?