Category Archives: Dynamic Programming

Number of palindromic paths in a matrix

Given a matrix containing lower alphabetical characters only, we need to count number of palindromic paths in given matrix. A path is defined as a sequence of cells starting from top-left cell and ending at bottom-right cell. We are allowed to move to right and down only from current cell. Examples: Input : mat[][] =… Read More »

Count All Palindrome Sub-Strings in a String

Given a string, the task is to count all palindrome substring in a given string. Length of palindrome substring is greater then or equal to 2. Examples: Input : str = “abaab” Output: 3 Explanation : All palindrome substring are : “aba” , “aa” , “baab” Input : str = “abbaeae” Output: 4 Explanation :… Read More »

Maximum sum alternating subsequence

Given an array, the task is to find sum of maximum sum alternating subsequence starting with first element. Here alternating sequence means first decreasing, then increasing, then decreasing, … For example 10, 5, 14, 3 is an alternating sequence. Note that the reverse type of sequence (increasing – decreasing – increasing -…) is not considered… Read More »

Path with maximum average value

Given a square matrix of size N*N, where each cell is associated with a specific cost. A path is defined as a specific sequence of cells which starts from top left cell move only right or down and ends on bottom right cell. We want to find a path with maximum average over all existing… Read More »