Company: Sharechat_15oct
Difficulty: medium
Wave Generation Problem Description The physicists in Hackerland are developing an algorithm to generate wave patterns. An array is considered to form a wave if it satisfies one of these conditions: Elements alternate as: a[1] > a[2] a[4] Elements alternate as: a[1] a[3] a[5]... Given an array arr of n integers, where values are either within the range 1 to m inclusive or -1, determine how many ways you can replace all the -1s in the array with integers from 1 to m such that the resulting array forms a wave. Return the result modulo (10 9 + 7). Function Description Complete the function countWaysToCreateWave in the editor with the following parameters: arr[n] : an array of integers m : an integer Returns int : the number of ways to replace -1s in the array to make it a wave array, modulo (10 9 + 7). Examples Example 1: Input: n = 4 arr = [-1, 1, 2, -1] m = 3 Output: 4 Explanation: Given n = 4 , arr = [-1, 1, 2, -1] , m = 3 . Possible ways to replace all -1s are- [1, 3, 2, 3] [2, 3, 2,