Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Reverse a Linked List

EasyPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Reverse a Linked List. 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.

You need to log in / sign up to run or submit.

Problem

Yelp Reservations processes booking-status events in fixed-size batches. Given an array of status identifiers, reverse the elements within every complete group of k consecutive elements, modifying the array in place. If the final group contains fewer than k elements, leave that group unchanged.

Return the modified array.

Formal Specification

  • Input: statuses, a list of integers, and k, a positive integer.
  • Output: The same list object after reversing each complete group of k elements.
  • The function must use constant extra space, excluding the input list.

Constraints

  • 1 <= len(statuses) <= 10^5
  • 1 <= k <= 10^5
  • -10^9 <= statuses[i] <= 10^9
  • The input list must be modified in place

Function Signature

def reverse_batches(statuses, k):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output