Apr 232017
 

Given a character matrix in which some of the cells have alphabets written on them while other cells are empty (empty cells contains character ‘-‘ in them). For example consider the below matrix:

A - -
- B -
- - C

All characters are unique. Set character on all empty cells in such a way that if we draw border around all cells of same characters, we get a rectangle. One of the solution for the above matrix is:

There can be multiple solutions possible for a given input matrix. Write code to print one of the possible solutions. Continue reading »

Apr 092017
 

Given a string of bits and a number k. In one flip, you can toggle k consecutive characters, how many flips are required to change the entire string to all ones. For example

Input String: 0000110000 
k: 3
OUTPUT: 4

Following are the four flips:

FLIP-1: 1110110000
FLIP-2: 1110110111
FLIP-3: 1111000111
FLIP-4: 1111111111

If it is not possible to set all bits in the string then return -1. For example:

Input String: 01010101 
k: 3
OUTPUT: -1

Continue reading »