Question: Given an array of integers, arr, you need to create a new array, arr', by performing a number of operations. Since arr may be large,
Given an array of integers, arr, you need to create a new array, arr', by performing a number of operations. Since arr may be large, you want to choose a data structure that will provide optimal performance. Choose the best data structure.
Note: The array is indexed. All positive integers can be represented as the sum of powers of
For each index i that is a power of : Replace arr'i with the sum of the values in arr from index through i For example, if i the new arr' then arr' arr arr Since is a power of arr' arr arr
For each index i that is even but not a power of : Replace arr'i with arr'k arr'k arr'km where the k values are the powers of that sum to i If i arr' arr' arr'
For each index i that is odd: The value of arr'i should be unchanged.
Examples:
arr
Output: arr'
arr
Output: arr'
Pick ONE option:
Create an array and do a prefix sum of all even index elements per the rules.
Implement a binary index tree and update all the even indexes per the rules.
Design a segment tree. For even indexes, find the powers of that sum to the index and sum the values at those indexes. Save the value to its node.
Create an array. For each even index, iterate the array to determine final values.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
