Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Bubble Sort, Reverse String, and Pointers

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

Your question is Bubble Sort, Reverse String, and Pointers. 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

SanDisk SSD Dashboard receives numeric diagnostic values and a mutable character buffer containing a device label. Implement both operations without using Python's built-in sorting, reversing, slicing, or auxiliary collections.

  1. Sort values in ascending order using stable bubble sort. Equal values must retain their original relative order, and the input list must be modified in place.
  2. Reverse label_chars in place using two pointers, one starting at each end of the list.
  3. Return both modified lists as [values, label_chars].

While explaining your solution, describe what the two index variables represent, how they move, and why Python indices behave as references into the list rather than C-style pointers. The implementation must use constant auxiliary space.

Formal Specification

  • Input: values, a list of integers, and label_chars, a list of one-character strings.
  • Output: [values, label_chars], containing the same two list objects after modification.
  • Sorting must be stable and must use bubble sort with an early-termination optimization.

Constraints

  • 0 <= len(values), len(label_chars) <= 2 * 10^4
  • -10^9 <= values[i] <= 10^9
  • Every element of label_chars is a one-character string
  • Equal values must retain their relative order
  • The input lists must be modified in place
  • Do not use built-in sorting or reversing operations

Function Signature

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