From 3b7f93f2a2cf47095dbfc6705b56eb039d8d8913 Mon Sep 17 00:00:00 2001 From: Tanmay-312 Date: Fri, 7 Jun 2024 10:36:07 +0530 Subject: [PATCH] Added codes for 7 June --- GeeksForGeeks/June/07-6-24/GFG.java | 82 ++++++++++++++++++++++++++++ GeeksForGeeks/June/07-6-24/README.md | 2 + LeetCode/June/07-6-24/README.md | 2 + LeetCode/June/07-6-24/Solution.java | 75 +++++++++++++++++++++++++ 4 files changed, 161 insertions(+) create mode 100644 GeeksForGeeks/June/07-6-24/GFG.java create mode 100644 GeeksForGeeks/June/07-6-24/README.md create mode 100644 LeetCode/June/07-6-24/README.md create mode 100644 LeetCode/June/07-6-24/Solution.java diff --git a/GeeksForGeeks/June/07-6-24/GFG.java b/GeeksForGeeks/June/07-6-24/GFG.java new file mode 100644 index 0000000..364fd45 --- /dev/null +++ b/GeeksForGeeks/June/07-6-24/GFG.java @@ -0,0 +1,82 @@ +//{ Driver Code Starts +import java.io.*; +import java.lang.*; +import java.util.*; + +class Main { + + public static void main(String[] args) throws IOException { + + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + int t = Integer.parseInt(br.readLine().trim()); // Inputting the testcases + while (t-- > 0) { + + // taking size of array + int n = Integer.parseInt(br.readLine().trim()); + int l[] = new int[n]; + int r[] = new int[n]; + String inputLine[] = br.readLine().trim().split(" "); + + // adding elements to array L + for (int i = 0; i < n; i++) { + l[i] = Integer.parseInt(inputLine[i]); + } + inputLine = br.readLine().trim().split(" "); + int maxx = Integer.MIN_VALUE; + + // adding elements to array R + for (int i = 0; i < n; i++) { + r[i] = Integer.parseInt(inputLine[i]); + if (r[i] > maxx) { + maxx = r[i]; + } + } + + Solution obj = new Solution(); + + // calling maxOccured() function + System.out.println(obj.maxOccured(n, l, r, maxx)); + } + } +} + + +// } Driver Code Ends +// L[] and R[] are input ranges +// n : size of array +// maxx: maximum element in R[] +// arr[]: declared globally with size equal to 1000000 + +class Solution +{ + // Function to find the maximum occurred integer in all ranges. + public static int maxOccured(int n, int l[], int r[], int maxx) + { + int[] arr = new int[maxx+2]; + + for (int i=0; i maxfreq) + { + maxfreq = arr[i]; + result = i; + } + } + + return result; + } +} + +//{ Driver Code Starts. + +// } Driver Code Ends diff --git a/GeeksForGeeks/June/07-6-24/README.md b/GeeksForGeeks/June/07-6-24/README.md new file mode 100644 index 0000000..d003028 --- /dev/null +++ b/GeeksForGeeks/June/07-6-24/README.md @@ -0,0 +1,2 @@ +Time complexity - O(n + maxx) +Space complexity - O(maxx) diff --git a/LeetCode/June/07-6-24/README.md b/LeetCode/June/07-6-24/README.md new file mode 100644 index 0000000..532a5be --- /dev/null +++ b/LeetCode/June/07-6-24/README.md @@ -0,0 +1,2 @@ +Time complexity - O(k*n + s*m) +SPace complexity - O(k*n*26) diff --git a/LeetCode/June/07-6-24/Solution.java b/LeetCode/June/07-6-24/Solution.java new file mode 100644 index 0000000..4abe3c6 --- /dev/null +++ b/LeetCode/June/07-6-24/Solution.java @@ -0,0 +1,75 @@ +class Solution +{ + class Trie + { + Trie child[]=new Trie[26]; + boolean isEnd; + } + + public String replaceWords(List dictionary, String sentence) + { + Trie root = new Trie(); + + for (String s: dictionary) + { + insert(root,s); + } + + StringBuilder res = new StringBuilder(); + String words[] = sentence.split(" "); + + for (int i=0; i