Posts

Showing posts from April 4, 2021

Zero Insert After K Times One

 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...

Keyboard Switch Count

 Keyboard Switch Count  PROBLEM STATEMENT : There are three rows in a keyboard containing the alphabets. The alphabets in each row are given as the input. The string S containing the alphabets to be typed is passed as the input. The program must print the number of times, the switch must happen to type the alphabets. Assume initially the position is in the middle row.  Note: Assume S contains only lower case alphabets and no special characters will be present in S.  Boundary Condition(s):   1 <= Length of S <= 100  Input Format:   The first three lines contain the alphabets in the three rows of a keyboard.  The fourth line contains S.  Outupt Format:   The first line contains an integer representing the switch count.  Example Input/Output 1: Input: ( ) qwertyuiop asdfghjkl zxcvbnm coding Output: 8 Explanation:  The string to be typed is coding.  c - bottom row. Hence switch count is 1.  o - top row. ...