Multiple Queries using array nums
Given an integer array nums, handle multiple queries of the following types:
Update the value of an element in nums.
Calculate the sum of the elements of nums between indices left and right inclusive where left <= right.
Input
["NumArray", "sumRange", "update", "sumRange"]
[[[1, 3, 5]], [0, 2], [1, 2], [0, 2]]
Output
[null, 9, null, 8]
class NumArr(object): def __init__(self,nums): self.nums=nums def update(self,index,val): self.nums[index]=val def sum1(self,i,j): self.sum=0 for k in range(i,j+1): self.sum+=self.nums[k] return self.sum #getting the input numarr,sumr= list(map(int,input('Num : ').split(','))),list(map(int,input('sumR : ').split(','))) update=list(map(int,input('Update : ').split(','))) rang=list(map(int,input('SRange : ').split(','))) #creating obj obj1=NumArr(numarr) x=obj1.sum1(rang[0],rang[1]) obj1.update(update[0],update[1]) y=obj1.sum1(rang[0],rang[1]) print([None,x,None,y])
Input_1:
Num : 1,3,5
sumR : 0,2
Update : 1,2
SRange : 0,2
Output:
[None, 9, None, 8]
Input_2:
Num : 1,2,3,5,6,7,8
sumR : 0,5
Update : 5,10
SRange : 0,6
Output:
[None, 32, None, 35]
Illustration of the Output:
![](http://www.fcukthecode.com/wp-content/uploads/2021/12/Screenshot-from-2021-12-11-20-43-24.png)
More Q
- Determine if a person could attend all meetings in given interval times.
- Find the volume of a volley ball
- Find the maximum score obtained at the end of colour chess grid game.
- Find the number of pairs if positive integers with condition is even.
- Return the largest subset such that every pair meets the given condition.
- Find the number of index triplets that satisfy given condition.
- Handling multiple queries using array – sum, update, range.
- Find all the sequences that occur more than once in DNA molecule.
- Find the biggest number.
- Sum of cube of each number is again equal to the number then it is an Armstrong number.
- Hello World.
- Calculate the Cube Root.
- Find the count of consecutive 1’s present in array.
- Return an array with athletes relative ranks according to the score.
- Return a string of its base 7 representation.
- Return kth largest element in sorted order.
- Find all repeated elements in the array.
- Find atleast one duplicate number in the array.
- Find the maximum result of = a XOR b.