Subsequence Equality
Hey guys, This problem I have taken from www.codechef.com to speed up our coding practice skills and now regularly add a new problem with its solution to clear our Java concept and sharp our logical skills. Problem : Chef Tobby is playing a rapid fire with Bhuvan. He gives Bhuvan a string S and each time, Bhuvan has to guess whether there exists 2 equal subsequences in the string or not. Bhuvan got a perfect score in the game with Chef Tobby. However, Chef Tobby has now asked Bhuvan to write a program that will do this automatically given a string S . Bhuvan is an intelligent man but he does not know how to write a code. Can you help him? Find two different subsequences such that they are equal in their value, more formally, find two sequences of indices (a 1 , a 2 , ..., a k-1 , a k ) and (b 1 , b 2 , ..., b k-1 , b k ) such that: 1≤ a i , b i ≤ |S| a i < a i+1 for all valid i b i < b i+1 ...