Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Array Reversal Without Built-ins

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

Your question is Array Reversal Without Built-ins. 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

Infineon Technologies engineers may need to reorder sampled data used by an AURIX microcontroller pipeline. Given an array of values, reverse its elements in place without using array-reversal helpers.

Implement reverse_array(arr) so that it rearranges arr into reverse order and returns the same array object. Do not use reversed(), slicing, .reverse(), sorting, or any library operation that directly reverses the array. Using indexing, len(), and a temporary variable is allowed.

Formal Specification

  • Input: arr, a mutable Python list containing integers.
  • Output: The same list object, with its elements ordered from last to first.
  • The input must be modified directly rather than copied into a second list.

Constraints

  • 0 <= len(arr) <= 10^5
  • Each element is an integer in the range [-10^9, 10^9].
  • The reversal must run in O(n) time.
  • Extra space must be O(1).
  • Array-reversal helpers, slicing, and sorting are not allowed.

Function Signature

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