Find the longest sub string of a word after concatenation of given words array
Think of encapsulation and responsibilities

The main method parses the input and uses this piece of code to compute and print the answer:


findCombi(arr, N, "", new HashMap&lt;Integer, Boolean&gt;());

System.out.println(max);



This is ugly in many ways:


Where does the value of max come from? It's a global variable, its value gets set as a side effect of the call to findCombi. Try to organize code in a way to avoid side effects.
What are all those parameters passed to findCombi? They are low-level implementation details of findCombi. They should not be exposed outside that function. The main method shouldn't have to know how the solution is computed. It has the inputs (the array of words), it should pass just that to a function, and get an int back as the answer.
The parameter N is redundant, thanks to the .length field of arrays in Java.


This is what the snippet should have looked like:

int solution = findLongestSubstringCombination(arr);


There are no unnecessary parameters, and no side effects needed.