Monthly Archive: October 2015

0

Generate all combinations of an array

  Input : [ 1, 2, 3 ]   Output : [  ‘ ‘,  1,  2,  12,  3,  13,  23,  123  ]   Logic : There are 2^n possible combinations for the array of...

0

Implement a power function

Naive logic: Loop through the number of times the exponent, and during each iteration multiply the base If our exponent is 10,000 then our loop has to run 10,000 times. But we can optimize...

0

Withdraw all money from bank account

Problem : You have some money in your bank account, the only function to withdraw money is Withdraw(value), if the value is greater than the money you have it returns 0, otherwise it withdraws...

0

Determine if a binary tree is balanced

A balanced tree is defined to be a tree such that the heights of the two subtrees of any node never differ more than one. Input : The root of a binary tree Output...