Jobs
Interviews

Solve Array Increment Operations using C Language

Solve Array Increment Operations using C to enhance your skills with c coding practice , master coding concepts, and prepare for interviews with practical exercises and detailed solutions.

Array Increment Operations

Difficulty : Medium

Categories :

  • Arrays

Design a data structure that supports incrementing subsequence of elements by a value. Implement the CustomArray class:

  • CustomArray(int size): Initializes array of size n with all elements set to 0
  • void increment(int start, int end, int val): Increments all elements from index start to end (inclusive) by val
  • int[] getArray(): Returns the current state of array

Constraints:

  • 1 ≤ size ≤ 10⁵
  • 0 ≤ start ≤ end < size
  • 1 ≤ val ≤ 100
  • At most 10⁴ calls will be made to increment and getArray

Examples:

Input:
["CustomArray", "increment", "increment", "getArray"]
[[5], [0, 2, 100], [1, 4, 100], []]
Output: [null, null, null, [100,200,200,100,100]]
Explanation:
CustomArray arr = new CustomArray(5);
arr.increment(0, 2, 100); // [100,100,100,0,0]
arr.increment(1, 4, 100); // [100,200,200,100,100]
arr.getArray();           // [100,200,200,100,100]

Coding works best on a laptop or desktop, with a keyboard and a wider editor. You can read the problem here and solve it there.

Problem Solving

Input

What You'll Find Here

Practical Challenges Solve coding problems that strengthen your understanding of C.

Step-by-Step Tutorials Learn how to write efficient and optimized code.

Career-Focused Skills Prepare for technical interviews with targeted exercises.

Choose from the following categories