Friday, June 26, 2015

Friend Circle - Hackerrank

Problem Reference - Hackerrank This updated information has been further expanded upon on my new website. You can find the updated details here: https://k5kc.com/cs/problems/number-of-provinces/. Problem There are N students in a class. Some of them are friends, while some are not. Their friendship is transitive in nature, i.e., if A is friend of B and B is friend of C, then A is also friend of C. A friend circle is a group of students who are directly or indirectly friends. You are given a N×N−matrix M which consists of characters Y...

Wednesday, June 10, 2015

Lazy Caterer's sequence

This updated information has been further expanded upon on my new website. You can find the updated details here: https://k5kc.com/cs/problems/lazy-caterer-s-sequence/. Problem Given a circular (or regular polygon) cake and a knife by which you can only cut vertically, find the maximum number of pieces of cake you can get by making n cuts. Write a program to do that. Solution The solution to this is very simple, if you know mathematics. :P Number of pieces p p = ( n^2+n+2)/2 p = C(n+1,2) + 1   More on wikipedia - http://en.wikipedia.org/wiki/Lazy_caterer%27s_sequence. Proof When...

Tuesday, June 2, 2015

Lego Blocks Problem

Problem statement - https://www.hackerrank.com/challenges/lego-blocks solution - http://stackoverflow.com/questions/15424945/lego-blocks-dynamic-programming http://stackoverflow.com/questions/913566/has-anyone-seen-a-programming-puzzle-similar-to-this Code - Thank...