Learn DSADSAContests
coding75 logo
LeetCode POTDPOTDSheets
coding75 Pro
coding75 logo
Dashboard
Learn DSA
Course RoadmapFlow
DSA Topic TreeNew 🚀
Contest SolutionsPractice
Practice Sheets
MasterclassesLive 👨🏻‍💻

coding75 ProPRO

Live Classes & Placement Guidance

coding75 logo

The premier developer platform for mastering Data Structures & Algorithms, exploring contest editorials, building ATS-ready resumes, and accelerating your tech career.

Connect & Community

DSA & Contests

  • Learn DSA
  • Contest Solutions
  • LeetCode POTDDaily
  • Practice Sheets
  • MasterclassesSoon

Interview Prep

  • Portfolio Projects
  • CS Fundamentals
  • System DesignSoon
  • Interview ExperiencesSoon
  • Mock InterviewsSoon

Career & Pro

  • Jobs & Internships
  • Resume BuilderATS
  • coding75 Pro
  • Submit Feedback
© 2026coding75•crackDSA™•Maa Lalita Edtech Private Limited. All Rights Reserved.
Privacy PolicyTerms & ConditionsContact Support
Registered Office: Kanpur 208021•Regional Office: Indiranagar, Bangalore, 560008
Maa Lalita Edtech Private Limited
Contests/CodeChef/Starters 207/Make Subarray
PrevNext
CodeChefCodeChef
3 Star
Starters 207

Make Subarray

MathString
Loading...
Solve on CodeChef

Problem Statement

Official algorithmic problem description and constraints.

Open on CodeChef

There is a canvas with N


N total cells, and each cell can be painted white or black. Currently, the state of the board can be represented by a binary string S


S, where Si=1


Si

​=1 if and only if the i


i-th call in the canvas is painted black, and Si=0


Si

​=0 otherwise.


You want the black cells to form a contiguous subarray, i.e. if cell x


x and cell y


y are coloured black, then all cells z


z between the 2


2 must also be black. Note that if there are no black cells, this condition is satisfied.

You can only change the colour of a cell from white to black (but not the other way around). Find the minimum number of changes needed.

Input Format

  • The first line of input will contain a single integer T

  • T, denoting the number of test cases.
  • Each test case consists of multiple lines of input.
  • The first line of each test case contains N

  • N - the number of cells.
  • The second line contains S

  • S - a binary string of size N

  • N.

Output Format

For each test case, output on a new line the minimum number of cells that need to be changed from white to black, such that the black cells form a contiguous subarray.

Constraints

  • 1≤T≤100

  • 1≤T≤100
  • 1≤N≤100

  • 1≤N≤100
  • Si∈{0,1}

  • Si
  • ​∈{0,1}

Sample 1:

Input


Output


4 2 00 3 101 4 0110 10 0100010011
0 1 0 5

Explanation:

Test Case 1 : There are no black cells, so the condition is satisfied.

Test Case 2 : We can colour the 2nd


2nd

 cell, and now the condition is satisfied.

Solutions & Walkthrough

Detailed video explanations, mathematical intuition, and clean C++ implementation code.

Connecting secure classroom stream...
Back to Starters 207
Previous ProblemNext Problem