diff --git a/GeeksForGeeks/May/22-5-24/GFG.java b/GeeksForGeeks/May/22-5-24/GFG.java new file mode 100644 index 0000000..127336b --- /dev/null +++ b/GeeksForGeeks/May/22-5-24/GFG.java @@ -0,0 +1,73 @@ +//{ Driver Code Starts +// Initial Template for Java + +import java.io.*; +import java.lang.*; +import java.math.*; +import java.util.*; + +class GFG { + public static void main(String[] args) throws IOException { + Scanner sc = new Scanner(System.in); + int T = sc.nextInt(); + while (T-- > 0) { + int n = sc.nextInt(); + int a[] = new int[n]; + for (int i = 0; i < n; i++) { + a[i] = sc.nextInt(); + } + int k = sc.nextInt(); + Solution obj = new Solution(); + double ans = obj.findSmallestMaxDist(a, k); + System.out.printf("%.2f", ans); + System.out.println(); + } + } +} + +// } Driver Code Ends + + +// User function Template for Java + +class Solution +{ + static double findSmallestMaxDist(int a[], int k) + { + // code here + int n=a.length; + double l=0, r=maxDist(a); + while(l+1e-6> partition(String s) + { + List> ans = new ArrayList<>(); + dfs(s, 0, new ArrayList<>(), ans); + return ans; + } + + private void dfs(final String s, int start, List path, List> ans) + { + if (start == s.length()) + { + ans.add(new ArrayList<>(path)); + return; + } + + for (int i = start; i < s.length(); ++i) + if (isPalindrome(s, start, i)) + { + path.add(s.substring(start, i + 1)); + dfs(s, i + 1, path, ans); + path.remove(path.size() - 1); + } + } + + private boolean isPalindrome(final String s, int l, int r) + { + while (l < r) + if (s.charAt(l++) != s.charAt(r--)) + return false; + + return true; + } +}