Back to problems

Max Element at Position k with Adjacent Differences 1 and Sum m

Algorithm · Squarepoint · Medium

Problem You are given three integers: n (the size of an array), m (the required total sum of all elements), and k (a 1‑based index). Construct an array of length n that satisfies two rules: The absolute difference between any two adjacent elements is exactly 1. The sum of all elements equals m. Among all arrays that meet these conditions, determine the maximum possible value that can appear at index k. Input Three integers: n, m, k. Output A single integer — the largest…

Checking your access…