Blogs Hub

by AskGif | Oct 15, 2020 | Category :coding

N-th Tribonacci Number - Recursion - Easy - LeetCode

N-th Tribonacci Number - Recursion - Easy - LeetCode

The Tribonacci sequence Tn is defined as follows:&nbsp; T0 = 0, T1 = 1, T2 = 1, and Tn+3 = Tn + Tn+1 + Tn+2 for n &gt;= 0. Given n, return the value of Tn. &nbsp; Example 1: Input: n = 4<br />Output: 4<br />Explanation:<br />T_3 = 0 + 1 + 1 = 2<br />T_4 = 1 + 1

read more...

by AskGif | Oct 03, 2020 | Category :coding

Range Sum Query - Immutable - Array - Easy - LeetCode

Range Sum Query - Immutable - Array - Easy - LeetCode

Given an integer array nums, find the sum of the elements between indices i and j (i &le; j), inclusive. Example: Given nums = [-2, 0, 3, -5, 2, -1] sumRange(0, 2) -&gt; 1<br />sumRange(2, 5) -&gt; -1<br />sumRange(0, 5) -&gt; -3<br />&nbsp; Constraints: You may

read more...

by AskGif | Oct 03, 2020 | Category :coding

House Robber - Array - Easy - LeetCode

House Robber - Array - Easy - LeetCode

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 system connected and it will automatically contact the police if two adjacent hou

read more...

by AskGif | Aug 29, 2020 | Category :coding

Longest Palindrome Subsequence - Dynamic Porgramming

Longest Palindrome Subsequence - Dynamic Porgramming

Given a string s, find the longest palindromic subsequence's length in s. You may assume that the maximum length of s is 1000. Example 1:<br />Input:<br />"bbbab"<br />Output:<br />4<br />One possible longest palindromic subsequence is "bbbb".<br />&nbsp;<br />Example 2:<br />Input:<br />"

read more...

by AskGif | Jul 31, 2018 | Category :coding

How to solve Longest Palindromic Subsequence Problem using dynamic programming?

How to solve Longest Palindromic Subsequence Problem using dynamic programming?

The longest palindromic subsequence (LPS) problem is the problem of finding the longest subsequence of a string (a subsequence is obtained by deleting some of the characters from a string without reordering the remaining characters) which is also a palindrome. In general, the longest palindromic

read more...

by AskGif | Jul 31, 2018 | Category :coding

How to solve Edit Distance Problem using dynamic programming?

How to solve Edit Distance Problem using dynamic programming?

In computational linguistics and computer science, edit distance is a way of quantifying how dissimilar two strings (e.g., words) are to one another by counting the minimum number of operations required to transform one string into the other. Edit distances find applications in natural language p

read more...

by AskGif | Jul 31, 2018 | Category :coding

How to Solve Coin Change Problem using Dynamic Programming for Minimum number of ways possible?

How to Solve Coin Change Problem using Dynamic Programming for Minimum number of ways possible?

Coin Change Problem is also known as Making Change Problem. The change-making problem, also known as the minimum coin change problem, addresses the question of finding the minimum number of coins (of certain denominations) that add up to a given amount of money. It is a knapsack type prob

read more...

by AskGif | Jul 31, 2018 | Category :coding

How to solve Knapsack problem using Dynamic Programming

How to solve Knapsack problem using Dynamic Programming

The knapsack problem or rucksack problem is a problem in combinatorial optimization: Given a set of items, each with a weight and a value, determine the number of each item to include in a collection so that the total weight is less than or equal to a given limit and the total value is as large a

read more...

by AskGif | Jul 30, 2018 | Category :coding

How to solve Matrix Product Parenthesizations problem?

How to solve Matrix Product Parenthesizations problem?

Matrix chain multiplication (or Matrix Chain Ordering Problem, MCOP) is an optimization problem that can be solved using dynamic programming. Given a sequence of matrices, the goal is to find the most efficient way to multiply these matrices. The problem is not actually to perform the multiplicat

read more...

by AskGif | Jul 30, 2018 | Category :coding

How to find Nth Number in Catalan Numbers?

How to find Nth Number in Catalan Numbers?

In combinatorial mathematics, the Catalan numbers form a sequence of natural numbers that occur in various counting problems, often involving recursively-defined objects. They are named after the Belgian mathematician Eug&egrave;ne Charles Catalan (1814&ndash;1894). The first Catalan numb

read more...

by AskGif | Jul 30, 2018 | Category :coding

How to Find Maximum Value Contiguous Subsequence?

How to Find Maximum Value Contiguous Subsequence?

The input to this problem is an array A[1...n] of real numbers. You need to find out what the highest value is that can be obtained by summing up all numbers of a contiguous subsequence A[i], A[i+1],...A[j] of A. If A does not contain negative numbers, the problem is trivial and can be solved by

read more...

by AskGif | Jul 30, 2018 | Category :coding

How to Find Longest Common Subsequence ?

How to Find Longest Common Subsequence ?

The longest common subsequence (LCS) problem is the problem of finding the longest subsequence common to all sequences in a set of sequences (often just two sequences). It differs from the longest common substring problem: unlike substrings, subsequences are not required to occupy consecutive pos

read more...