PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Amazon

Solve median extremes and segment flips

Last updated: Mar 29, 2026

Quick Overview

This question evaluates proficiency in algorithm design, efficient data structures for dynamic order-statistics and sliding-window median computation, and combinatorial optimization for binary-array segmentation with minimal flips.

  • Medium
  • Amazon
  • Coding & Algorithms
  • Software Engineer

Solve median extremes and segment flips

Company: Amazon

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: Medium

Interview Round: Take-home Project

Part A — Sliding-window median extremes: - Input: an integer k (1 ≤ k ≤ n) and an array nums of length n. - For every contiguous subarray of length k, compute its median (for even k, use the lower median). - Output: the maximum and the minimum among these medians. - Design an algorithm that runs in O(n log k) time and O(k) space, and describe the data structures used. Part B — Even-length uniform segmenting with minimal flips: - Input: a binary array frames of length n. - You may flip any bits (0↔ 1). - After flipping, the array must be partitionable into contiguous segments, each of even length and containing identical values (all 0s or all 1s). - Objective: minimize the number of segments; subject to that minimum, minimize the total number of flips. - Output: the minimal number of segments and the minimal flips needed to achieve it. - Describe an algorithm and provide its time and space complexity.

Quick Answer: This question evaluates proficiency in algorithm design, efficient data structures for dynamic order-statistics and sliding-window median computation, and combinatorial optimization for binary-array segmentation with minimal flips.

Related Interview Questions

  • Implement Datacenter Router Commands - Amazon (hard)
  • Replace Delimited Tokens in a String - Amazon (medium)
  • Minimize Circular Redistribution Cost - Amazon (medium)
  • Find the Most Common Visit Pattern - Amazon (hard)
  • Maximize Value Under a Budget - Amazon (medium)
Amazon logo
Amazon
Jul 26, 2025, 12:00 AM
Software Engineer
Take-home Project
Coding & Algorithms
1
0

Part A — Sliding-window median extremes:

  • Input: an integer k (1 ≤ k ≤ n) and an array nums of length n.
  • For every contiguous subarray of length k, compute its median (for even k, use the lower median).
  • Output: the maximum and the minimum among these medians.
  • Design an algorithm that runs in O(n log k) time and O(k) space, and describe the data structures used.

Part B — Even-length uniform segmenting with minimal flips:

  • Input: a binary array frames of length n.
  • You may flip any bits (0↔ 1).
  • After flipping, the array must be partitionable into contiguous segments, each of even length and containing identical values (all 0s or all 1s).
  • Objective: minimize the number of segments; subject to that minimum, minimize the total number of flips.
  • Output: the minimal number of segments and the minimal flips needed to achieve it.
  • Describe an algorithm and provide its time and space complexity.

Submit Your Answer

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Amazon•More Software Engineer•Amazon Software Engineer•Amazon Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 8,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.