Challenge Description:
You are provided with a list of n
non-negative integers. Your task is to write a program that performs the following operations:
- Query Mode:
- The program should first ask the user if they want to perform queries or updates:
Enter 'Q' for query and 'U' for update
. - If the user enters
Q
, prompt them to enter a range[l, r]
(1-based index) and then output the sum of elements from indexl
tor
inclusive.
- The program should first ask the user if they want to perform queries or updates:
- Update Mode:
- If the user enters
U
, prompt them to enter an indexi
(1-based index) and a valuev
. Update the element at indexi
by addingv
to it (this is an increment operation, not set). - After each update, print the new full array.
- If the user enters
The challenge is designed to teach basic array manipulations and looping constructs, with a focus on handling user inputs and performing range queries and updates efficiently.
Continue reading “Programming Challenge: Array and Loop Manipulation (Intermediate)”