✅☑[C++/Java/Python/JavaScript] || Easy Approach || EXPLAINED🔥
PLEASE UPVOTE IF IT HELPED\n\n---\n\n\n# Approaches\n(Also explained in the code)\n\n1. Initialization and Declarations:\n\n    - ans stores the total number of
# PLEASE UPVOTE IF IT HELPED\n\n---\n\n\n# Approaches\n**(Also explained in the code)**\n\n1. **Initialization and Declarations:**\n\n    - `ans` stores the total number of minimum steps required.\n    - `vector<int> black` is used to hold indices of \'1\'s encountered in the input string `s`.\n    - `n` denotes the length of the input string s.\n1. **Finding \'1\'s:**\n\n    - The code iterates through the string `s` to find the indices of characters that are \'1\'s and stores these indices in the `black` vector.\n1. **Calculating Minimum Steps:**\n\n    - After finding all \'1\'s, the code calculates the minimum steps required to move each \'1\' to the end of the string.\n    - For each \'1\' at index `black[i]`, the steps needed to move it to the end are `(n - i - 1 - black[i])`.\n    - The code accumulates th$$O(n)$$ese steps into the `ans` variable.\n\n\n# Complexity\n- *Time complexity:*\n   $$O(N)$$ (where N is the length of the input string s)\n    \n\n- *Space complexity:*\n   $$O(M)$$ ( where M represents the number of \'1\'s in the input string s)\n    \n\n\n# Code\n```C++ []\n\nclass Solution {\npublic:\n    long long minimumSteps(string s) {\n        long long ans = 0;            // Variable to store the result\n        vector<int> black;            // Vector to store indices of \'1\'s in the string\n\n        int n = s.length();           // Length of the input string \'s\'\n\n        // Iterate through the string \'s\' to find indices of \'1\'s\n        for (int i = 0; i < n; i++) {\n            if (s[i] == \'1\') {\n                black.push_back(i);   // Store index if the character is \'1\'\n            }\n        }\n\n        reverse(black.begin(), black.end()); // Reverse the \'black\' vector\n\n        // Calculate the minimum steps required\n        for (int i = 0; i < black.size(); i++) {\n            // For each \'1\', calculate steps needed to move it to the end\n            ans += (n - i - 1 - black[i]);\n        }\n\n        return ans; // Return the total minimum steps\n    }\n};\n\n\n```\n```C []\n\n\n\nlong long minimumSteps(char *s) {\n    long long ans = 0;         // Variable to store the result\n    int black[1000];           // Array to store indices of \'1\'s in the string\n    int n = strlen(s);         // Length of the input string \'s\'\n    int i, j = 0;\n\n    // Iterate through the string \'s\' to find indices of \'1\'s\n    for (i = 0; i < n; i++) {\n        if (s[i] == \'1\') {\n            black[j++] = i;    // Store index if the character is \'1\'\n        }\n    }\n\n    // Reverse the \'black\' array\n    for (i = 0, j--; i < j; i++, j--) {\n        int temp = black[i];\n        black[i] = black[j];\n        black[j] = temp;\n    }\n\n    // Calculate the minimum steps required\n    for (i = 0; i < j; i++) {\n        // For each \'1\', calculate steps needed to move it to the end\n        ans += (n - i - 1 - black[i]);\n    }\n\n    return ans;  // Return the total minimum steps\n}\n\n\n\n```\n```Java []\n\npublic class Solution {\n    public long minimumSteps(String s) {\n        long ans = 0;                     // Variable to store the result\n        List<Integer> black = new ArrayList<>(); // List to store indices of \'1\'s in the string\n\n        int n = s.length();               // Length of the input string \'s\'\n\n        // Iterate through the string \'s\' to find indices of \'1\'s\n        for (int i = 0; i < n; i++) {\n            if (s.charAt(i) == \'1\') {\n                black.add(i);            // Store index if the character is \'1\'\n            }\n        }\n\n        Collections.reverse(black);      // Reverse the \'black\' list\n\n        // Calculate the minimum steps required\n        for (int i = 0; i < black.size(); i++) {\n            // For each \'1\', calculate steps needed to move it to the end\n            ans += (n - i - 1 - black.get(i));\n        }\n\n        return ans; // Return the total minimum steps\n    }\n}\n\n\n```\n```python3 []\nclass Solution:\n    def minimumSteps(self, s: str) -> int:\n        ans = 0                            # Variable to store the result\n        black = []                         # List to store indices of \'1\'s in the string\n\n        n = len(s)                         # Length of the input string \'s\'\n\n        # Iterate through the string \'s\' to find indices of \'1\'s\n        for i in range(n):\n            if s[i] == \'1\':\n                black.append(i)            # Store index if the character is \'1\'\n\n        black.reverse()                    # Reverse the \'black\' list\n\n        # Calculate the minimum steps required\n        for i in range(len(black)):\n            # For each \'1\', calculate steps needed to move it to the end\n            ans += (n - i - 1 - black[i])\n\n        return ans  # Return the total minimum steps\n\n\n\n```\n```javascript []\nfunction minimumSteps(s) {\n    let ans = 0;                // Variable to store the result\n    let black = [];             // Array to store indices of \'1\'s in the string\n    const n = s.length;         // Length of the input string \'s\'\n\n    // Iterate through the string \'s\' to find indices of \'1\'s\n    for (let i = 0; i < n; i++) {\n        if (s[i] === \'1\') {\n            black.push(i);      // Store index if the character is \'1\'\n        }\n    }\n\n    // Reverse the \'black\' array\n    black.reverse();\n\n    // Calculate the minimum steps required\n    for (let i = 0; i < black.length; i++) {\n        // For each \'1\', calculate steps needed to move it to the end\n        ans += (n - i - 1 - black[i]);\n    }\n\n    return ans; // Return the total minimum steps\n}\n\n\n```\n\n---\n\n\n\n# PLEASE UPVOTE IF IT HELPED\n\n---\n---\n\n\n---
['Bit Manipulation', 'C', 'C++', 'Java', 'Python3', 'JavaScript']