[Python] matching pair with constraint

Discussão em 'Python' iniciado por Stack, Julho 17, 2025.

  1. Stack

    Stack Membro Participativo

    I have the following question that I have been asked in my interview. I gave a simple solution but apparently that was not correct. Appreciate any insight. Here is the question:

    If the system has 2x servers, then x of them will be primary and the other x will be backup servers. For each primary server P, there exists a backup server B where the memory capacity of B ≥ memory capacity of P. The system's memory capacity is the sum of the memory capacity of all the primary servers. Given n servers and an array memory, find the maximum system memory capacity that can be formed using the n servers.

    My solution:

    Sorting the array and use even indices as primary.

    any thoughts?

    Continue reading...

Compartilhe esta Página