Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Topics Problem Submissions Solutions Discuss Java ( 1 7 ) 0 0 : 1 4 : 4 6 Constraints: 1 N 1 0 ? ?

Topics
Problem
Submissions
Solutions
Discuss
Java (17)
00:14:46
Constraints:
1N10??5
1Q10??5
1|rN
0val10??6
0arr[i]10??6
where 'N' is the size of the array, 'Q' is the number of queries, and arr[i] denotes the ith element of the array.
Time Limit: 1 sec.
Sample Input 1:
44
1110
214
1441
234
212
Sample Output 1:
3
2
2
Explanation For Sample Output 1:
0 references
4 public class NumArray {
5
6
7
// Initialize here
private int[] array;
0 references
8 NumArray (int [] arr){
9// write your code here
10 array=new int[arr.length+1];
11
12
13
14
15
16
System.arraycopy(arr,0, array, 1, arr.length);
}
// Update operation
0 references
public void update(int 1, int r, int val){
// Write your code here
for (int i=1;ir;i++)
array[i]+=(val+i-1);
}
// Return the sum of subarray arr[1..r]
0 references
public long rangesum(int 1, int r){
// write your code here
int sum=0;
for (int i=1;ir;i++)
sum+=array [i];
Run
Submit
Sample test case Custom test case
6 Test cases
+- Download
Test case 1: Wrong Answer
Your above test case has failed. Please fix and rerun your code to check remaining test cases.
18, for , array [i]+=(val+i-1);
1920
21
22
23
24
25
26
27
28
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Knowledge Discovery In Databases

Authors: Animesh Adhikari, Jhimli Adhikari

1st Edition

3319132121, 9783319132129

More Books

Students also viewed these Databases questions

Question

How appropriate would it be to conduct additional research?

Answered: 1 week ago

Question

Who are credible sources and opinion leaders for this public?

Answered: 1 week ago

Question

How does or how might your organization affect this public?

Answered: 1 week ago