Loading...
Loading...
In legacy enterprise systems (like those built on COBOL), programs can invoke subprograms either statically (linked at compile time, always in memory) or dynamically (loaded at runtime, can be swapped without recompilation). Understanding the performance and memory trade-offs of these paradigms is critical when optimizing large batch systems.
You are simulating a simplified module call dispatcher that decides whether to use a static or dynamic call strategy for a list of subprogram invocations.
Given a list of subprogram calls with their call types and usage frequencies, compute the total execution cost under two strategies:
1 unit (no load overhead). However, memory reservation costs M units per unique static module regardless of call count.D units; subsequent calls to the same module cost 1 unit each.Return the strategy ("STATIC" or "DYNAMIC") with the lower total cost. If costs are equal, return "STATIC".
Your function receives:
calls: a list of strings representing subprogram names in invocation orderM: integer memory reservation cost per unique static moduleD: integer dynamic load cost for first invocation of a moduleReturn a string: "STATIC" or "DYNAMIC"
Input: calls = ["MOD-A", "MOD-B", "MOD-A", "MOD-A"], M = 5, D = 4
Output: "DYNAMIC"
Explanation:
Input: calls = ["MOD-X", "MOD-Y", "MOD-Z"], M = 2, D = 10
Output: "STATIC"
Explanation:
1 <= calls.length <= 10^5 1 <= M, D <= 10^4 Each call name is a non-empty alphanumeric string of length 1-20 Call names are case-sensitive
Input: calls = ["MOD-A"], M = 3, D = 3
Output: "STATIC"
Explanation:
D, subsequent visits cost 1.