Company: Agoda
Difficulty: medium
2. Folder Compression You have a folder with n files, each with a size given by fileSize[i], where 0 ≤ i This operation takes 1 second and can be performed any number of times: Extract the first file and insert it at the back (highest index). Continue swapping the file with the one before it until it reaches either the front of the array or a position where its size is strictly greater than the file in front. Return the number of seconds required to compress the folder, or -1 if it's impossible. Function Description Complete the function getMinimumSeconds in the editor below. Function Parameters: int fileSize[n] : the size of the files. Returns int : the number of seconds required to compress the folder or -1 if impossible. Constraints 1 ≤ n ≤ 2 × 10⁵ 1 ≤ fileSize[i] ≤ 10⁹ Example Given, n = 5 fileSize = [4, 3, 1, 3, 5] Steps Operation Description State of Array 0 Initial state [4, 3, 1, 3, 5] 1 Remove the first file (4) and insert it at the back (requires 1 second) [3, 1, 3, 5, 4] 2 S