Given an array of signal strengths, replace each signal strength with the product of its neighboring signals. Identify the indices of peak signals in the modified array, where a peak signal is one that is not weaker than its neighbors.
Explanation: Step-by-step: For input [5, 2, 8, 3, 1], we first calculate the product of neighboring signals. The product of neighboring signals for the first element 5 is 2 (left neighbor) * 8 (right neighbor) = 16. The product of neighboring signals for the second element 2 is 5 (left neighbor) * 8 (right neighbor) = 40, but we take the minimum of 16 and 40 which is 16. The product of neighboring signals for the third element 8 is 2 (left neighbor) * 3 (right neighbor) = 6, but we take the maximum of 16 and 6 which is 16. The product of neighboring signals for the fourth element 3 is 8 (left neighbor) * 1 (right neighbor) = 8. The product of neighboring signals for the fifth element 1 is 3 (left neighbor) * 8 (right neighbor) = 24. Therefore, the modified array is [10, 16, 24, 3, 5].
Explanation: Step-by-step: For input [1, 8, 2], we first calculate the product of neighboring signals. The product of neighboring signals for the first element 1 is 8 (right neighbor) = 8. The product of neighboring signals for the second element 8 is 1 (left neighbor) * 2 (right neighbor) = 2, but we take the minimum of 8 and 2 which is 2. The product of neighboring signals for the third element 2 is 8 (left neighbor) * 1 (right neighbor) = 8, but we take the maximum of 2 and 8 which is 8. Therefore, the modified array is [8, 16, 2].
Master coding challenges related to Arrays and solve the [Backup] Galaxy Signal Peaks problem optimally.
No dry run loaded.
🚀 Practice this problem
Run code, get AI hints & track streak