Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Start free
Linked List and String Reversal Patterns
00:00
5 left

Linked List and String Reversal Patterns

MediumPython

Problem

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.

Formal Specification

Implement solve(s, k, reverse_head, list1, list2):

  1. Reverse the characters in s from index 0 through index k, inclusive. Leave the remaining suffix unchanged.
  2. Reverse reverse_head in place and return the new head.
  3. Merge 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.

Constraints

  • 1 <= len(s) <= 10^5
  • 0 <= k < len(s)
  • Each linked list contains at most 10^5 nodes
  • Node values are integers in [-10^9, 10^9]
  • list1 and list2 are sorted in nondecreasing order
  • All linked lists are acyclic

Function Signature

def solve(s, k, reverse_head, list1, list2):
Interviewer

Whenever you're ready, walk me through your approach or go straight to the code. The requirements are in the Question tab.

Sign up free to run or submit. Log in
Code
Sign up free to run your code. Your draft is saved.Run with a free accountLog inLn 2
Run your code to see test output here.