Problem Link: https://www.hackerrank.com/challenges/common-child
Summary:
Given 2 strings of equal length what's the longest string that can be constructed such that it is a child of both.
For example:
Sample Input 1:
HARRY
SALLY
Sample Output 1:
2
Longest possible string is "AY"
Sample Input 2:
ABCDEF
FBDAMN
Sample Output 2:
2
Longest possible string is "BD"
Topic:
Dynamic Programming Approach: https://en.wikipedia.org/wiki/Dynamic_programming
Longest String Subsequence: https://en.wikipedia.org/wiki/Longest_common_substring_problem
http://www.geeksforgeeks.org/longest-common-substring/
My Logic:
Let string str1 = HARRY and str2 = SALLY
So this is how i solved this question using DP(Dynamic Programming).
To view My Solution:
https://github.com/shivam04/hackerrank/blob/master/common-child.java
Summary:
Given 2 strings of equal length what's the longest string that can be constructed such that it is a child of both.
For example:
Sample Input 1:
HARRY
SALLY
Sample Output 1:
2
Longest possible string is "AY"
Sample Input 2:
ABCDEF
FBDAMN
Sample Output 2:
2
Longest possible string is "BD"
Topic:
Dynamic Programming Approach: https://en.wikipedia.org/wiki/Dynamic_programming
Longest String Subsequence: https://en.wikipedia.org/wiki/Longest_common_substring_problem
http://www.geeksforgeeks.org/longest-common-substring/
My Logic:
Let string str1 = HARRY and str2 = SALLY
So this is how i solved this question using DP(Dynamic Programming).
https://github.com/shivam04/hackerrank/blob/master/common-child.java
How do you get the notion of this, this is pretty simple yet glorious solution. I appreciate it.
ReplyDeleteThanks :)
DeleteNice yar..
ReplyDelete1 question, how this hard thoughts come to in ur mind? ;) :)
thanks :)
Deletewell when i study dp for the first time i found this question next day so i made this solution may be my mind is set for dp that time :p
Very nice
ReplyDeleteThanks :D
DeleteThis Code will fail for HARRY and SALLY test case and also for AA and BB
ReplyDelete