## 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...

Skip to content# Monthly Archive: October 2015

## Generate all combinations of an array

## Implement a power function

## Determine given a pattern and string are isomorphic

## Determine if given strings are isomorphic

## Find consecutive segments in an sorted array

## Rearrange characters in a string so that no character repeats consecutively.

## Withdraw all money from bank account

## Print half pyramids using * as shown

## Create a minimal height binary search tree from given sorted array of unique integers

## Determine if a binary tree is balanced

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

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...

Problem : Given a pattern and a string str, find if str follows the same pattern. Here follow means a full match, such that there is a bijection between a letter in pattern and...

Problem : Given two (dictionary) words as Strings, determine if they are isomorphic. Two words are called isomorphic if the letters in one word can be remapped to get the second word. Remapping a...

Problem : Number list compressing. Given an sorted array. Input: sorted number list [ 1, 2, 3,10, 25, 26, 30, 31, 32, 33] Output: find consecutive segments print: 1-3, 10, 25-26, 30-33 Logic :...

Below are some of the test strings with their expected output. Input: aaabc Output: abaca Input: aa Output: No valid output Input: aaaabc Output: No valid output Logic : Create frequency map of the...

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...

Pattern 1 : * ** *** **** ***** Logic : i height Number of * (= i) 1 5 1 2 5 2 3 5 3 4 5 4 5 5 5 Solution :...

Problem description : Given a sorted (increasing order) array with unique integer elements, create a binary search tree (BST) with minimal height. Input : A sorted array with unique integer elements // [0, 1,...

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...