Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Min First Half Max Second Half

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

Your question is Min First Half Max Second Half. 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

Alten telemetry processing separates each sensor reading window into two segments. Write a function that returns the minimum value from the first half of nums and the maximum value from the second half.

For an array of length n, define the halves as follows:

  • First half: indices 0 through n // 2 - 1
  • Second half: indices n // 2 through n - 1

For odd-length arrays, the middle element belongs to the second half.

Formal Specification

Implement half_extremes(nums).

  • Input: nums, a list of integers with at least two elements.
  • Output: a two-element list [first_half_minimum, second_half_maximum].

Do not sort the array. A single pass over each half is sufficient.

Constraints

  • 2 <= len(nums) <= 10^5
  • -10^9 <= nums[i] <= 10^9
  • The input list contains only integers
  • For odd-length arrays, index len(nums) // 2 belongs to the second half

Function Signature

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