Extract Cards
Problem Overview
- Given a permutation of n cards, extract them in order 1..n while minimizing score; allowed moves: move first to end adding its value, move last to front adding its value, or discard the next correct card for free; return score mod 1e9+7.
- Input: n (1≤n≤1e5) and Arr[1..n] (permutation 1..n); Output: minimal score mod 1e9+7.
- Context: sequence/card arrangement optimization with rotation costs and free discard.
- From Infosys interviews; a coding interview 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:
