https://online.codingblocks.com/player/10922/content/4738?s=1615 or https://hack.codingblocks.com/contests/c/262/103
code-https://ide.codingblocks.com/s/40963
I am getting stuck, have put in my doubts along with the code
pls help, thanks
https://online.codingblocks.com/player/10922/content/4738?s=1615 or https://hack.codingblocks.com/contests/c/262/103
code-https://ide.codingblocks.com/s/40963
I am getting stuck, have put in my doubts along with the code
pls help, thanks
You need to print longer before only when one is substring of other.
So, sort alphabetically in general, check for substring between two consecutive, if found substring then display the longer one before shorter one
yes, I tried ORing and ANDing both the conditions(if that’s what you mean to say), but it didn’t work
Basically check_substring func in my code shouldn’t work for 2 diff strings, even if it gets entered, but somehow diff strings are also getting compared and returning an answer, and that’s what messes the o/p
No there is no need of ORing and ANDing both the conditions
Simple approach to this question
First sort simply, which would give you lexicographically (dictionary ordered) array.
This would be containing shorter substring before the longer string.
So now compare consecutive elements and if there is substring of other, then swap them.
Hope this helps and solves your problem
There are three conditions here:
Condition should be such that:
Tip for conditions in comparator:
Condition should be such that it return true in cases when objects should NOT swap.
In our case, conditions will be a.length() > b.length()
or a < b
Happy coding
https://ide.codingblocks.com/s/41648
passed test cases, but is this approach fine, is there a better one?
Yes, it is correct and optimized.
Correct , but when strings are same , how can i campare consecutive, i think given test cases in question is very simple.