From 047ce0a649098930a77a52be54346244d58f8fe0 Mon Sep 17 00:00:00 2001 From: Tanmay-312 Date: Wed, 22 May 2024 08:26:49 +0530 Subject: [PATCH] Added codes for 22 May --- GeeksForGeeks/May/22-5-24/GFG.java | 73 +++++++++++++++++++++++++++++ GeeksForGeeks/May/22-5-24/README.md | 2 + LeetCode/May/22-5-24/README.md | 2 + LeetCode/May/22-5-24/Solution.java | 35 ++++++++++++++ 4 files changed, 112 insertions(+) create mode 100644 GeeksForGeeks/May/22-5-24/GFG.java create mode 100644 GeeksForGeeks/May/22-5-24/README.md create mode 100644 LeetCode/May/22-5-24/README.md create mode 100644 LeetCode/May/22-5-24/Solution.java 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; + } +}