This is a famous interview question asked in Google, Paytm and many other company interviews. Below is the problem statement.

Read More »There are N stations on route of a train. The train goes from station 0 to N-1. The ticket cost for all pair of stations (i, j) is given where j is greater than i. Find the minimum cost to reach the destination.

Read More »## Vertex Cover Problem | Set 2 (Dynamic Programming Solution for Tree)

Leave a comment | Filed under TreesA vertex cover of an undirected graph is a subset of its vertices such that for every edge (u, v) of the graph, either ‘u’ or ‘v’ is in vertex cover.

Read More »Consider a game where a player can score 3 or 5 or 10 points in a move. Given a total score n, find number of ways to reach the given score.

Read More »Given N jobs where every job is represented by following three elements of it. 1) Start Time 2) Finish Time. 3) Profit or Value Associated.

Read More »## Longest Even Length Substring such that Sum of First and Second Half is same

Leave a comment | Filed under StringsGiven a string ‘str’ of digits, find length of the longest substring of ‘str’, such that the length of the substring is 2k digits and sum of left k digits is equal to the sum of right k digits.

Read More »A triangulation of a convex polygon is formed by drawing diagonals between non-adjacent vertices (corners) such that the diagonals never intersect.

Read More »Given the mobile numeric keypad. You can only press buttons that are up, left, right or down to the current button. You are not allowed to press bottom row corner buttons (i.e. * and # ).

Read More »## Shortest path with exactly k edges in a directed and weighted graph

Leave a comment | Filed under GraphGiven a directed and two vertices ‘u’ and ‘v’ in it, find shortest path from ‘u’ to ‘v’ with exactly k edges on the path.

Read More »## Count all possible walks from a source to a destination with exactly k edges

Leave a comment | Filed under GraphGiven a directed graph and two vertices ‘u’ and ‘v’ in it, count all possible walks from ‘u’ to ‘v’ with exactly k edges on the walk.

Read More »Let 1 represent ‘A’, 2 represents ‘B’, etc. Given a digit sequence, count the number of possible decodings of the given digit sequence.

Read More »Given a positive integer N, count all possible distinct binary strings of length N such that there are no consecutive 1’s.

Read More »Catalan numbers are a sequence of natural numbers that occurs in many interesting counting problems like following.

Read More »## Remove minimum elements from either side such that 2*min becomes more than max

Leave a comment | Filed under ArraysGiven an unsorted array, trim the array such that twice of minimum is greater than maximum in the trimmed array. Elements should be removed either end of the array.

Read More »