From ea2289a56cb24647902e8bf0bb0e2f9cb1f030ce Mon Sep 17 00:00:00 2001 From: chayan das <110921638+Chayandas07@users.noreply.github.com> Date: Wed, 19 Mar 2025 14:45:13 +0530 Subject: [PATCH] Create 3191. Minimum Operations to Make Binary Array Elements Equal to One I --- ...to Make Binary Array Elements Equal to One I | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 3191. Minimum Operations to Make Binary Array Elements Equal to One I diff --git a/3191. Minimum Operations to Make Binary Array Elements Equal to One I b/3191. Minimum Operations to Make Binary Array Elements Equal to One I new file mode 100644 index 0000000..981268b --- /dev/null +++ b/3191. Minimum Operations to Make Binary Array Elements Equal to One I @@ -0,0 +1,17 @@ +class Solution { +public: + int minOperations(vector& nums) { + int n = nums.size(); + int count = 0; + for( int x = 0 ; x < n-2 ; x++ ){ + if( nums[ x ] == 0 ){ + nums[ x ] = 1; + nums[ x+1 ] = 1 - nums[ x+1 ]; + nums[ x+2 ] = 1 - nums[ x+2 ]; + count++; + } + } + for( auto i : nums ) if( i == 0 ) return -1; + return count; + } +};