Zero Insert After K Times One PROBLEM STATEMENT : Given a bitstream of length N consisting of 0s and 1s, insert 0 after 1 has appeared K times consecutively. Input Format: The first line contains N and K separated by a space. The second line contains the bitstream with 1s and 0s with each value separated by a space. Output Format: In the first line, the bitstream with the 0 inserted after 1s has appeared K times with each value separated by a space. Boundary Conditions: 1 <= K <= 1000 2 <= N <= 1000 Example Input/Output 1: Input: ( ) 12 2 1 0 1 1 0 1 1 0 1 1 1 1 Output: 1 0 1 1 0 0 1 1 0 0 1 1 0 1 1 0 SOLUTION : C (Programming Language) Copy Code #include<stdio.h> #include<stdlib.h> int main() { int n,k,cnt=0,i,j,a[2002]; scanf("%d%d",&n,&k); for(i=0;i<n;++i) { scanf("%d",&a[i]); } //Count of 1 in first step for(i=0;i<k;++i...
Comments
Post a Comment