Learn DSADSAContests
coding75 logo
LeetCode POTDPOTDSheets
coding75 Pro
coding75 logo
Dashboard
Learn DSA
Course RoadmapFlow
DSA Topic TreeNew 🚀
Contest SolutionsPractice
Practice Sheets
MasterclassesLive 👨🏻‍💻

coding75 ProPRO

Live Classes & Placement Guidance

coding75 logo

The premier developer platform for mastering Data Structures & Algorithms, exploring contest editorials, building ATS-ready resumes, and accelerating your tech career.

Connect & Community

DSA & Contests

  • Learn DSA
  • Contest Solutions
  • LeetCode POTDDaily
  • Practice Sheets
  • MasterclassesSoon

Interview Prep

  • Portfolio Projects
  • CS Fundamentals
  • System DesignSoon
  • Interview ExperiencesSoon
  • Mock InterviewsSoon

Career & Pro

  • Jobs & Internships
  • Resume BuilderATS
  • coding75 Pro
  • Submit Feedback
© 2026coding75•crackDSA™•Maa Lalita Edtech Private Limited. All Rights Reserved.
Privacy PolicyTerms & ConditionsContact Support
Registered Office: Kanpur 208021•Regional Office: Indiranagar, Bangalore, 560008
Maa Lalita Edtech Private Limited
Contests/LeetCode/Weekly Contest 398/3154. Find Number of Ways to Reach the K-th Stair
Prev
LeetCodeLeetCode
Hard
Weekly Contest 398

3154. Find Number of Ways to Reach the K-th Stair

Dynamic ProgrammingCombinatoricsNumber TheoryRecursionMath
Loading...
Solve on LeetCode

Problem Statement

Official algorithmic problem description and constraints.

Open on LeetCode

You are given a non-negative integer k. There exists a staircase with an infinite number of stairs, with the lowest stair numbered 0.

Alice has an integer jump, with an initial value of 0. She starts on stair 1 and wants to reach stair k using any number of operations. If she is on stair i, in one operation she can:

  • Go down to stair i - 1. This operation cannot be used consecutively or on stair 0.
  • Go up to stair i + 2jump. And then, jump becomes jump + 1.

Return the total number of ways Alice can reach stair k.

Note that it is possible that Alice reaches the stair k, and performs some operations to reach the stair k again.

 

Example 1:

Input: k = 0

Output: 2

Explanation:

The 2 possible ways of reaching stair 0 are:

  • Alice starts at stair 1.
  • Using an operation of the first type, she goes down 1 stair to reach stair 0.
  • Alice starts at stair 1.
  • Using an operation of the first type, she goes down 1 stair to reach stair 0.
  • Using an operation of the second type, she goes up 20 stairs to reach stair 1.
  • Using an operation of the first type, she goes down 1 stair to reach stair 0.

Example 2:

Input: k = 1

Output: 4

Explanation:

The 4 possible ways of reaching stair 1 are:

  • Alice starts at stair 1. Alice is at stair 1.
  • Alice starts at stair 1.
  • Using an operation of the first type, she goes down 1 stair to reach stair 0.
  • Using an operation of the second type, she goes up 20 stairs to reach stair 1.
  • Alice starts at stair 1.
  • Using an operation of the second type, she goes up 20 stairs to reach stair 2.
  • Using an operation of the first type, she goes down 1 stair to reach stair 1.
  • Alice starts at stair 1.
  • Using an operation of the first type, she goes down 1 stair to reach stair 0.
  • Using an operation of the second type, she goes up 20 stairs to reach stair 1.
  • Using an operation of the first type, she goes down 1 stair to reach stair 0.
  • Using an operation of the second type, she goes up 21 stairs to reach stair 2.
  • Using an operation of the first type, she goes down 1 stair to reach stair 1.

 

Constraints:

  • 0 <= k <= 109


Solutions & Walkthrough

Detailed video explanations, mathematical intuition, and clean C++ implementation code.

Connecting secure classroom stream...
Back to Weekly Contest 398
Previous Problem