• Skip to primary navigation
  • Skip to content
  • Skip to primary sidebar
  • Skip to secondary sidebar

GoHired

Interview Questions asked in Google, Microsoft, Amazon

Join WeekEnd Online Batch from 4-April-2020 on How to Crack Coding Interview in Just 10 Weeks : Fees just 20,000 INR

  • Home
  • Best Java Books
  • Algorithm
  • Internship
  • Certificates
  • About Us
  • Contact Us
  • Privacy Policy
  • Array
  • Stack
  • Queue
  • LinkedList
  • DP
  • Strings
  • Tree
  • Mathametical
  • Puzzles
  • Graph

‘N’ Story Building, with 1,2,3 steps how many ways can a person reach top of building.

April 13, 2015 by Dhaval Dave

A building has n steps. A person can take 1,2 or 3 steps. In how many ways can a person reach top of building.

In order to build logic, lets think from first step
If N=1 and Steps=1. There is only 1 way to reach with 1 step.
F(1)=1

If N=2 and Steps=1. There 1  way to reach with 1+1 step.
F(2)=1

if N=2 and Steps=1,2 . There are 2 ways to reach, with 1+1 & 0+2 steps.
F(2)=2
if N=3 and Steps=1,2 . There are 3 ways to reach, with 1+1+1 , 1+2 & 2+1 steps.
F(3)=3.


if N=4 and Steps=1,2 . There are 5 ways to reach, with 1+1+1+1 , 1+2+1 , 1+1+2 , 2+1+1  & 2+2 steps.
F(4)=5

So what is that function , does it look similar to fibonacchi series ?

F(n) = F(n-1) + F(n-2)

So Extend the same function for 3 steps

F(n) = F(n-1) + F(n-2) + F(n-3)

So code it

int main()
{
  int n, first = 0, second = 1, third=1, next, c;
  printf("Enter the number of terms\n");
  scanf("%d",&n);
  for ( c = 3; c < n ; c++ )
      {
       next = first + second + third;
       first = second;
       second = third;
       third = next ;
      }

  printf("Total Steps required =%d\n",next);
  return 0;
}

Similar Articles

Filed Under: Adobe Interview Questions, Amazon Interview Question, Microsoft Interview Questions, problem Tagged With: Dynamic Programming, Mathematical, Recursion

Reader Interactions

Primary Sidebar

Join WeekEnd Online/Offline Batch from 4-April-2020 on How to Crack Coding Interview in Just 10 Weeks : Fees just 20,000 INR

Join WeekEnd Online/Offline Batch from 4-April-2020

WhatsApp us

Secondary Sidebar

Custom Search

  • How I cracked AMAZON
  • LeetCode
  • Adobe
  • Amazon
  • Facebook
  • Microsoft
  • Hacker Earth
  • CSE Interview

Top Rated Questions

Find the smallest window in a string containing all characters of another string

Cisco Hiring Event 21st – 22nd Feb 2015

Urban Ladder Written Test.

SAP Off Campus Hiring_ March 2015 Computer Skills

Coin Collection Dynamic Programming

25 horses 5 tracks Find 3 fastest puzzle

TicTacToe Game As Asked in Flipkart

Closed Parentheses checker

Get Minimum element in O(1) from input numbers or Stack

Adobe Interview Questions 8 month Exp

Apriori algorithm C Code Data Mining

N Petrol bunks or City arranged in circle. You have Fuel and distance between petrol bunks. Is it possible to find starting point so that we can travel all Petrol Bunks

1014 Practice Question of New GRE – Princeton

Connect n ropes with minimum cost

Find the element that appears once others appears thrice

Puzzle : 100 doors in a row Visit and Toggle the door. What state the door will be after nth pass ?

System Design: Designing a LLD for Hotel Booking

Flipkart Set 1 On Campus with Answers

DFS (Depth First Search)

Word Break Problem

Microsoft BING Interview Experience

VMWare SDEII Interview

Length of the longest substring without repeating characters

Maximum path sum between two leaves

C Program for TAIL command of UNIX

robot standing at first cell of an M*N matrix. It can move only in two directions, right and down. In how many ways, it can reach to the last cell i.e. (M, N) Code it

Password Predictor

Generic Object Oriented Stack with Template

C++ OOPs Part2

Handle duplicates in Binary Search Tree

Copyright © 2025 · Genesis Framework · WordPress · Log in