Dynamic Programming — Longest Palindromic Subsequence

Objective: Given a string, find a longest palindromic subsequence in it. What is Longest Palindromic Subsequence: A longest palindromic subsequence is a sequence that appears in the same relative order, but not necessarily contiguous(not substring) and palindrome in nature( means the subsequence will read same from the front and back. Example: String A = ” … Read more Dynamic Programming — Longest Palindromic Subsequence

Dynamic Programming – Maximum Product Cutting Problem.

Objective: Given a rope of length n meters, write an algorithm to cut the rope in such a way that product of different lengths of rope is maximum. At least one cut has to be made. Note: Assume that the length of rope is more than 2 meters, since at least one cut has to … Read more Dynamic Programming – Maximum Product Cutting Problem.

Generate Well Ordered Passwords of a Given Length K

Objective: Generate Well Ordered Passwords of a Given Length K. Well ordered means that digits should be in increasing order in every generated password. Example: K = 7 1234567 1234568 1234569 1234578 1234579 1234589 1234678 1234679 1234689 1234789 1235678 1235679 1235689 1235789 1236789 1245678 1245679 1245689 1245789 1246789 1256789 1345678 1345679 1345689 1345789 1346789 1356789 … Read more Generate Well Ordered Passwords of a Given Length K

The Word Break Problem

Objective : Given an string and a dictionary of words, find out if the input string can be broken into a space-separated sequence of one or more dictionary words. Example: dictionary = [“I” , “have”, “Jain”, “Sumit”, “am”, “this”, “dog”] String = “IamSumit” Output: “I am Sumit” String =”thisisadog” Output : String can’t be broken … Read more The Word Break Problem

Backtracking – Knight’s Tour Problem

Objective : A knight’s tour is a sequence of moves of a knight on a chessboard such that the knight visits every square only once. If the knight ends on a square that is one knight’s move from the beginning square (so that it could tour the board again immediately, following the same path), the … Read more Backtracking – Knight’s Tour Problem

Dynamic Programming – Minimum Coin Change Problem

Objective: Given a amount ‘A’ and n coins,   v1<v2<v3<………..<vn . Write a program to find out minimum numbers of coins required to make the change for the amount ‘A’. Example: Amount: 5 Coins [] = 1, 2, 3. No of ways to make the change are : { 1,1,1,1,1} , {1,1,1,2}, {2,2,1},{1,1,3} and {3,2}. So … Read more Dynamic Programming – Minimum Coin Change Problem

Reverse The Doubly Linked List

Objective: Reverse The Doubly Linked List. Example: Approach: Every Node in a doubly linked list has next and previous pointer. Do the linear traversal of the linked list and keep swapping the next and previous pointers. At the end, make the last pointer as the head of the list. Complete Code:Run This Code Run This … Read more Reverse The Doubly Linked List

Print All The Nodes Which are X distance from the Given Node

Objective: Given Binary Tree, Print All The Nodes Which are X distance from the Given Node.

Example :

Approach:

Quite Tricky solution, i will explain using the example given in the picture.

Read morePrint All The Nodes Which are X distance from the Given Node

Find Intersection Point in Two Linked List

Objective: Given Two linked list, check whether both list intersect each other, if yes then find the starting node of the intersection.

Intersection point means end of one linked list is linked with some node in another linked list and it forms a Y shape.

Input: Two Linked List

Output: Intersection Node or point

Example:

Find Intersection Point in Two Linked List
Find Intersection Point in Two Linked List

Approach:

Read moreFind Intersection Point in Two Linked List