Skip to main content
All Questions

Climbing Stairs

Easy

Given an integer n, representing the number of steps in a staircase, write a function climbStairs that returns the number of distinct ways to climb to the top of the staircase. Each time you can either climb 1 step or 2 steps. You may assume that n is a non-negative integer.

Examples

Input: n = 1 Output: 1 Explanation: There is only 1 way to climb a staircase with 1 step. Input: n = 2 Output: 2 Explanation: There are 2 ways to climb a staircase with 2 steps: 1. Climb 1 step + 1 step 2. Climb 2 steps directly Input: n = 3 Output: 3 Explanation: There are 3 ways to climb a staircase with 3 steps: 1. Climb 1 step + 1 step + 1 step 2. Climb 1 step + 2 steps 3. Climb 2 steps + 1 step Input: n = 4 Output: 5 Explanation: There are 5 ways to climb a staircase with 4 steps: 1. Climb 1 step + 1 step + 1 step + 1 step 2. Climb 1 step + 1 step + 2 steps 3. Climb 1 step + 2 steps + 1 step 4. Climb 2 steps + 1 step + 1 step 5. Climb 2 steps + 2 steps

Interview experiences

5 shared
Google · 4 months ago
"It's pretty standard. Medium difficulty, nothing that is really surprising. For the domain interview, they also expect you to do a mini-design, but it was simple and brief."
Software Engineer · Senior / L5
Pinterest · 4 months ago
"Process was good. wish it was a bit quicker though it lasted a long time. try to get through final round as quick as possible since it takes a while afterwards to hear back"
Software Engineer · Senior / L5
F
Fresh Prep · 10 months ago
"The interview process for the Full Stack Developer role consisted of a take-home assessment followed by a final interview round. The take-home focused on practical software development and gave me an opportunity to demonstrate my coding approach, problem-solving skills, and ability to structure a solution independently. The final interview covered a mix of computer science fundamentals, technical problem-solving, and questions about my previous development experience. We discussed topics such as data structures and algorithms, object-oriented programming, databases, APIs, and general software engineering concepts. There were also questions about projects I had worked on and the technical decisions I made. Overall, the process was fairly well structured and provided a good balance between practical coding and theoretical knowledge. The interviewers were professional, and the final round allowed me to explain my reasoning and discuss my experience in more depth."
Software Engineer · Entry Level / L3
Salesforce · a year ago
"Went well, The interviewer has experience and the questions asked was more systematic aligned to the job posting and tweaked as per the resume submitted"
Software Engineer · Staff / L6
Walmart Labs · a year ago
"The interview process was well-structured and fairly rigorous compared to others I’ve experienced. I appreciated that the recruiter clearly communicated expectations upfront, which helped me prepare in the right direction. The technical rounds were challenging but relevant to the role, and the interviewers were professional and engaging."
Software Engineer · Mid Level / L4

Related courses

Course

Data Science Interview Prep

Land your dream data science role at Google, Amazon, Microsoft, Meta, Apple, and other top companies. Learn from mock interviews, frameworks, and advice from senior candidates. Practice statistics, experimentation, coding, SQL, machine learning, behavioral interviews, and more.

Course

Data Engineering Interview Prep

Land your dream data engineering role at Meta, Google, Amazon, Microsoft, Walmart, DoorDash, and other top companies. Learn from mock interviews, frameworks, and advice from senior candidates. Practice data modeling, pipeline design, SQL, coding, behavioral interviews, and more.