From ec8d53f921c60c23baa2948160be130070be2b34 Mon Sep 17 00:00:00 2001 From: Amaan-29 Date: Mon, 19 Jan 2026 11:07:02 -0500 Subject: [PATCH 1/3] Hashing-1 - IsIsomorphic problem HW --- .idea/.gitignore | 3 + .idea/Hashing-1.iml | 11 ++ .idea/codeStyles/Project.xml | 7 + .idea/codeStyles/codeStyleConfig.xml | 5 + .idea/misc.xml | 6 + .idea/modules.xml | 8 ++ .idea/uiDesigner.xml | 124 ++++++++++++++++++ .idea/vcs.xml | 6 + IsIsomorphic.java | 39 ++++++ out/production/Hashing-1/.idea/.gitignore | 3 + out/production/Hashing-1/.idea/Hashing-1.iml | 11 ++ .../Hashing-1/.idea/codeStyles/Project.xml | 7 + .../.idea/codeStyles/codeStyleConfig.xml | 5 + out/production/Hashing-1/.idea/misc.xml | 6 + out/production/Hashing-1/.idea/modules.xml | 8 ++ out/production/Hashing-1/.idea/uiDesigner.xml | 124 ++++++++++++++++++ out/production/Hashing-1/.idea/vcs.xml | 6 + out/production/Hashing-1/IsIsomorphic.class | Bin 0 -> 1658 bytes out/production/Hashing-1/README.md | 60 +++++++++ 19 files changed, 439 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/Hashing-1.iml create mode 100644 .idea/codeStyles/Project.xml create mode 100644 .idea/codeStyles/codeStyleConfig.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/uiDesigner.xml create mode 100644 .idea/vcs.xml create mode 100644 IsIsomorphic.java create mode 100644 out/production/Hashing-1/.idea/.gitignore create mode 100644 out/production/Hashing-1/.idea/Hashing-1.iml create mode 100644 out/production/Hashing-1/.idea/codeStyles/Project.xml create mode 100644 out/production/Hashing-1/.idea/codeStyles/codeStyleConfig.xml create mode 100644 out/production/Hashing-1/.idea/misc.xml create mode 100644 out/production/Hashing-1/.idea/modules.xml create mode 100644 out/production/Hashing-1/.idea/uiDesigner.xml create mode 100644 out/production/Hashing-1/.idea/vcs.xml create mode 100644 out/production/Hashing-1/IsIsomorphic.class create mode 100644 out/production/Hashing-1/README.md diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 00000000..26d33521 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/Hashing-1.iml b/.idea/Hashing-1.iml new file mode 100644 index 00000000..b107a2dd --- /dev/null +++ b/.idea/Hashing-1.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 00000000..919ce1f1 --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 00000000..a55e7a17 --- /dev/null +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 00000000..f5bd2dfe --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 00000000..c12cdf14 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 00000000..2b63946d --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 00000000..35eb1ddf --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/IsIsomorphic.java b/IsIsomorphic.java new file mode 100644 index 00000000..ecde5a0e --- /dev/null +++ b/IsIsomorphic.java @@ -0,0 +1,39 @@ +import java.util.HashMap; + +public class IsIsomorphic { + public static void main(String args[]){ + String s = "paper"; + String t = "title"; + System.out.println(isIsomorphic(s,t)); + } + public static boolean isIsomorphic(String s, String t) { + int sl = s.length(); + int tl = t.length(); + //create two HashMaps to store characters of s & t + HashMap sMap = new HashMap<>(); + HashMap tMap = new HashMap<>(); + for(int i=0; i < sl; i++){ + char sChar = s.charAt(i); + char tChar = t.charAt(i); + //s to t mapping + if(sMap.containsKey(sChar)){ + //if earlier mapped character of s is equal to t, if not return false --> breech + if(sMap.get(sChar) != tChar){ + return false; + } + } else{ + sMap.put(sChar, tChar); + } + // t to s mapping + if(tMap.containsKey(tChar)){ + //if earlier mapped character of t is equal to s, if not return false --> breech + if(tMap.get(tChar) != sChar){ + return false; + } + } else{ + tMap.put(tChar, sChar); + } + } + return true; + } +} diff --git a/out/production/Hashing-1/.idea/.gitignore b/out/production/Hashing-1/.idea/.gitignore new file mode 100644 index 00000000..26d33521 --- /dev/null +++ b/out/production/Hashing-1/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/out/production/Hashing-1/.idea/Hashing-1.iml b/out/production/Hashing-1/.idea/Hashing-1.iml new file mode 100644 index 00000000..b107a2dd --- /dev/null +++ b/out/production/Hashing-1/.idea/Hashing-1.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/out/production/Hashing-1/.idea/codeStyles/Project.xml b/out/production/Hashing-1/.idea/codeStyles/Project.xml new file mode 100644 index 00000000..919ce1f1 --- /dev/null +++ b/out/production/Hashing-1/.idea/codeStyles/Project.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/out/production/Hashing-1/.idea/codeStyles/codeStyleConfig.xml b/out/production/Hashing-1/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 00000000..a55e7a17 --- /dev/null +++ b/out/production/Hashing-1/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/out/production/Hashing-1/.idea/misc.xml b/out/production/Hashing-1/.idea/misc.xml new file mode 100644 index 00000000..f5bd2dfe --- /dev/null +++ b/out/production/Hashing-1/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/out/production/Hashing-1/.idea/modules.xml b/out/production/Hashing-1/.idea/modules.xml new file mode 100644 index 00000000..c12cdf14 --- /dev/null +++ b/out/production/Hashing-1/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/out/production/Hashing-1/.idea/uiDesigner.xml b/out/production/Hashing-1/.idea/uiDesigner.xml new file mode 100644 index 00000000..2b63946d --- /dev/null +++ b/out/production/Hashing-1/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/out/production/Hashing-1/.idea/vcs.xml b/out/production/Hashing-1/.idea/vcs.xml new file mode 100644 index 00000000..35eb1ddf --- /dev/null +++ b/out/production/Hashing-1/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/out/production/Hashing-1/IsIsomorphic.class b/out/production/Hashing-1/IsIsomorphic.class new file mode 100644 index 0000000000000000000000000000000000000000..e2baf9a7c5df85f22f328f487877bf8ac6df5d23 GIT binary patch literal 1658 zcmZuxOK%%h7(Le>&)Cl7<>1hi(3YCCcGA?m658g`hauF|X$mejO}m+x!JaZ6TQlQG zSs|ou5Msj)Ap|M{Hr>D?tw2Jo`9~l@Id^89I*RSlz2A4g=Q;P&{p-Kq{s6FsyJ^G_ z*P!S~Koyv{Z|oXH+i;r2t)2U3!xvCjEywcL1>*TaEs3N+qHA4X?FnbkoQoE>oS=kw<|+jh5kFC441c zE|k((z&QHOV+veBRvYP1_}lW|i+%mRXz%+WX+2rc1B_9>U-+()uSy(|#( zY%V?*#p4Vxf0$)(Fl2LnV4OY-Xs_D`b@^!2>OecsZhz?EIxCD;eWURSt3))VtDT

#y z8SgT$%6c~_#aM~&L|94uM2{5xew^ROi)#y9)_+It&ST77Qu;z7zN}`|*@yUSKCABI z%(Au+?#US?t33fjU-=rx50p3l1QT7zCci^A{wO-mCIiRS`b;7cgP6Y3kI}-I@Hk4o zT7RI5pPzoJJYu6tK;s7C0%^h@;W~;bjA52g=P-dq+Lm~7jWFv3dIvMGXx-(L@&!)f zOPt2H^!3LJK!3CF%J9TewByNKZf_1xk`cdDGwHJz8U|{|(-! z6lcw^P{nQbIE&Bm0i^_LjG3laXsaLC>a=}G+Z@!VETw5U!A}ScIer|He{oTW@!a1S N|A(%EFystv{|{-TWrF|! literal 0 HcmV?d00001 diff --git a/out/production/Hashing-1/README.md b/out/production/Hashing-1/README.md new file mode 100644 index 00000000..17be34ff --- /dev/null +++ b/out/production/Hashing-1/README.md @@ -0,0 +1,60 @@ +# Hashing-1 +Explain your approach in **three sentences only** at top of your code + + +## Problem 1: +Given an array of strings, group anagrams together. + +Example: +Input: ["eat", "tea", "tan", "ate", "nat", "bat"], +Output: +[ + ["ate","eat","tea"], + ["nat","tan"], + ["bat"] +] + +Note: +All inputs will be in lowercase. +The order of your output does not matter. + +## Problem 2: +Given two strings s and t, determine if they are isomorphic. +Two strings are isomorphic if the characters in s can be replaced to get t. +All occurrences of a character must be replaced with another character while preserving the order of characters. No two characters may map to the same character but a character may map to itself. + +Example 1: +Input: s = "egg", t = "add" +Output: true + +Example 2: +Input: s = "foo", t = "bar" +Output: false + +Example 3: +Input: s = "paper", t = "title" +Output: true +Note: +You may assume both s and t have the same length. + +## Problem 3: +Given a pattern and a string str, find if str follows the same pattern. +Here follow means a full match, such that there is a bijection between a letter in pattern and a non-empty word in str. + +Example 1: +Input: pattern = "abba", str = "dog cat cat dog" +Output: true + +Example 2: +Input:pattern = "abba", str = "dog cat cat fish" +Output: false + +Example 3: +Input: pattern = "aaaa", str = "dog cat cat dog" +Output: false + +Example 4: +Input: pattern = "abba", str = "dog dog dog dog" +Output: false +Notes: +You may assume pattern contains only lowercase letters, and str contains lowercase letters that may be separated by a single space. From 05b0ea635155803aae12575f7823f088508e1540 Mon Sep 17 00:00:00 2001 From: Amaan-29 Date: Mon, 19 Jan 2026 11:08:13 -0500 Subject: [PATCH 2/3] Hashing-1 - IsIsomorphic problem HW --- IsIsomorphic.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/IsIsomorphic.java b/IsIsomorphic.java index ecde5a0e..c172baa6 100644 --- a/IsIsomorphic.java +++ b/IsIsomorphic.java @@ -37,3 +37,6 @@ public static boolean isIsomorphic(String s, String t) { return true; } } + +// TC : O(N) +//SC : O(1) \ No newline at end of file From 3787c272946c46fa4636b2d550c1f40cd474c59c Mon Sep 17 00:00:00 2001 From: Amaan-29 Date: Mon, 19 Jan 2026 13:03:26 -0500 Subject: [PATCH 3/3] Hashing-1 - group Anagram problem HW --- .idea/.gitignore | 3 - .idea/Hashing-1.iml | 11 --- .idea/codeStyles/Project.xml | 7 -- .idea/codeStyles/codeStyleConfig.xml | 5 -- .idea/misc.xml | 6 -- .idea/modules.xml | 8 -- .idea/uiDesigner.xml | 124 --------------------------- .idea/vcs.xml | 6 -- .idea/workspace.xml | 87 +++++++++++++++++++ GroupAnagrams.java | 29 +++++++ 10 files changed, 116 insertions(+), 170 deletions(-) delete mode 100644 .idea/.gitignore delete mode 100644 .idea/Hashing-1.iml delete mode 100644 .idea/codeStyles/Project.xml delete mode 100644 .idea/codeStyles/codeStyleConfig.xml delete mode 100644 .idea/misc.xml delete mode 100644 .idea/modules.xml delete mode 100644 .idea/uiDesigner.xml delete mode 100644 .idea/vcs.xml create mode 100644 .idea/workspace.xml create mode 100644 GroupAnagrams.java diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index 26d33521..00000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml diff --git a/.idea/Hashing-1.iml b/.idea/Hashing-1.iml deleted file mode 100644 index b107a2dd..00000000 --- a/.idea/Hashing-1.iml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml deleted file mode 100644 index 919ce1f1..00000000 --- a/.idea/codeStyles/Project.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml deleted file mode 100644 index a55e7a17..00000000 --- a/.idea/codeStyles/codeStyleConfig.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index f5bd2dfe..00000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index c12cdf14..00000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml deleted file mode 100644 index 2b63946d..00000000 --- a/.idea/uiDesigner.xml +++ /dev/null @@ -1,124 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 35eb1ddf..00000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 00000000..5cd3857e --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,87 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1768803248350 + + + + + + + \ No newline at end of file diff --git a/GroupAnagrams.java b/GroupAnagrams.java new file mode 100644 index 00000000..ba238d82 --- /dev/null +++ b/GroupAnagrams.java @@ -0,0 +1,29 @@ +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; + +public class GroupAnagrams { + public List> groupAnagrams(String[] strs){ + HashMap> map = new HashMap<>(); + for(int i=0;i()); //map = {"aet" : []} creates new empty list + } + //get list of all Strings + List li = map.get(sorted); + li.add(curr); //add to list + map.put(sorted,li);//add to map + } + return new ArrayList<>(map.values()); + } +} + +//TC: O(N KlogK) +//SC: O(NK) \ No newline at end of file