Batch Photography Problem

Alex has acquired a machine that can photocopy photos in batches of a minimum size 'K'. Given 'N' photos with resolutions represented in an integer array photos, the machine produces an error for each batch. The error is computed as the absolute difference between the highest and the lowest resolution in that batch.

Alex aims to split the photos into groups, each with size at least 'K', to minimize the maximum error across all batches. Help Alex by determining the minimum possible maximum error.

Example:

Input:
resolutions = [1, 5, 2], K = 2
Output:
4
Explanation:

There is only one way to divide the array into a single group of all three photos, resulting in an error of 5 - 1 = 4.

Constraints:

  • 1 ≤ T ≤ 10
  • 1 ≤ K ≤ N ≤ 104
  • 1 ≤ photos[i] ≤ 109
  • Time Limit: 1 sec
Note:
You only need to implement the function and return the result; there is no need to print anything.
AnswerBot
4mo

Minimize maximum error by splitting photos into batches of size at least 'K'.

  • Sort the array of resolutions in ascending order.

  • Iterate through the array and calculate the error for each possible batch....read more

Help your peers!
Select
Add answer anonymously...

Samsung Research Software Developer interview questions & answers

A Software Developer was asked 12mo agoQ. Design and implement a data structure for Least Recently Used (LRU) cache. It sh...read more
A Software Developer was asked 12mo agoQ. Trie Implementation
A Software Developer was asked Q. The Skyline Problem Compute the skyline of given rectangular buildings in a 2D c...read more

Popular interview questions of Software Developer

A Software Developer was asked 12mo agoQ1. Design and implement a data structure for Least Recently Used (LRU) cache. It sh...read more
A Software Developer was asked 4d agoQ2. What is the number of ways to reach the bottom right corner from the top left co...read more
A Software Developer was asked 4d agoQ3. What is the definition of Object-Oriented Programming (OOP), and how does polymo...read more
Samsung Research Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits