Most Servers Brought to the Same Version With K Upgrade Steps

Last updated: November 29, 2026

Quick Overview

Servers run integer version numbers. One upgrade step raises one server's version by 1. With at most k total steps, return the largest number of servers that can end up on the same version.

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Medium

0

0

0 solved


Servers run integer version numbers. One upgrade step raises one server's version by 1. With at most k total steps, return the largest number of servers that can end up on the same version.

Framed around fleet rollouts in Google's production infrastructure, this tests sort plus a sliding window with a cost formula. The interviewer checks that the candidate realizes the target should be the largest version in the window and computes the window's upgrade cost in O(1).

What the Interviewer Expects
  • Sorts versions and slides a window
  • Targets the window's maximum since versions only go up
  • Computes cost as `max * len - window_sum`
  • Shrinks from the left when cost exceeds k
  • Uses a wide integer type for the cost in other languages
Key Topics to Cover
Sliding Window
Sorting
Prefix Sums
Greedy
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • What if downgrades are also allowed, each costing one step?
  • What if each server has a different cost per step?
  • How would you answer many queries with different k?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements
  • Input: list ver of integers, integer k >= 0.
  • Only increases are allowed, one step per unit per server.
  • Output: the maximum count of servers that can share one version....
High-Level Design

Since we can only raise versions, a group should converge on its largest member, and the cheapest group for a given target is the servers just below it in sorted order. So sort and use a window `[left...


Submit Your Answer
Markdown supported