Interview Questions

  • View all interview questions
  • blank
  • Step-by-step solution for step counting using recursion
    A lecturer at Hack Reactor made this comment on Quora in response to a question about preparing for the Hack Reactor admission's challenge:
    One big thing that will help you: get intimately familiar with the concepts of recursion and JavaScript closures ... they will come up early in your interactions with Hack Reactor (and are just great things to understand in general).
    Below we'll cover a clever question that we'll solve using recursion. In a previous post we covered some questions regarding closures.


    You need to be a premium member to see the rest of this question and code.

    mrdaniel published this on 12/6/15 | javascript, bootcamp, recursion, Fullstack Academy, Hack Reactor, Google
  • +
  • 2
  • -
  • So when I was thinking about the problem, looking at 3 and 4 steps.. I was also able to arrive at Num_of_Ways = (n-1) + (n-2) This doesn't work when you arrive at 5 steps as it this equation would give 7 ways instead of 8. So how do you know to put the equation into recursion vs just having the above equation? Thank you!
  • +
  • 0
  • -
  • Wanted to post my solution as well. Adapted from the recursion example found in Eloquent JavaScript, Chapter 3:
    function stairCounter(stairs){
    	var count = 0;
    	var start = 0;
    	function find(start){
    		if(start === stairs){
    			count += 1
    		else if(start > stairs)
    			return null
    			return find(start + 2) || find(start + 1)
    	return count;
  • +
  • 0
  • -
  • Hope you like another way to solve it (Python):
    def steps(N):
        for i in range (3,N+1):
        return lst[N]
    Login to submit a comment