Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Min Cost Climbing Steps

HardPython00:00
I
Practice interviewer
Your interviewer
In session
I
Interviewer

Welcome to the Python screen.

The question is on your right: Min Cost Climbing Steps. Read through the requirements first.

Run and submit your code as often as you need. You also have five interviewer messages this session - want to talk through your approach, or are you ready to start coding?

You need to log in / sign up to run or submit.

Problem

At Google, a checkout or navigation flow can be modeled as a staircase of steps with varying costs. Given an integer array cost, where cost[i] is the cost of stepping on stair i, return the minimum total cost needed to move beyond the final index.

You may start at index 0 or 1. From any stair, you may move forward by either 1 step or 2 steps. You pay the cost of every stair you land on, including the starting stair if you begin there.

Formal Specification

  • Input: A list of integers cost
  • Output: An integer, the minimum cost to reach beyond the last stair

Constraints

  • 2 <= len(cost) <= 10^4
  • 0 <= cost[i] <= 999
  • You may start at index 0 or 1
  • You may move forward by 1 or 2 steps at a time

Function Signature

def min_cost_climbing_stairs(cost):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output