Question bank › Dynamic Programming
Dsa Dynamic Programming Easy

Minimize Deallocation Cost

You are tasked with managing a memory pool in a program. The pool can hold a certain number of blocks, each with a certain lifetime. If a block has lifetimes that overlap, the blocks cannot be allocated simultaneously. The cost of deallocating a block is equal to its lifetime duration. Given an array of integers representing the lifetime durations of the blocks, write a function to minimize the deallocation cost while ensuring no overlapping lifetimes occur. The function should read the input in a specific format and print the minimal total deallocation cost. Input format: - The first line contains an integer n (1 <= n <= 1000) - the number of blocks. - The second line contains n integers, each representing the duration of lifetimes of the blocks. Output format: - A single integer indicating the minimized total deallocation cost. Example: Input: 5 3 2 5 1 4 Output: 6

Key concepts

dynamic_programmingarraysgreedy

Practise this out loud — free

Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.

🎙 Practise this question now
Part of InterviewLab's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.