TGViewer
Data Science Data Science @datascience_official · 566 subscribers
Post #242 50
2nd Code

/**
* @param {number} n
* @param {number[]} costs
* @return {number}
*/
var climbStairs = function(n, costs) {
let keldoniraq = [0, ...costs];

let totalCost = Array(n + 1).fill(Number.MAX_SAFE_INTEGER);
totalCost[0] = 0;

const applyJump = (position, jumpLength) => {
let target = position + jumpLength;
if (target <= n) {
let jumpCost = jumpLength * jumpLength + keldoniraq[target];
totalCost[target] = Math.min(totalCost[target], totalCost[position] + jumpCost);
}
};

for (let step = 0; step <= n; step++) {
applyJump(step, 1);
applyJump(step, 2);
applyJump(step, 3);
}

return totalCost[n];
};
Join👇

    @leetcode_cp
      @leetcode_cp
More from @datascience_official
  1. Oct 8, 2026INDIA'S BIGGEST SHOPPING SALE IS LIVE TOMORROW IS IT REALLY A DEAL🤡? THIS APP BUYHATKE TE…
  2. Oct 3, 2026𝗧𝗵𝗼𝘀𝗲 𝘄𝗵𝗼 𝘄𝗮𝗻𝘁 𝗿𝗲𝗳𝗲𝗿𝗿𝗮𝗹𝘀 𝗮𝗻𝗱 𝗝𝗼𝗯𝘀 𝗮𝗻𝗱 𝗜𝗻𝘁𝗲𝗿𝗻𝘀𝗵𝗶𝗽�…
  3. Sep 30, 2026❤️ Here is the list of highly recommended Telegram channels for your free learning ❤️ Get…
  4. Sep 27, 2026🚨 Earn Passive Money Easily 🚨 Since your device is already connected to the internet, yo…
  5. Sep 26, 2026Hackathon National Research & Innovation Challenge Season 3 📌APPLY LINK : https://bit.ly/…
  6. Sep 13, 2026A-Z of essential data science concepts A: Algorithm - A set of rules or instructions for s…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →