Fortune Telling
Problem Overview
- Given n two-sided cards with front Ai initially up and back Bi, flip at most m cards to minimize the range (max − min) of all face-up numbers.
- Input: n, m, array A (size n), array B (size n). Output: one integer: the minimum possible range.
- Constraints: 1 ≤ m ≤ n; 1 ≤ Ai, Bi ≤ 1e7.
- Real-world context: choose flips in a fortune-telling card setup to tighten the spread of visible numbers.
- Amazon coding interview question/problem and common interview question.
Example
Unlock to view complete problem details
and practice with sample input/output
Was this article helpful?
View Test Cases & Run Code requires membership
Input Variables
Execution Result:
