## Create a protocol to transmit numbers efficiently or Huffman coding puzzle

Problem statment There are two people on different sides of the bridge. The only way they can communicate is via Flash lights. One person wants to communicate the numbers, came up with roll of...

## increment an integer array by one

Problem Given an integer array, increment its numeric value by one. For example, increment([2, 7, 3]) returns [2, 7, 4] Solution

Solution

## hex to rgba conversion using javascript

Algorithm get two characters from the input string at a time and convert it to the integer For example let hex = ‘ff00ff’; let r = parseInt(hex.substring(0, 2), 16) // 255 concat all the...

## Use map to accept an additional argument in javascript

Problem Write a function Array.prototype.map() which can accept one additional argument. function mul(x) { return x * x; } console.log([1, 2, 3].map(mul)); // [1, 4, 9] Modify the function so that it can accept...

## Word break problem dynamic programming

Problem : Given a string and an array of words, find out if the input string can be bro­ken into a space-separated sequence of one or more words. For example, inputDict = [“I” ,...

## Generate all permutations of a given array using backtracking

A permutation is a rearrangement of the elements in a list. A string/array of length n has n! permutation. Input: An array // [‘A’, ‘B’, ‘C’] Output: [‘A’, ‘B’, ‘C’] [‘A’, ‘C’, ‘B’], [‘B’,...

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

## Find consecutive segments in an sorted array

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

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

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