Pages

Wednesday, 30 August 2017

InterviewBit : Dynamic Programming : Arrange II

Problem

You are given a sequence of black and white horses, and a set of K stables numbered 1 to K. You have to accommodate the horses into the stables in such a way that the following conditions are satisfied:
  • You fill the horses into the stables preserving the relative order of horses. For instance, you cannot put horse 1 into stable 2 and horse 2 into stable 1. You have to preserve the ordering of the horses.
  • No stable should be empty and no horse should be left unaccommodated.
  • Take the product (number of white horses * number of black horses) for each stable and take the sum of all these products. This value should be the minimum among all possible accommodation arrangements. 

Input 
string A = WWWB 
int K = 2

Output 
0

Saturday, 19 August 2017

How to send mass emails from Gmail account

This post explains how to send mass emails using google spreadsheet and a simple google script from your gmail account.












Sunday, 4 June 2017

Form a palindrome

Solution of geeksforgeeks problem.
http://practice.geeksforgeeks.org/problems/form-a-palindrome/0

Problem:
Given a string, find the minimum number of characters to be inserted to convert it to palindrome.

For Example:
ab: Number of insertions required is 1. bab or aba
aa: Number of insertions required is 0. aa
abcd: Number of insertions required is 3. dcbabcd

Preorder to Postorder

Recursive solution to a problem of geeksforgeeks.
http://practice.geeksforgeeks.org/problems/preorder-to-postorder/0

Problem:
Given an array representing preorder traversal of BST, print its postorder traversal.