Optimize Context Switching

Problem Overview

  • Given n segments with threadSize[i], adjust values to maximize the number of “special” segments where threadSize[i-1] < threadSize[i] > threadSize[i+1]; endpoints cannot be special.
  • Input: n and threadSize array; operation: choose index i and add x, with 0 ≤ x ≤ 1e18. Output: the minimum total increase that still achieves the maximum possible special segments.
  • Domain: process/thread stack tuning to optimize context switching.
  • From LinkedIn interviews; a coding interview interview question and array optimization problem.

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: