File Block

Company: Coursera_16sep

Difficulty: medium

Problem Statement

File Block Problem Description A software team is working on a data storage system where a file is represented as binary string fileBlocks . A '1' represents a compressed file block, and a '0' represents an uncompressed file block. The task is to rearrange the file blocks so that all compressed blocks (1s) are moved to the end of the string. In a single operation, the team can select any compressed block (1) and move it to the right until it reaches the end of the string or another compressed block. The cost of the operation is 1 + (the number of positions moved). Implement a function that finds the minimum total cost required to rearrange the string so that all compressed blocks (1s) are at the right end. The function getMaxCost takes one input: string fileBlocks : a binary string where '1' represents a compressed file block and '0' represents an uncompressed block The function should return the minimum total cost to rearrange the string. Example fileBlocks = "110100" The final string