Company: HCL TECH

Difficulty: medium

Problem Statement

Minimize Array Cost Given an array of `n` integers, its cost is the sum of the squared differences of adjacent elements. Insert exactly one integer at any position to minimize the cost after insertion. Print the minimum possible cost. Input Format The first line contains `n`. The second line contains the array. Output Format Print the minimum possible cost. Constraints `1 ≤ n ≤ 100000`; `-10000 ≤ ai ≤ 10000`. Use 64-bit arithmetic. Notes The inserted integer may be any integer. Inserting at either end cannot lower the cost.

More HCL TECH OA questionsInterview experiences