Company: Myntra_20sep
Difficulty: medium
Perfect Subarrays Problem Description Call an array perfect if it can be rearranged into ascending order purely by picking elements and flipping their sign to negative — any number of times, on any elements. For instance, [3,1,2,4] becomes sorted once we flip the sign of 3, giving [-3,1,2,4] . You'll be given an array seq of n integers, all distinct and drawn from [1, n] (inclusive). Determine how many subarrays of seq are perfect. Input Format Input: The first line holds an integer n , the number of elements in the array. The second line holds n space-separated integers, seq , the array itself. Output Format Output: Print an integer — the count of subarrays of seq that are perfect. Examples Example 1: Input: 3 2 3 1 Output: 5 Explanation: Take seq = [2, 3, 1] . Contiguous Subarrays: Subarray: [2] A single element is already sorted on its own. Running perfect count: 1 Subarray: [3] A single element is already sorted on its own. Running perfect count: 2 Subarray: [1] A single element is