Company: Ibm_24dec
Difficulty: medium
Detect First Anomaly Detect First Anomaly Problem Description You are given a list of numbers representing recorded measurements. A value is called a spike if it is at least three times greater than the maximum of all previous values. Find the 0-based index of the first spike in the stream. If no spike is found, return -1. The function detectFirstAnomaly will take one input: int metrics[] : the monitored data stream values The function should return an integer denoting the 0-based index of the first spike, or -1 if no such spike is found. Examples Example 1: Input: metrics = [3, 10, 2, 7] Output: 1 Explanation: The analysis of metric values is as follows (using 0-based indexing): At index 0: The value is 3. This becomes the initial maximum observed. At index 1: The value is 10. The maximum of previous values is 3. Since 10 ≥ 3 * 3 = 9, this qualifies as a spike. As a spike is detected at index 1, this is the first spike, and we return its index. Example 2: Input: metrics = [2, 1, 5]