Given N strings N <= 1000. The task is to choose a subsequence such that the concatenation of the chosen elements gives the maximum lexicographical string. For example N = 3, ["ab", "ac", "b"] answer = "b", N = 2 ["z", "za"] answer is "zza". How to solve this problem?
Hi stuck, I'm Ivan!
You should solve it backwards greedily. If $$$s$$$ is the solution for the last $$$k$$$ strings, then, for the last $$$k+1$$$ it's either $$$ps$$$ or $$$s$$$, where $$$p$$$ is the $$$k+1$$$-st string from the end.
Thanks step-coder!
Haha i guess "step" is important here!!
Hmm, CornHub's interface is looking rather weird today
What are you doing step-coder??
How is the answer for N=3, {"b", "ab", "ac"} "b", shouldn't it be "bacab". This is a greedy problem using sorting!
You can't change the order of the elements