|
| 1 | +# [Arrays: Array Manipulation](https://www.hackerrank.com/challenges/crush) |
| 2 | + |
| 3 | +Perform m operations on an array and print the maximum of the values. |
| 4 | + |
| 5 | +- Difficulty: ` #hard ` |
| 6 | +- Category: ` #ProblemSolvingIntermediate ` |
| 7 | + |
| 8 | +Starting with a 1-indexed array of zeros and a list of operations, for each |
| 9 | +operation add a value to each the array element between two given indices, |
| 10 | +inclusive. Once all operations have been performed, return the maximum |
| 11 | +value in the array. |
| 12 | + |
| 13 | +## Example |
| 14 | + |
| 15 | +Queries are interpreted as follows: |
| 16 | + |
| 17 | +```text |
| 18 | + a b k |
| 19 | + 1 5 3 |
| 20 | + 4 8 7 |
| 21 | + 6 9 1 |
| 22 | +``` |
| 23 | + |
| 24 | +Add the values of between the indices and inclusive: |
| 25 | + |
| 26 | +```text |
| 27 | +index-> 1 2 3 4 5 6 7 8 9 10 |
| 28 | + [0,0,0, 0, 0,0,0,0,0, 0] |
| 29 | + [3,3,3, 3, 3,0,0,0,0, 0] |
| 30 | + [3,3,3,10,10,7,7,7,0, 0] |
| 31 | + [3,3,3,10,10,8,8,8,1, 0] |
| 32 | +``` |
| 33 | + |
| 34 | +The largest value is `10` after all operations are performed. |
| 35 | + |
| 36 | +## Function Description |
| 37 | + |
| 38 | +Complete the function arrayManipulation in the editor below. |
| 39 | + |
| 40 | +arrayManipulation has the following parameters: |
| 41 | + |
| 42 | +- `int n` - the number of elements in the array |
| 43 | +- `int queries[q][3]` - a two dimensional array of queries where |
| 44 | +each `queries[i]` contains three integers, `a`, `b`, and `k`. |
| 45 | + |
| 46 | +## Returns |
| 47 | + |
| 48 | +- int - the maximum value in the resultant array |
| 49 | + |
| 50 | +## Input Format |
| 51 | + |
| 52 | +The first line contains two space-separated integers `n` and `m`, the size of |
| 53 | +the array and the number of operations. |
| 54 | +Each of the next `m` lines contains three space-separated integers |
| 55 | +`a`, `b` and `k`, the left index, right index and summand. |
| 56 | + |
| 57 | +## Constraints |
| 58 | + |
| 59 | +- $ 3 \leq n \leq 10^7 $ |
| 60 | +- $ 1 \leq m \leq 2*10^5 $ |
| 61 | +- $ 1 \leq a \leq b \leq n $ |
| 62 | +- $ 0 \leq k \leq 10^9 $ |
| 63 | + |
| 64 | +## Sample Input |
| 65 | + |
| 66 | +```text |
| 67 | +5 3 |
| 68 | +1 2 100 |
| 69 | +2 5 100 |
| 70 | +3 4 100 |
| 71 | +``` |
| 72 | + |
| 73 | +## Sample Output |
| 74 | + |
| 75 | +```text |
| 76 | +200 |
| 77 | +```` |
| 78 | +
|
| 79 | +## Explanation |
| 80 | +
|
| 81 | +After the first update the list is `100 100 0 0 0`. |
| 82 | +After the second update list is `100 200 100 100 100`. |
| 83 | +After the third update list is `100 200 200 200 100`. |
| 84 | +
|
| 85 | +The maximum value is `200`. |
0 commit comments