Posts

Showing posts from July, 2020

Coding Problem 2

                Decode number to string                                                     asked by facebook Ques. Given any number you have to find the number of ways to decode the number like if you are given the number 12 then it can be decode as "ab" where a=1 and b=2 and "l" where l=12 so the total number of ways to decoed 12 is 2 as "ab" and "l".  Solution. We can map our alphabets to the number from 1 to 26. If we have empty string or a single digit number then we can have only one way to decode it but for two or more than 2 digit numbe we have to check each number plus the pair of numbers. Now here we can simplify it as we can have number from 0 to 9 and we have to check only those pair of numbers which are less than 27 as we have 26 alphabets only.  Suppose we have input as "4" then we can decode it...

Coding Problem 1

      Number of Ways to Climb the Stairs                                                        asked by Amazon Ques. There is a Staircase with N steps, and you can climb only certain number of steps at a time given in the list. Write the function which can return the total number of unique ways to climb the staircase using only given number of steps.  For example - If N = 4, and X = [1, 2] then there are 5 ways to climb the stair.                              1st way = 1, 1, 1, 1                              2nd way = 2, 1, 1                              3rd way = 1, 2, 1 ...