Your question is Linked List and String Reversal Patterns. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Red Hat test tooling may need to transform textual data and linked-list representations during validation. Implement one function that performs three independent operations: reverse a string through a specified index, reverse a singly linked list, and merge two sorted singly linked lists.
Implement solve(s, k, reverse_head, list1, list2):
s from index 0 through index k, inclusive. Leave the remaining suffix unchanged.reverse_head in place and return the new head.list1 and list2, which are sorted in nondecreasing order, into one sorted linked list. Reuse the existing nodes rather than creating replacement value nodes.Each linked list is represented as a nested JSON-compatible object with integer field value and nullable field next. The function returns a dictionary containing reversed_string, reversed_list, and merged_list, each in the same serialized linked-list format.
def solve(s, k, reverse_head, list1, list2):