In this post we will tackle the LeetCode 307. Range Sum Query – Mutable problem using the Java programming language and the VSCode IDE on a Windows computer. Unless you have a good reason (i.e., keep test code and solution on the same source code) my suggestion is to solve the problem using the online IDE provided by LeetCode.
Given an integer array nums, handle multiple queries of the following types: o Update the value of an element in nums. o Calculate the sum of the elements of nums between indices left and right inclusive where left <= right. Implement the NumArray class: o NumArray(int[] nums) Initializes the object with the integer array nums. o void update(int index, int val) Updates the value of nums[index] to be val. o int sumRange(int left, int right) Returns the sum of the elements of nums between indices left and right inclusive (i.e. nums[left] + nums[left + 1] + ... + nums[right]). Constraints: o 1 <= nums.length <= 3 * 10^4 o -100 <= nums[i] <= 100 o 0 <= index < nums.length o -100 <= val <= 100 o 0 <= left <= right < nums.length o At most 3 * 10^4 calls will be made to update and sumRange. Related Topics: * Array o Design o Binary Indexed Tree * Segment Tree
We are given an int[] and asked to perform two operations as part of a class. Continue reading “LeetCode 307. Range Sum Query – Mutable in Java”