# Monthly Archive: November 2015

## Pascals triangle javascript code

Problem : Create a pascal’s triangle using javascript. More details about Pascal’s triangle pattern can be found here. Input: #Rows = 6 Output: Logic : Pascal’s triangle can be simulated using 2-D array While...

## Flatten nested array javascript

Problem : Given a nested array, flatten the given array. Input : [1, 2, 3, [4, 5], [6, [7, 8]]] Output : [1, 2, 3, 4, 5, 6, 7, 8] Logic : Iterate throgh...

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

## Replace all spaces in a string with %20

The solution is self explanatory. Solution :

## Justify if a string consists of valid parentheses

You are given an array of strings. Each of these strings is made up of bracket characters only : ‘(‘, ‘)’, ‘{‘,  ‘}’,  ‘[‘,  ‘]’. Programming languages utilize these brackets in balanced pairs, so...

## Negate a number using addition operator

Problem: Given a number X, flip it to -X. Time complexity : O ( X ) Logic : The negation can be implemented by adding -1, X times. Solution :

## Find a pair of elements from an array whose sum equals a given number

Input: An array of n integers and given a number X. Expected output: All the unique pairs of elements (a, b), whose summation is equal to X. Example <pre>Given<span class=”pl-k”>var</span> unSortedArr <span class=”pl-k”>=</span> [<span...