Leetcode 0338. Counting Bits

Posted on Tue 17 December 2024 in Leetcode • Tagged with bits, dp

Question Link : https://leetcode.com/problems/counting-bits/

Difficulty: Easy

Premium: False

Question

Given an integer n, return an array ans of length n + 1 such that for each i (0 <= i <= n), ans[i] is the number of 1's in the binary representation of i.   Example 1:

Input: n = 2 …


Continue reading

Leetcode 0494. Target Sum

Posted on Sun 24 November 2024 in Leetcode • Tagged with backtracking, dp, knapsack-1-0

Question Link : https://leetcode.com/problems/target-sum/

Difficulty: Medium

Premium: False

Question

You are given an integer array nums and an integer target. You want to build an expression out of nums by adding one of the symbols '+' and '-' before each integer in nums and then concatenate all the integers …


Continue reading

Leetcode 0983. Minimum Cost For Tickets

Posted on Mon 27 March 2023 in Leetcode • Tagged with dp, knapsack-unbounded

Question Link : https://leetcode.com/problems/minimum-cost-for-tickets/

Difficulty: Medium

Premium: False

Question

You have planned some train traveling one year in advance. The days of the year in which you will travel are given as an integer array days. Each day is an integer from 1 to 365. Train tickets …


Continue reading

Leetcode 0064. Minimum Path Sum

Posted on Sun 26 March 2023 in Leetcode • Tagged with dp-2d, dp

Question Link : https://leetcode.com/problems/minimum-path-sum/

Difficulty: Medium

Premium: False

Question

Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right, which minimizes the sum of all numbers along its path. Note: You can only move either down or right …


Continue reading

Leetcode 0198. House Robber

Posted on Tue 13 December 2022 in Leetcode • Tagged with dp

Question Link : https://leetcode.com/problems/house-robber/

Difficulty: Medium

Premium: False

Question

You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent houses have security systems …


Continue reading

Leetcode 0070. Climbing Stairs

Posted on Sun 09 October 2022 in Leetcode • Tagged with dp

Question Link : https://leetcode.com/problems/climbing-stairs/

Difficulty: Easy

Question

You are climbing a staircase. It takes n steps to reach the top. Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?   Example 1:

Input: n = 2 Output …


Continue reading

Leetcode 0746. Min Cost Climbing Stairs

Posted on Mon 11 July 2022 in Leetcode • Tagged with dp

Question Link : https://leetcode.com/problems/min-cost-climbing-stairs/

Difficulty: Easy

Question

You are given an integer array cost where cost[i] is the cost of ith step on a staircase. Once you pay the cost, you can either climb one or two steps. You can either start from the step with …


Continue reading

Leetcode 0740. Delete and Earn

Posted on Fri 04 March 2022 in Leetcode • Tagged with dp

Question Link : https://leetcode.com/problems/delete-and-earn/

Difficulty: Medium

Question

You are given an integer array nums. You want to maximize the number of points you get by performing the following operation any number of times:

Pick any nums[i] and delete it to earn nums[i] points. Afterwards, you …


Continue reading

Leetcode 0413. Arithmetic Slices

Posted on Wed 02 March 2022 in Leetcode • Tagged with dp

Question Link : https://leetcode.com/problems/arithmetic-slices/

Difficulty: Medium

Question

An integer array is called arithmetic if it consists of at least three elements and if the difference between any two consecutive elements is the same.

For example, [1,3,5,7,9], [7,7,7,7], and [3,-1 …


Continue reading