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
3d

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!
Add answer anonymously...
Samsung Research Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

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

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter