## Count number of equal pairs in a String in C++

Here we will first understand how to count number of equal pairs in a String using two methods, then we will write a C++ programs to implement these solutions. Given: A string s Problem: To find the number of equal pairs in the string s. Note: Pairs (s[i], s[j]), (s[j], s[i]), (s[i], s[i]), (s[j], s[j]) should be … Read more

## Number of substrings of binary string containing K ones

In this post we will write a program in C++ to count the number of substrings of a binary string containing K ones, first we will discuss the problem with examples and then implement the solution in C++. Given: A binary string of length N and an integer K. Problem: Find out how many substrings of the given … Read more

## Maximum points from top left to bottom right of Matrix

Given: Matrix of size MxN, consists of ‘#’, ‘.’ and ‘*’, where: # means blocked path . means walkable path * means points to collect. Problem: To find the maximum points you can grab to reach bottom right of the matrix from top left. Consider you are at the top left of the matrix, you have … Read more

## Highway Billboard Problem: Dynamic Programming

In this post we will understand the problem of Highway Billboard Problem and then we will implement the solution using Dynamic Programming. Problem: Let’s suppose we got a job to place billboards (advertising hoarding) on a National Highway of length M miles. The possible site for billboards are given by numbers x1 < x2 < ….. < … Read more

## Find length of the longest sub-sequence in C++

In this post first we are going to understand the problem to find the length of longest sub-sequence of an array and then we will write a C++ program to implement the same. Let’s understand the problem first: Given: An array arr[ ] of N integers. Problem: To find the length of the longest subsequence … Read more

## Implement K stacks in single Array C++

Here first we are going to understand the problem of how to efficiently implement K Stacks in a single array, then we will discuss a solution and then finally we can implement the same in C++. Implement K Queues in single Array in C++ Problem: Create a data structure kStacks that represents k stacks. Implementation … Read more