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.
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
Top Samsung Research Software Developer interview questions & answers
Popular interview questions of Software Developer
Top HR questions asked in Samsung Research Software Developer
Reviews
Interviews
Salaries
Users/Month