You are given an array of strings A of size N. You need to pick two strings Ai and Aj such that len(Ai)* len(Aj) is maximized. Thanks in advance. Edit : Sry, forgot to add the constraints : there was a condition stating those two strings should have no common characters, then what would be the optimal solution ?
You can't do that in less than O($$$\text{total length of all strings}$$$) since you need to read the strings.
I don't think there is any more optimal way than this?
Correct idea, but the code is wrong. You forgot to test if the length of a given string is smaller than the largest but larger than the second largest.
thanks, my bad. Updated the code.
Could you please tell the optimal approach for the modified question?
can you please tell what are the constraints on the length of the array of strings?
That was was asked in test, i forgot the constraints but i tried brute force solution and got tle. My solution is n*n*n, so i was thinking what would be the optimized approach
I guess, you can use bitmasking for this approach, wait lemme write it with the code.
TC: O((n * m) + (n * n)), where*m is length of maximum length string, n is count of strings.
SC: O(n), pair to store length and mask [used bitmasking in the problem]
[don't know if it can be done in a better way]