# Maximum Frequency After Subarray Operation: Explained
Maximum Frequency After Subarray Operation shows up often in coding rounds. Here is how I talk through it when the interviewer is watching.
## Key idea
You may pick one subarray and add any integer x to every element of it (one operation). After that, maximize the frequency of a target value k (or of any value — LC 2968/3374-style variants differ). When the goal is to make as many elements equal to k as possible, elements already equal to k should stay, and a subarray of values that share the same (k - value) offset can be shifted together; this reduces to the max number of times a single value appears in a window that you choose to shift onto k, plus the k's outside that window. Kadane on a derived +1/-1 array (treat the chosen source value as +1 and k as -1 so you do not double-count k's inside the window) solves it.
## Steps to say out loud
1. Restate the input and the exact ask, and nail down constraints and overflow.
2. Name the pattern (binary search on the answer, monotonic stack or deque, interval / interval-DP, string hashing, graph traversal, or shortest paths) and why a nested scan or naive search fails.
3. Code it, then trace a short example plus one empty or already-solved edge case.
## Complexity
O(n * U) for U distinct values.
## Common mistake
Shifting a window that already contains k without subtracting those k's (they would be moved off k) or allowing several different source values in one add-x operation.
## Practice tip
Time yourself: two minutes to explain, ten to code, three to test edges. Disclosure: I work on Linkjob AI. I also keep a practice cheat sheet at Linkjob.ai.