+ Reply to Thread
Results 1 to 2 of 2

Dynamic Programming

  1. #1
    Registered User
    Join Date
    05-19-2020
    Location
    Bangalore
    MS-Off Ver
    2019
    Posts
    1

    Dynamic Programming

    Hi everyone,

    Any coders out here, who have good knowledge on Dynamic programming?

    Spent quite a few hours trying to solve this problem. Can someone help me as to how to approach this problem from Interviewbit?


    Q) You are climbing a stair case and it takes A steps to reach to the top.

    Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?

    Input Format:
    The first and the only argument contains an integer A, the number of steps.

    Output Format:
    Return an integer, representing the number of ways to reach the top.

    Constrains:
    1 <= A <= 36

    Example :

    Input 1:
    A = 2 Output 1:

    2 Explanation 1:

    [1, 1], [2] Input 2:

    A = 3 Output 2:

    3 Explanation 2:

    [1 1 1], [1 2], [2 1]



    Thanks..!

  2. #2
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,863

    Re: Dynamic Programming

    I'm not sure what you mean by dynamic programming, but the result (if you only want to calculate the number of ways will be (A+1) Fibonacci number (see for instance https://en.wikipedia.org/wiki/Fibonacci_number )
    So to calculate the number its enough to use for instance such code:

    Please Login or Register  to view this content.
    The Fibonacci numbers grow quite rapidly (not like factorial, but still :-)) so with 36 steps you will have 24+ millions possible distinct ways. How do you plan to list them in excel sheet?

    And here is the recursive method to list the ways (I limited the number of listed to some 40K+ - 23 steps max). If more is needed other way of presenting than simple transposing of an array would be needed. See the Module1 code in attached workbook with :
    Please Login or Register  to view this content.
    Enjoy! (or adopt to your needs)
    Attached Files Attached Files
    Best Regards,

    Kaper

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Populate Dynamic Array from Cell Values and write to Dynamic Range
    By TFiske in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-22-2018, 09:09 AM
  2. How to use Solver & Dynamic Programming to solve this problem?
    By brooklyn12 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-26-2013, 03:45 PM
  3. Dynamic referencing pivot table and VBA programming
    By browntofu in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-09-2013, 01:59 AM
  4. Consolidation of vba programming and dynamic update
    By ferrum_equitis in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-01-2012, 04:02 AM
  5. Programming a Dynamic Web Query
    By pzorner in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-19-2011, 07:06 PM
  6. Dynamic programming in Excel
    By Makafi in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-07-2006, 11:08 AM
  7. Programming for a Dynamic 'Where' clause
    By ACase in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-29-2005, 03:05 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1