Constraint in this Question

in the video, bhaiya has checked one condition like outputstring.length() + arr[i].length, should be less than 26, but I have not applied such condition because in the question I didn’t find any such condition to be applied and my all test cases are passed. so would you please make me understand where exactly I need to apply that condition.

Here is my Code : - import java.util.Scanner; public class Main { public static int maxSubsequence(String[] arr){ return maxSubsequence(arr,0,""); } private static int maxSubsequence(String[] arr, int start,String subs){ if(start == arr.length){ boolean flag = checkUnique(subs); if(flag) return subs.length(); else return Integer.MIN_VALUE; }//Base Case int max1 = maxSubsequence(arr,start+1,subs+arr[start]); int max2 = maxSubsequence(arr,start+1,subs); return (Math.max(max1,max2)); }//End of maxSubsequence() Method private static boolean checkUnique(String subs){ if(subs.length() == 0 || subs.length() == 1) return true; int[] cache = new int[26]; for(int i=0;i<subs.length();i++) cache[subs.charAt(i) - ‘a’]++; for(int i=0;i<26;i++) if(cache[i] > 1) return false; return true; } public static void main (String args[]) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); String[] arr = new String[n]; for(int i=0;i<n;i++) arr[i] = sc.next(); int res = maxSubsequence(arr); System.out.println(res); } }

Hey @87adarsh.gupta
There is no neet to apply that constraint but it helps to save some time
If we have a string with length more than 26 then it will always have a duplicate

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.