Count N-digit numbers whose adjacent digits have equal GCD
Given a positive integer N, the task is to find the number of all N-digit numbers whose adjacent digits have equal Greatest Common Divisor(GCD)....
read more
Minimum length of Run Length Encoding possible by removing at most K characters from a given string
Given a string S of length N, consisting of lowercase English alphabets only, the task is to find the minimum possible length of run-length-encoding that can be generated by removing at most K characters from the string S....
read more
Number of ways such that only K bars are visible from the left
Given a number K, and N bars of height from 1 to N, the task is to find the number of ways to arrange the N bars such that only K bars are visible from the left....
read more
Minimum cost to delete characters from String A to remove any subsequence as String B
Given two strings A and B of size N and M respectively, where B is a sub-sequence of A and an array arr[] of size N, where arr[i] is the cost to delete ith character from string A. The task is to find the minimum cost to delete characters from A such that after deletion no subsequence of A is the same as B....
read more
Count of Distinct Substrings occurring consecutively in a given String
Given a string str, the task is to find the number of distinct substrings that are placed consecutively in the given string....
read more
Print Longest Bitonic subsequence (Space Optimized Approach)
Given an array arr[] of size N, the task is to print the longest bitonic subsequence of the given array.Note: If more than one solution exit then prints anyone solution....
read more
Maximize score by multiplying elements of given Array with given multipliers
Given two arrays array[] and multipliers[] of size N and M where N is always greater than equal to M. There are M operations to be performed. In each operation, choose multiplier[i] and an element from the array arr[] either from the start or the end let’s say K then add multiplier[i]*K to the total score say ans and remove K from the array arr[]. The task is to find the maximum value of the final score ans....
read more
Maximize sum by selecting X different-indexed elements from three given arrays
Given three arrays A[], B[] and C[] of size N and three positive integers X, Y, and Z, the task is to find the maximum sum possible by selecting at most N array elements such that at most X elements are from the array A[], at most Y elements from the array B[], at most Z elements are from the array C[] and all elements are from different indices....
read more
What is memoization? A Complete tutorial
The term “Memoization” comes from the Latin word “memorandum” (to remember), which is commonly shortened to “memo” in American English, and which means “to transform the results of a function into something to remember.”....
read more
Length of longest subset consisting of A 0s and B 1s from an array of strings
Given an array arr[] consisting of N binary strings, and two integers A and B, the task is to find the length of the longest subset consisting of at most A 0s and B 1s....
read more
Count of ways to traverse a Matrix and return to origin in K steps
Given three integers N, M and K, where N and M are the dimensions of the matrix and K is the maximum possible steps, the task is to count the number ways to start from (0, 0) and return traversing the matrix by using K steps only. Note: In each step, one can move up, down, left, right, or stay at the current position. The answer could be large, so print the answer modulo 109 + 7Examples:...
read more
Count of ways to split a given number
Given a number N, the task is to find the count of unique ways to split it into different parts....
read more