Pick Non-Adjacent Edge Sites Arranged Around a Ring Network

Last updated: November 29, 2026

Quick Overview

Edge cache sites sit on a ring, each with an expected latency savings, and two neighboring sites cannot both be upgraded because they share power. Return the maximum savings from upgrading a set of non-adjacent sites, where the first and last sites are also neighbors.

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

0

0

0 solved


Edge cache sites sit on a ring, each with an expected latency savings, and two neighboring sites cannot both be upgraded because they share power. Return the maximum savings from upgrading a set of non-adjacent sites, where the first and last sites are also neighbors.

An onsite follow-up to the linear take-or-skip problem: Google interviewers like seeing whether you can reduce the circular constraint to two linear runs. The evaluation centers on the reduction argument and the single-site corner case.

What the Interviewer Expects
  • Reuse the linear non-adjacent DP as a helper
  • Break the ring by excluding the first or the last site
  • Argue that one of the two cases contains the optimum
  • Handle rings of size 1 and 2 correctly
  • Keep O(n) time and O(1) extra space
Key Topics to Cover
1D dynamic programming
Circular constraints
House robber II
Problem reduction
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 adjacency extends to two neighbors on each side?
  • Return which sites to upgrade.
  • The ring becomes a general graph. What is the complexity now?
  • Some sites are mandatory. How do you incorporate that?
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 save of non-negative numbers for sites 0..n-1 on a ring. Choose a subset with no two ring-adjacent sites (site n - 1 is adjacent to site 0). Output the maximum total. For n = 1 the only ...

High-Level Design

In any valid choice, site 0 and site n - 1 are not both chosen. So the optimum either excludes site 0 or excludes site n - 1 (or both). Excluding a site cuts the ring into a line, where the linear rec...


Submit Your Answer
Markdown supported