Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds the implementation of the sublist search algorithm using linked lists in Java. The algorithm determines if one linked list (list2) is a sublist of another linked list (list1) by sequentially comparing nodes using a sliding window approach.
the strategy that i have used:
Node Class: Defined to represent elements in a linked list, encapsulating data and a reference to the next node.
Sublist Search Function: Implemented to check if list2 is a sublist of list1. The function traverses list1 and compares segments of list1 with list2.
Helper Function: Added to create a linked list from an array for easier testing and demonstration.
Main Method: Provided example usage to demonstrate the sublist search algorithm.
Testing:
Created example linked lists and verified that the function correctly identifies sublists.
Tested edge cases including empty lists and lists of different lengths.
Results
Successfully identified list2 as a sublist of list1 in various test cases.
Passed all edge case scenarios.