Posts

Showing posts from May, 2013

Number System Conversion

Convert numbers between decimal, binary, octal, hexadecimal or any other number within base 2 and 36.

Interview Question

Problem: For a given pyramid find out the largest possible sum of numbers while travelling down from the top. ======================================================================== EXAMPLE 1: 1 2 3 4 5 6 The possible routes going down on this pyramid would be 1+2+4 1+2+5 1+3+5 1+3+6 ANS: 10 ======================================================================== EXAMPLE 2: 1 2 3 4 5 6 7 8 9 1 The possible routes going down on this pyramid would be 1+2+4+7 1+2+4+8 1+2+5+8 1+2+5+9 1+3+5+8 1+3+5+9 1+3+6+9 1+3+6+1 ANS: 19 Solution in Python: #!/usr/bin/env python # -*- coding: utf-8 -*- def findMaxHeight(items,pyramidHeight):     '''     This def returns the greatest path.     Logic:  From second last line for each element find if its left or right child is greatest.             Replace that element with sum of that eleme...