AMAZON | SDE I | OA 2022
Anonymous User
887

image
image
Intuition

  1. create a variable max_memory
  2. Keep a sliding window of m - size and update the max_memory with the maximum seen so far
  3. Subtract the maximum from the total sum
def minimizeMemory(processes, m):
	total_memory = sum(processes)
	left = 0
	max_memory = float('-inf')
	temp_sum = 0
	for right in range(len(processes)):
		temp_sum += processes[right]
		if right - left + 1 == m:
			max_memory = max(max_memory, temp_sum)
			temp_sum -= processes[left]
			left += 1
	return total_memory - max_memory
Comments (5)