question_slug stringlengths 3 77 | title stringlengths 1 183 | slug stringlengths 12 45 | summary stringlengths 1 160 ⌀ | author stringlengths 2 30 | certification stringclasses 2
values | created_at stringdate 2013-10-25 17:32:12 2025-04-12 09:38:24 | updated_at stringdate 2013-10-25 17:32:12 2025-04-12 09:38:24 | hit_count int64 0 10.6M | has_video bool 2
classes | content stringlengths 4 576k | upvotes int64 0 11.5k | downvotes int64 0 358 | tags stringlengths 2 193 | comments int64 0 2.56k |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
isomorphic-strings | Java solution with 1 line core code | java-solution-with-1-line-core-code-by-y-u4t3 | public boolean isIsomorphic(String s1, String s2) {\n Map<Character, Integer> m1 = new HashMap<>();\n Map<Character, Integer> m2 = new Has | yfcheng | NORMAL | 2015-12-25T22:40:41+00:00 | 2015-12-25T22:40:41+00:00 | 16,905 | false | public boolean isIsomorphic(String s1, String s2) {\n Map<Character, Integer> m1 = new HashMap<>();\n Map<Character, Integer> m2 = new HashMap<>();\n \n for(Integer i = 0; i < s1.length(); i++) {\n \n if(m1.put(s1.charAt(i), i) != m2.put(s2.charAt(i), i)) {\... | 96 | 2 | [] | 12 |
isomorphic-strings | Simple solution using one Hashmap. | simple-solution-using-one-hashmap-by-sat-bsvn | ALGORITHM\n1. Insert chars of string s as key, and chars of t as value , into a map. For ex. if s = foo and t = baa contents of map should be\'f\'-\'b\' , \' | satyyaa98 | NORMAL | 2021-04-19T10:18:04.371408+00:00 | 2021-04-19T10:18:04.371454+00:00 | 9,108 | false | **ALGORITHM**\n1. Insert chars of string ```s``` as key, and chars of ```t``` as value , into a map. For ex. if ```s = foo and t = baa``` contents of map should be``` \'f\'-\'b\' , \'o\'-\'a\' ```.\n2. Before inserting, check for the presence of the key:\n\tif present check for the values of the corresponding chars ... | 92 | 1 | ['C'] | 12 |
isomorphic-strings | Easy JS Sol. || 99.14% acceptable || Understandable Approach 💯🧑💻 | easy-js-sol-9914-acceptable-understandab-6s3q | Intuition\n Describe your first thoughts on how to solve this problem. \n\n- Loop through the input strings and apply the conditions.\n\n# Approach\n Descri | Rajat310 | NORMAL | 2023-01-31T05:01:44.010371+00:00 | 2023-09-26T19:11:58.090611+00:00 | 4,966 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n- Loop through the input strings and apply the conditions.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n1. The **approach** of the function is to compare the positions of characters in the two input stri... | 78 | 0 | ['Hash Table', 'String', 'JavaScript'] | 7 |
isomorphic-strings | My C 0ms solution | my-c-0ms-solution-by-rxm24217-bqgx | bool isIsomorphic(char* s, char* t) {\n \tchar charArrS[256] = { 0 };\n \tchar charArrT[256] = { 0 };\n \tint i = 0;\n \twhile (s[i] !=0)\n \t{\n | rxm24217 | NORMAL | 2015-05-26T14:28:04+00:00 | 2018-09-11T22:10:45.887993+00:00 | 15,073 | false | bool isIsomorphic(char* s, char* t) {\n \tchar charArrS[256] = { 0 };\n \tchar charArrT[256] = { 0 };\n \tint i = 0;\n \twhile (s[i] !=0)\n \t{\n \t\tif (charArrS[s[i]] == 0 && charArrT[t[i]] == 0)\n \t\t{\n \t\t\tcharArrS[s[i]] = t[i];\n \t\t\tcharArrT[t[i]] = s[i];\n \t\t}\n \t\te... | 78 | 0 | [] | 5 |
isomorphic-strings | 8ms C++ Solution without Hashmap | 8ms-c-solution-without-hashmap-by-xh2312-30de | bool isIsomorphic(string s, string t) {\n char map_s[128] = { 0 };\n char map_t[128] = { 0 };\n int len = s.size();\n | xh23123 | NORMAL | 2015-06-18T15:14:08+00:00 | 2018-08-12T19:23:52.860048+00:00 | 22,510 | false | bool isIsomorphic(string s, string t) {\n char map_s[128] = { 0 };\n char map_t[128] = { 0 };\n int len = s.size();\n for (int i = 0; i < len; ++i)\n {\n if (map_s[s[i]]!=map_t[t[i]]) return false;\n map_s[s[i]] = i+1;\n ... | 75 | 6 | ['C++'] | 15 |
isomorphic-strings | [Python/C++] 2 solutions - Clean & Concise | pythonc-2-solutions-clean-concise-by-hie-16ia | \u2714\uFE0F Solution 1: Normalize 2 strings\n- The idea is to normalize s and t into the same string.\n- For example: s = "egg", t = "add"\n\t- Then both will | hiepit | NORMAL | 2021-07-12T07:17:53.072729+00:00 | 2021-08-30T03:31:44.617203+00:00 | 4,619 | false | **\u2714\uFE0F Solution 1: Normalize 2 strings**\n- The idea is to normalize `s` and `t` into the same string.\n- For example: `s = "egg", t = "add"`\n\t- Then both will be normalized as `"abb"`.\n- Finally, compare if the normalize version of 2 string is the same or not.\n\n**Python 3**\n```python\nclass Solution:\n ... | 70 | 14 | [] | 8 |
isomorphic-strings | [JAVA] easy 4 liner solution | java-easy-4-liner-solution-by-jugantar20-uvsm | \n\n# Complexity\n- Time complexity: O(n)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(n)\n Add your space complexity here, e.g. O(n) \n | Jugantar2020 | NORMAL | 2022-10-09T14:15:45.193168+00:00 | 2022-10-09T14:15:45.193408+00:00 | 9,591 | false | \n\n# Complexity\n- Time complexity: O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(n)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n public boolean isIsomorphic(String s, String t) {\n Map<Character, Integer> map1 = new HashMap<>(... | 62 | 1 | ['Java'] | 12 |
isomorphic-strings | ✅5 Different types of solutions✅ || Brute Force ➡️Optimization || Easy To Understand✅ | 5-different-types-of-solutions-brute-for-tqd5 | \n\n# Intuition\nGiven two strings, s and t, determine if they are isomorphic. Two strings are isomorphic if the characters in s can be mapped to the characters | Onkar-S | NORMAL | 2023-12-04T13:14:24.569665+00:00 | 2023-12-04T13:14:24.569690+00:00 | 4,386 | false | \n\n# Intuition\nGiven two strings, `s` and `t`, determine if they are isomorphic. Two strings are isomorphic if the characters in `s` can be mapped to the characters in `t` in a one-to-one relationship.... | 55 | 0 | ['Array', 'Hash Table', 'String', 'C++'] | 6 |
isomorphic-strings | Java 3ms beats 99.25% | java-3ms-beats-9925-by-joebluesky-v3t1 | Since all the test cases use ASCII characters, you can use small arrays as a lookup tables.\n\n public class Solution {\n \n public boolean isI | joebluesky | NORMAL | 2016-04-02T06:04:58+00:00 | 2016-04-02T06:04:58+00:00 | 13,848 | false | Since all the test cases use ASCII characters, you can use small arrays as a lookup tables.\n\n public class Solution {\n \n public boolean isIsomorphic(String sString, String tString) {\n \n char[] s = sString.toCharArray();\n char[] t = tString.toCharArray();\n \n ... | 52 | 0 | ['Java'] | 13 |
isomorphic-strings | 1 line Python Solution, 95% | 1-line-python-solution-95-by-antarestsao-a2pk | Say we have 2 strings 'add' and 'egg':\nfor the result to be true, one letter in the first string must have an unique mapping to one letter in the other string. | antarestsao | NORMAL | 2016-10-30T21:25:24.663000+00:00 | 2018-10-16T00:54:02.653681+00:00 | 3,861 | false | Say we have 2 strings ```'add'``` and ```'egg'```:\nfor the result to be true, one letter in the first string must have an unique mapping to one letter in the other string. \n```'a'->'e'``` and ```'d'->'g'```\nAnd the number of such mapping should be the **SAME** as the number of different letters in the 2 strings. \nA... | 50 | 1 | [] | 5 |
isomorphic-strings | 🔥🔥🔥🔥🔥 Beat 99% 🔥🔥🔥🔥🔥 EASY 🔥🔥🔥🔥🔥🔥 | beat-99-easy-by-abdallaellaithy-re8w | \n\n\n# Code\n\nclass Solution(object):\n def isIsomorphic(self, s, t):\n """\n :type s: str\n :type t: str\n :rtype: bool\n | abdallaellaithy | NORMAL | 2024-04-02T00:02:24.653648+00:00 | 2024-04-02T00:05:11.565839+00:00 | 16,169 | false | [](https://leetcode.com/problems/isomorphic-strings/submissions/1203909730/?envType=daily-question&envId=2024-04-02)\n\n\n# Code\n```\nclass Solution(object):\n def isIsomorphic(self, s, t):\n """\n ... | 47 | 0 | ['String', 'Python', 'Python3'] | 11 |
isomorphic-strings | Javascript 6 lines solution | javascript-6-lines-solution-by-lostrace-yfri | var isIsomorphic = function(s, t) {\n var obj = {};\n \n for(var i = 0; i < s.length; i++){\n if(!obj['s' + s[i]]) obj['s' + s[i]] = | lostrace | NORMAL | 2015-09-10T17:10:00+00:00 | 2015-09-10T17:10:00+00:00 | 7,145 | false | var isIsomorphic = function(s, t) {\n var obj = {};\n \n for(var i = 0; i < s.length; i++){\n if(!obj['s' + s[i]]) obj['s' + s[i]] = t[i];\n if(!obj['t' + t[i]]) obj['t' + t[i]] = s[i];\n if(t[i] != obj['s' + s[i]] || s[i] != obj['t' + t[i]]) return false;\n ... | 42 | 2 | ['JavaScript'] | 5 |
isomorphic-strings | 5 lines simple Java | 5-lines-simple-java-by-stefanpochmann-mm4d | public boolean isIsomorphic(String s, String t) {\n Map m = new HashMap();\n for (Integer i=0; i<s.length(); ++i)\n if (m.put(s.charAt( | stefanpochmann | NORMAL | 2016-01-17T15:44:56+00:00 | 2018-08-24T12:29:44.554517+00:00 | 15,485 | false | public boolean isIsomorphic(String s, String t) {\n Map m = new HashMap();\n for (Integer i=0; i<s.length(); ++i)\n if (m.put(s.charAt(i), i) != m.put(t.charAt(i)+"", i))\n return false;\n return true;\n }\n\nBased on my [earlier solution for another problem](https:... | 39 | 7 | ['Java'] | 20 |
isomorphic-strings | JS hashmap solution | js-hashmap-solution-by-yushi_lu-f28w | We use a Map to record the key/val pair in S and T. For each char in S, if we never met it before, we record the (s[i], t[i]) pair in map. If we met s[i] before | yushi_lu | NORMAL | 2019-07-28T01:28:09.142443+00:00 | 2019-07-28T01:28:09.142474+00:00 | 4,993 | false | We use a Map to record the key/val pair in S and T. For each char in S, if we never met it before, we record the (s[i], t[i]) pair in map. If we met s[i] before, we compare the value of s[i] with t[i], which are supposed to be the same. After that, we need to check whether map.values() contain duplicate value. If map.v... | 36 | 0 | ['JavaScript'] | 3 |
isomorphic-strings | ✅Accepted || ✅Short & Simple || ✅Best Method || ✅Easy-To-Understand | accepted-short-simple-best-method-easy-t-6x26 | \n# Code\n\nclass Solution {\npublic:\n bool isIsomorphic(string s, string t) {\n int m1[256] = {0}, m2[256] = {0}, n = s.size();\n for (int i | sanjaydwk8 | NORMAL | 2023-01-30T08:37:37.890470+00:00 | 2023-01-30T08:37:37.890507+00:00 | 7,388 | false | \n# Code\n```\nclass Solution {\npublic:\n bool isIsomorphic(string s, string t) {\n int m1[256] = {0}, m2[256] = {0}, n = s.size();\n for (int i = 0; i < n; ++i) {\n if (m1[s[i]] != m2[t[i]]) return false;\n m1[s[i]] = i + 1;\n m2[t[i]] = i + 1;\n }\n re... | 29 | 0 | ['C++'] | 4 |
isomorphic-strings | [Python] Easy Approach ✔ | python-easy-approach-by-triposat-bi4i | \tclass Solution:\n\t\tdef isIsomorphic(self, s: str, t: str) -> bool:\n\t\t\tif len(set(s)) != len(set(t)):\n\t\t\t\treturn False\n\t\t\thash_map = {}\n\t\t\tf | triposat | NORMAL | 2022-01-17T10:08:37.823649+00:00 | 2022-04-27T12:43:47.027250+00:00 | 4,692 | false | \tclass Solution:\n\t\tdef isIsomorphic(self, s: str, t: str) -> bool:\n\t\t\tif len(set(s)) != len(set(t)):\n\t\t\t\treturn False\n\t\t\thash_map = {}\n\t\t\tfor char in range(len(t)):\n\t\t\t\tif t[char] not in hash_map:\n\t\t\t\t\thash_map[t[char]] = s[char]\n\t\t\t\telif hash_map[t[char]] != s[char]:\n\t\t\t\t\tret... | 28 | 1 | ['Python', 'Python3'] | 5 |
isomorphic-strings | Intuitive ➡️ Explained In Depth ➡️[Java/C++/JavaScript/C#/Python3/Go] | intuitive-explained-in-depth-javacjavasc-ev04 | Approach\n1. Initialize Frequency Maps: Two arrays, map1 and map2, of size 128 are created. These arrays are used to store the frequency of characters encounter | Shivansu_7 | NORMAL | 2024-04-02T03:50:27.251785+00:00 | 2024-04-02T03:50:27.251814+00:00 | 3,324 | false | # Approach\n1. **Initialize Frequency Maps**: Two arrays, `map1` and `map2`, of size 128 are created. These arrays are used to store the frequency of characters encountered in strings `s` and `t`, respectively. Since the ASCII character set has 128 characters, these arrays can efficiently store the frequency of each ch... | 26 | 0 | ['Python', 'C++', 'Java', 'Go', 'Python3', 'Rust', 'JavaScript', 'C#'] | 4 |
isomorphic-strings | Java ☕| With/without Hashmap ✅✅| Dry run examples 🚀| Handwritten Notes 🎯| Beginners Friendly ✔️✔️ | java-withwithout-hashmap-dry-run-example-zxea | Intuition\nThe problem requires determining whether two strings are isomorphic. The main idea is to establish a one-to-one mapping between characters in both st | pnkulkarni05 | NORMAL | 2024-04-02T03:43:08.797492+00:00 | 2024-04-02T05:28:21.549347+00:00 | 2,779 | false | # Intuition\nThe problem requires determining whether two strings are isomorphic. The main idea is to establish a one-to-one mapping between characters in both strings.\n\n# Approach 1: Using HashMap\nIn this approach, we use two hashmaps to store mappings between characters of both strings. We iterate through each cha... | 24 | 0 | ['Array', 'Hash Table', 'String', 'Java'] | 9 |
isomorphic-strings | ✅ 🔥 0 ms Runtime Beats 100% User🔥|| Code Idea ✅ || Algorithm & Solving Step ✅ || | 0-ms-runtime-beats-100-user-code-idea-al-47qv | \n\n\u2705 IF YOU LIKE THIS SOLUTION, PLEASE UPVOTE AT THE END \u2705 :\n\n### Approach: Using Array as Mapping Table for ASCII Characters :\n\n### Intuition\ | Letssoumen | NORMAL | 2024-12-04T00:48:32.455495+00:00 | 2024-12-04T00:48:32.455521+00:00 | 3,959 | false | \n\n\u2705 IF YOU LIKE THIS SOLUTION, PLEASE UPVOTE AT THE END \u2705 :\n\n### Approach: Using Array as Mapping Table for ASCII Characters :\n\n### **Intuition**\nInstea... | 23 | 0 | ['Hash Table', 'String', 'C++', 'Java', 'Python3'] | 1 |
isomorphic-strings | 4ms Accept C code | 4ms-accept-c-code-by-haiyuanli-yns5 | Hopefully a nice balance of readability and performance.\n\nThe Code:\n\n bool isIsomorphic(char s, char t) {\n \t\tchar mapST[128] = { 0 };\n \t\tchar | haiyuanli | NORMAL | 2015-05-14T05:36:25+00:00 | 2015-05-14T05:36:25+00:00 | 2,563 | false | Hopefully a nice balance of readability and performance.\n\nThe Code:\n\n bool isIsomorphic(char* s, char* t) {\n \t\tchar mapST[128] = { 0 };\n \t\tchar mapTS[128] = { 0 };\n \t\tsize_t len = strlen(s);\n \t\tfor (int i = 0; i < len; ++i)\n \t\t{\n \t\t\tif (mapST[s[i]] == 0 && mapTS[t[i]] == 0)\n... | 21 | 0 | [] | 1 |
isomorphic-strings | Use array as map+ bitset vs Hash map||0ms beats 100% | use-array-as-map-bitset-vs-hash-map0ms-b-ny1s | Intuition\n Describe your first thoughts on how to solve this problem. \nThis is a problem to judge whether there is a one-to-one correspondence between s & t. | anwendeng | NORMAL | 2024-04-02T01:33:17.046761+00:00 | 2024-04-02T11:59:03.306095+00:00 | 10,420 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThis is a problem to judge whether there is a one-to-one correspondence between s & t.\nMy idea is to construct the mapping st:s->t & inverse map ts:t->s, if possible.\n\n3 C++ codes, 1x array+biset, 1 x unordered_map & 1x just array.\nT... | 19 | 0 | ['Array', 'Hash Table', 'Bit Manipulation', 'C++', 'Python3'] | 6 |
isomorphic-strings | ✅ [Accepted] Solution for Swift | accepted-solution-for-swift-by-asahiocea-z94x | \nDisclaimer: By using any content from this post or thread, you release the author(s) from all liability and warranties of any kind. You can are to use the con | AsahiOcean | NORMAL | 2021-03-22T23:58:13.623360+00:00 | 2022-06-20T01:24:07.832559+00:00 | 1,760 | false | <blockquote>\n<b>Disclaimer:</b> By using any content from this post or thread, you release the author(s) from all liability and warranties of any kind. You can are to use the content as you see fit. Any suggestions for improvement are welcome and greatly appreciated! Happy coding!\n</blockquote>\n\n```swift\nclass Sol... | 19 | 0 | ['Swift'] | 2 |
isomorphic-strings | [C++] Array-based Solution Explained, 100% Time, 100% Space | c-array-based-solution-explained-100-tim-zeoi | Pretty simple problem, but again I preferred to challenge me a bit and not go for an easy/lazy/inefficient approach with hashmaps: since we know that we are lik | ajna | NORMAL | 2020-09-08T18:41:00.250300+00:00 | 2021-07-12T08:39:00.968068+00:00 | 3,518 | false | Pretty simple problem, but again I preferred to challenge me a bit and not go for an easy/lazy/inefficient approach with hashmaps: since we know that we are likely to get a limited amount of different characters (annoyingly not specified in the specs), I needed to make a few bets and decide to store the already seen on... | 19 | 0 | ['String', 'C', 'C++'] | 4 |
isomorphic-strings | JavaScript 91.97% | javascript-9197-by-cindy0092-s8t9 | used two objects to cross-reference\n\nvar isIsomorphic = function(s, t) {\n if (s.length !== t.length) {\n return false;\n }\n if (s === t) {\n | cindy0092 | NORMAL | 2019-03-28T14:08:43.395122+00:00 | 2019-03-28T14:08:43.395165+00:00 | 2,007 | false | used two objects to cross-reference\n```\nvar isIsomorphic = function(s, t) {\n if (s.length !== t.length) {\n return false;\n }\n if (s === t) {\n return true;\n }\n const obj1 = {};\n const obj2 = {};\n for(let i = 0; i < s.length; i++) {\n const letter = s[i];\n const... | 19 | 1 | [] | 0 |
isomorphic-strings | ✅Super Easy HashMap (C++/Java/Python) Solution With Detailed Explanation✅ | super-easy-hashmap-cjavapython-solution-i9mro | Intuition\nThe intuition checks if two strings, s and t, are isomorphic by ensuring a one-to-one correspondence between each character in s and t using two hash | suyogshete04 | NORMAL | 2024-04-02T01:53:46.680282+00:00 | 2024-04-02T05:01:11.928029+00:00 | 12,826 | false | # Intuition\nThe intuition checks if two strings, `s` and `t`, are isomorphic by ensuring a one-to-one correspondence between each character in `s` and `t` using two hash maps. It iterates through both strings simultaneously, verifying existing mappings for consistency and creating new mappings when necessary. If it en... | 18 | 0 | ['Hash Table', 'String', 'C++', 'Java', 'Python3'] | 10 |
isomorphic-strings | JAVASCRIPT 100% WITH EXPLANATION || 92% BEATS || HASH MAPS | javascript-100-with-explanation-92-beats-0scl | Intuition\nThe isomorphic strings problem asks us to determine if two strings have the same pattern of character occurrences. For example, the strings "egg" and | ikboljonme | NORMAL | 2023-03-27T13:39:34.203020+00:00 | 2023-03-27T13:44:46.588114+00:00 | 1,928 | false | # Intuition\nThe isomorphic strings problem asks us to determine if two strings have the same pattern of character occurrences. For example, the strings "egg" and "add" are isomorphic because they both have the pattern "abb", where "a" is mapped to "e" and "b" is mapped to "d". On the other hand, the strings "foo" and ... | 18 | 0 | ['JavaScript'] | 0 |
isomorphic-strings | C++ solution with hashmap | c-solution-with-hashmap-by-lhqqqqq-td65 | class Solution {\n public:\n bool isIsomorphic(string s, string t) {\n if (s.empty())\n return true;\n return hel | lhqqqqq | NORMAL | 2015-04-29T03:02:03+00:00 | 2018-09-21T01:05:17.034320+00:00 | 4,784 | false | class Solution {\n public:\n bool isIsomorphic(string s, string t) {\n if (s.empty())\n return true;\n return helper(s, t) && helper(t, s);\n }\n bool helper(string s, string t) {\n \tunordered_map<char, char> m;\n for (auto i = 0; i != ... | 17 | 0 | ['C++'] | 3 |
isomorphic-strings | 🔥 [LeetCode The Hard Way]🔥 Hash Map | Explained Line By Line | leetcode-the-hard-way-hash-map-explained-1ojr | Please check out LeetCode The Hard Way for more solution explanations and tutorials. If you like it, please give a star, watch my Github Repository and upvote t | __wkw__ | NORMAL | 2022-09-07T05:48:52.045304+00:00 | 2022-09-07T05:48:52.045348+00:00 | 1,312 | false | Please check out [LeetCode The Hard Way](https://wingkwong.github.io/leetcode-the-hard-way/) for more solution explanations and tutorials. If you like it, please give a star, watch my [Github Repository](https://github.com/wingkwong/leetcode-the-hard-way) and upvote this post.\n\n---\n\n```cpp\nclass Solution {\npublic... | 16 | 0 | ['C', 'C++'] | 4 |
isomorphic-strings | Python solution | python-solution-by-zitaowang-6gm8 | \nclass Solution(object):\n def isIsomorphic(self, s, t):\n """\n :type s: str\n :type t: str\n :rtype: bool\n """\n | zitaowang | NORMAL | 2018-08-17T05:33:19.007453+00:00 | 2018-10-11T20:20:16.950285+00:00 | 2,038 | false | ```\nclass Solution(object):\n def isIsomorphic(self, s, t):\n """\n :type s: str\n :type t: str\n :rtype: bool\n """\n n = len(s)\n m = len(t)\n if n != m:\n return False\n dic = {}\n for i in range(n):\n if s[i] in dic:\n ... | 16 | 0 | [] | 1 |
isomorphic-strings | C++/Java/Python/JavaScript || ✅🚀O(n) Using Map Simple Solution || ✔️🔥Easy To Understand | cjavapythonjavascript-on-using-map-simpl-cg6d | Intuition\nTwo strings are considered isomorphic if the characters in one string can be replaced by the characters in the other string in such a way that the tw | devanshupatel | NORMAL | 2023-05-20T14:36:09.531510+00:00 | 2023-05-20T19:33:52.617363+00:00 | 7,147 | false | # Intuition\nTwo strings are considered isomorphic if the characters in one string can be replaced by the characters in the other string in such a way that the two strings become identical.\n\n# Approach\nThe Solution uses a `map<char, char>` to store the mapping between characters of string `s` and string `t`, and a `... | 15 | 0 | ['Hash Table', 'Python', 'C++', 'Java', 'JavaScript'] | 1 |
isomorphic-strings | C++ Simple and Clean Solution Using Normalized Pattern, 7 Lines | c-simple-and-clean-solution-using-normal-4xvn | Normalize both strings to the same pattern.\n\nclass Solution {\npublic:\n string normalize_pattern(string word) {\n unordered_map<char, char> m;\n | yehudisk | NORMAL | 2021-07-12T07:33:33.772769+00:00 | 2021-07-12T07:34:54.706261+00:00 | 2,929 | false | Normalize both strings to the same pattern.\n```\nclass Solution {\npublic:\n string normalize_pattern(string word) {\n unordered_map<char, char> m;\n char curr = \'a\';\n \n for (auto letter : word)\n if (!m[letter]) m[letter] = curr++;\n \n for (int i = 0; i < w... | 15 | 1 | ['C'] | 2 |
isomorphic-strings | 1-liner in Python | 1-liner-in-python-by-stefanpochmann-tu4d | Edit: For an even shorter solution, check out mathsam's answer below and my comment on it.\n\n class Solution:\n def isIsomorphic(self, s, t):\n | stefanpochmann | NORMAL | 2015-05-19T22:43:26+00:00 | 2015-05-19T22:43:26+00:00 | 6,985 | false | Edit: For an even shorter solution, check out mathsam's answer below and my comment on it.\n\n class Solution:\n def isIsomorphic(self, s, t):\n return all(map({}.setdefault, a, b) == list(b) for a, b in ((s, t), (t, s))) | 15 | 5 | ['Python'] | 8 |
isomorphic-strings | Very Easy Solution C++ using both 1 Hashmap and 2 Hashmaps | very-easy-solution-c-using-both-1-hashma-3sp3 | ```\nunordered_map mp1, mp2; //we take 2 unordered maps\n int n = s.length();\n int m = t.length();\n \n if(n != m){ //if there si | tanu_0208 | NORMAL | 2023-03-25T19:13:56.567099+00:00 | 2023-03-26T17:36:50.840773+00:00 | 2,484 | false | ```\nunordered_map<char, int> mp1, mp2; //we take 2 unordered maps\n int n = s.length();\n int m = t.length();\n \n if(n != m){ //if there size is not the same no need to go furthur simply return false\n return false; \n }\n \n for(int i=0; i<n; i++){\n ... | 14 | 0 | ['String', 'C'] | 4 |
isomorphic-strings | 205: Solution with step by step explanation | 205-solution-with-step-by-step-explanati-5r64 | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\nThis solution uses two hash maps to keep track of the mapping of characte | Marlen09 | NORMAL | 2023-02-23T20:12:56.879135+00:00 | 2023-02-23T20:12:56.879168+00:00 | 5,891 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nThis solution uses two hash maps to keep track of the mapping of characters from string s to string t and vice versa. It iterates over the characters in the strings, and if a character is not already in either hash map, it a... | 14 | 0 | ['Hash Table', 'String', 'Python', 'Python3'] | 2 |
isomorphic-strings | ✅C++ solution with hash tables | c-solution-with-hash-tables-by-coding_me-26ov | My GitHub: https://github.com/crimsonKn1ght\n\n\nC++ []\nclass Solution {\npublic:\n bool isIsomorphic(string s, string t) {\n unordered_map<char, cha | coding_menance | NORMAL | 2022-10-14T18:19:19.381536+00:00 | 2022-10-31T11:12:43.028846+00:00 | 3,261 | false | ## My GitHub: https://github.com/crimsonKn1ght\n\n\n``` C++ []\nclass Solution {\npublic:\n bool isIsomorphic(string s, string t) {\n unordered_map<char, char> mp, mp2;\n for (int i=0; i<s.length(); ++i) {\n if (mp[s[i]] && mp[s[i]]!=t[i]) return false;\n if (mp2[t[i]] && mp2[t[i]... | 14 | 0 | ['Hash Table', 'String', 'C++'] | 2 |
isomorphic-strings | Simple JavaScript solution, faster 96.72%~ | simple-javascript-solution-faster-9672-b-neic | \nvar isIsomorphic = function(s, t) {\n let mapS = {}, mapT = {};\n for (let i = 0; i < s.length; i++) {\n if (!mapS[s[i]] && !mapT[t[i]]) {\n | UDN | NORMAL | 2022-08-07T04:27:44.978622+00:00 | 2022-08-07T04:27:44.978646+00:00 | 2,353 | false | ```\nvar isIsomorphic = function(s, t) {\n let mapS = {}, mapT = {};\n for (let i = 0; i < s.length; i++) {\n if (!mapS[s[i]] && !mapT[t[i]]) {\n mapS[s[i]] = t[i];\n mapT[t[i]] = s[i];\n } else if (mapS[s[i]] !== t[i] || mapT[t[i]] !== s[i]) return false;\n } \n return... | 14 | 0 | ['JavaScript'] | 2 |
isomorphic-strings | Ruby short functional solution | ruby-short-functional-solution-by-rowan4-7lgl | ruby\n# @param {String} s\n# @param {String} t\n# @return {Boolean}\ndef is_isomorphic(s, t)\n s.chars.map{ |c| s.index(c) } == t.chars.map{ |c| t.index(c) } | Rowan441 | NORMAL | 2022-06-28T04:42:28.108007+00:00 | 2022-06-28T04:42:28.108041+00:00 | 456 | false | ```ruby\n# @param {String} s\n# @param {String} t\n# @return {Boolean}\ndef is_isomorphic(s, t)\n s.chars.map{ |c| s.index(c) } == t.chars.map{ |c| t.index(c) }\nend\n```\n\n* For both inputs (`s` & `t`) map each letter to the index of the first occurence of that letter in the string (e.g egg => [0, 1, 1])\n* If the... | 14 | 0 | ['Ruby'] | 0 |
isomorphic-strings | C++ 8ms - simple solution | c-8ms-simple-solution-by-rantos22-p9wi | class Solution {\n public:\n bool isIsomorphic(string s, string t) \n {\n const size_t n = s.size();\n if ( n != t.size() | rantos22 | NORMAL | 2015-04-29T10:42:03+00:00 | 2015-04-29T10:42:03+00:00 | 4,466 | false | class Solution {\n public:\n bool isIsomorphic(string s, string t) \n {\n const size_t n = s.size();\n if ( n != t.size())\n return false;\n \n unsigned char forward_map[256] = {}, reverse_map[256] = {};\n \n for ( int... | 14 | 0 | [] | 1 |
isomorphic-strings | Java solution || easy approach using hash map || beginner friendly || | java-solution-easy-approach-using-hash-m-4v5n | //explained in code;str\n\n# Code\n\nclass Solution {\n public boolean isIsomorphic(String s, String t) {\n //first we check if theor length is equall | k_io | NORMAL | 2023-01-26T12:01:32.817932+00:00 | 2023-01-26T12:01:32.817977+00:00 | 2,560 | false | //explained in code;str\n\n# Code\n```\nclass Solution {\n public boolean isIsomorphic(String s, String t) {\n //first we check if theor length is equall or not;\n if(s.length() != t.length()){\n return false ;//if not then we return false ;\n }\n\n HashMap<Character , Characte... | 13 | 0 | ['String', 'Java'] | 2 |
isomorphic-strings | Easy java solution with explanation | easy-java-solution-with-explanation-by-u-cnbl | For s to be Isomorphic t ,t should also be Isomorphic to s\n Here I have used 2 maps as both the strings are of same length we can iterate only once\n get the | uj2208 | NORMAL | 2022-07-20T15:22:29.209548+00:00 | 2022-07-20T15:22:51.493141+00:00 | 1,176 | false | * For s to be Isomorphic t ,t should also be Isomorphic to s\n* Here I have used 2 maps as both the strings are of same length we can iterate only once\n* get the individual characters of each string and map them with other character of the 2nd string\n* but before that check if map1 has key (s[i]) and map.get(s[i]!=t... | 13 | 0 | ['Java'] | 1 |
isomorphic-strings | [Java] TC: O(N) | SC: O(N) | Simple One-Pass solution using a Map & Set | java-tc-on-sc-on-simple-one-pass-solutio-bn5r | java\n/**\n * One-Pass solution using HashMap and HashSet\n *\n * Time Complexity:\n * - O(1) --> This will be in case S & T are of different lengths\n * - O(N) | NarutoBaryonMode | NORMAL | 2021-11-02T22:28:36.065205+00:00 | 2021-11-02T22:41:52.283691+00:00 | 886 | false | ```java\n/**\n * One-Pass solution using HashMap and HashSet\n *\n * Time Complexity:\n * - O(1) --> This will be in case S & T are of different lengths\n * - O(N) --> If S & T are of same length, say N, the code will check the Isomorphic property in one-pass.\n *\n * - O(1) --> This will be in case S & T are of differ... | 12 | 0 | ['String', 'Java'] | 1 |
isomorphic-strings | Java clean code using hashmap (simple solution) | java-clean-code-using-hashmap-simple-sol-jhdn | <-----If you like the solution . Kindly UPvote for better reach\n\nclass Solution {\n public boolean isIsomorphic(String s, String t) {\n HashMap<Char | adarsh1405 | NORMAL | 2021-07-13T04:11:41.306014+00:00 | 2021-07-16T11:46:34.546622+00:00 | 973 | false | <-----**If you like the solution . Kindly UPvote for better reach**\n```\nclass Solution {\n public boolean isIsomorphic(String s, String t) {\n HashMap<Character,Character> hm = new HashMap<>();\n if(s.length()!=t.length())\n return false;\n \n for(int i=0;i<s.length();i++)\n ... | 12 | 2 | ['Java'] | 2 |
isomorphic-strings | 10 lines C solution, without hash table | 10-lines-c-solution-without-hash-table-b-0c7p | bool isIsomorphic(char* s, char* t){\n \tif(!(s&&t))\n \t\treturn false;\n \tchar *spt = s, *tpt=t;\n \twhile(*spt != '\\0'){\n \t\tif( strchr(s, | yxmy | NORMAL | 2015-06-13T08:17:05+00:00 | 2015-06-13T08:17:05+00:00 | 1,307 | false | bool isIsomorphic(char* s, char* t){\n \tif(!(s&&t))\n \t\treturn false;\n \tchar *spt = s, *tpt=t;\n \twhile(*spt != '\\0'){\n \t\tif( strchr(s, *spt++)-s != strchr(t, *tpt++)-t)\n \t\t\treturn false;\n \t}\n \treturn true;\n }\n\nTwo strings s and t are not isomorphic if for every index... | 12 | 0 | ['C'] | 1 |
isomorphic-strings | 8ms c++ simple solution | 8ms-c-simple-solution-by-wtsanshou-o3pl | \n bool isIsomorphic(string s, string t) {\n int cs[128] = {0}, ct[128] = {0};\n for(int i=0; i<s.size(); i++)\n {\n if(cs[s[ | wtsanshou | NORMAL | 2016-06-28T18:36:29+00:00 | 2016-06-28T18:36:29+00:00 | 5,882 | false | \n bool isIsomorphic(string s, string t) {\n int cs[128] = {0}, ct[128] = {0};\n for(int i=0; i<s.size(); i++)\n {\n if(cs[s[i]] != ct[t[i]]) return false;\n else if(!cs[s[i]]) //only record once\n {\n cs[s[i]] = i+1;\n ct[t[i]] = i+... | 12 | 0 | ['C++'] | 7 |
isomorphic-strings | ✅ One Line Solution | one-line-solution-by-mikposp-y6va | (Disclaimer: this is not an example to follow in a real project - it is written for fun and training mostly)\n\n# Code #1\nTime complexity: O(n). Space complexi | MikPosp | NORMAL | 2024-04-02T11:34:30.089546+00:00 | 2024-04-02T16:30:18.111370+00:00 | 2,454 | false | (Disclaimer: this is not an example to follow in a real project - it is written for fun and training mostly)\n\n# Code #1\nTime complexity: $$O(n)$$. Space complexity: $$O(1)$$.\n```\nclass Solution:\n def isIsomorphic(self, s: str, t: str) -> bool:\n return len({*zip(s,t)})==len({*s})==len({*t})\n```\n\n# Co... | 11 | 0 | ['Hash Table', 'String', 'Python', 'Python3'] | 0 |
isomorphic-strings | [C++] Map Character to Index | c-map-character-to-index-by-awesome-bug-uqrk | Intuition\n Describe your first thoughts on how to solve this problem. \n- Convert each character to an integer, which is the appearance order in the string\n- | pepe-the-frog | NORMAL | 2024-04-02T01:24:14.856064+00:00 | 2024-04-02T01:24:14.856082+00:00 | 4,053 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n- Convert each character to an integer, which is the appearance order in the string\n- For example,\n - `egg` to `0, 1, 1`\n - `add` to `0, 1, 1`\n - `foo` to `0, 1, 1`\n - `bar` to `0, 1, 2`\n - `paper` to `0, 1, 0, 2, 3`\n - `titl... | 11 | 0 | ['Hash Table', 'C++'] | 4 |
isomorphic-strings | ✅Java Simple Solution | java-simple-solution-by-ahmedna126-iqgi | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | ahmedna126 | NORMAL | 2023-11-14T11:44:12.066942+00:00 | 2023-11-14T11:44:12.066974+00:00 | 1,356 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 11 | 0 | ['Java'] | 1 |
isomorphic-strings | Python fast and simple code | python-fast-and-simple-code-by-lukehwang-bbtx | python\nclass Solution:\n def isIsomorphic(self, s: str, t: str) -> bool:\n z = zip(s, t)\n return len(set(s)) == len(set(t)) == len(set(z))\n | lukehwang | NORMAL | 2022-09-30T14:25:15.296622+00:00 | 2022-09-30T14:25:15.296667+00:00 | 2,106 | false | ```python\nclass Solution:\n def isIsomorphic(self, s: str, t: str) -> bool:\n z = zip(s, t)\n return len(set(s)) == len(set(t)) == len(set(z))\n``` | 11 | 0 | ['Python'] | 5 |
isomorphic-strings | c++(0ms 100%) very easy, hash table, one pass (with comments) | c0ms-100-very-easy-hash-table-one-pass-w-uo6s | Runtime: 0 ms, faster than 100.00% of C++ online submissions for Isomorphic Strings.\nMemory Usage: 6.9 MB, less than 88.81% of C++ online submissions for Isomo | zx007pi | NORMAL | 2021-01-05T18:34:22.195421+00:00 | 2022-07-28T16:20:19.369662+00:00 | 2,220 | false | Runtime: 0 ms, faster than 100.00% of C++ online submissions for Isomorphic Strings.\nMemory Usage: 6.9 MB, less than 88.81% of C++ online submissions for Isomorphic Strings.\n\n```\nclass Solution {\npublic:\n bool isIsomorphic(string s, string t) {\n int sind[129] = {0}, tind[129] = {0}; //has... | 11 | 0 | ['C', 'C++'] | 3 |
isomorphic-strings | Fastest JavaScript Solution w/ Map & Set | fastest-javascript-solution-w-map-set-by-knqg | Strategy: Store each letter in t as the value of a key === to the letter in s at the same index, also add the character at this index of t to a set to ensure di | trevh | NORMAL | 2020-03-04T00:18:49.773765+00:00 | 2020-03-04T18:26:10.266596+00:00 | 2,007 | false | **Strategy**: Store each letter in *t* as the value of a key === to the letter in *s* at the same index, also add the character at this index of *t* to a set to ensure different keys can\'t map to the same letter, as that wouldn\'t be an isomorph\n```\nconst isIsomorphic = (s, t) => {\n let map = new Map(), set = ne... | 11 | 0 | ['JavaScript'] | 1 |
isomorphic-strings | Golang easy way to solve | golang-easy-way-to-solve-by-cra2yk-2gbq | using two maps to record last index.\n\ngolang\nfunc isIsomorphic(s string, t string) bool {\n\tsPattern, tPattern := map[uint8]int{}, map[uint8]int{}\n\tfor in | cra2yk | NORMAL | 2019-06-24T08:18:04.532609+00:00 | 2019-09-02T07:49:58.693264+00:00 | 1,218 | false | using two maps to record last index.\n\n```golang\nfunc isIsomorphic(s string, t string) bool {\n\tsPattern, tPattern := map[uint8]int{}, map[uint8]int{}\n\tfor index := range s {\n\t\tif sPattern[s[index]] != tPattern[t[index]] {\n\t\t\treturn false\n\t\t} else {\n\t\t\tsPattern[s[index]] = index + 1\n\t\t\ttPattern[t... | 11 | 0 | ['Go'] | 2 |
isomorphic-strings | AC HashMap Clear code (JAVA) | ac-hashmap-clear-code-java-by-zwangbo-fo6t | public class Solution {\n public boolean isIsomorphic(String s, String t) {\n if(s == null || t == null){\n return false;\n | zwangbo | NORMAL | 2015-04-29T02:59:09+00:00 | 2015-04-29T02:59:09+00:00 | 4,530 | false | public class Solution {\n public boolean isIsomorphic(String s, String t) {\n if(s == null || t == null){\n return false;\n }\n if(s.length() == 0 || t.length() == 0){\n return true;\n }\n \n Map<Character,Charact... | 11 | 1 | ['Java'] | 5 |
isomorphic-strings | C++ || O(N) || Easy to Understand with In-Depth Explanation and Examples | c-on-easy-to-understand-with-in-depth-ex-spbd | Table of Contents\n\n- TL;DR\n - Code\n - Complexity\n- In Depth Analysis\n - Intuition\n - Approach\n - Example\n\n# TL;DR\n\nCreate a map of every charac | krazyhair | NORMAL | 2022-12-06T20:59:32.742093+00:00 | 2023-01-03T15:54:03.014908+00:00 | 697 | false | #### Table of Contents\n\n- [TL;DR](#tldr)\n - [Code](#code)\n - [Complexity](#complexity)\n- [In Depth Analysis](#in-depth-analysis)\n - [Intuition](#intuition)\n - [Approach](#approach)\n - [Example](#example)\n\n# TL;DR\n\nCreate a map of every character in `s` and `t` to an index (1-indexed) and ensure that th... | 10 | 0 | ['Hash Table', 'String', 'C++'] | 1 |
isomorphic-strings | Kotlin In One Line. | kotlin-in-one-line-by-cityzouitel-f20j | kotlin\nval isIsomorphic: (String, String) -> Boolean = { s, t ->\n s.zip(t).toSet().size.run { equals(s.toSet().size) && equals(t.toSet().size) }\n}\n | CityZouitel | NORMAL | 2022-11-15T09:46:51.265698+00:00 | 2022-11-15T09:50:46.694355+00:00 | 757 | false | ```kotlin\nval isIsomorphic: (String, String) -> Boolean = { s, t ->\n s.zip(t).toSet().size.run { equals(s.toSet().size) && equals(t.toSet().size) }\n}\n``` | 10 | 0 | ['Kotlin'] | 1 |
isomorphic-strings | HashMap simple O(n) Javascript ES6 | hashmap-simple-on-javascript-es6-by-mp33-jha6 | Commentary:\n- Key idea is to ignore the char-matching but map the pattern via index-footprints\n\nconst isIsomorphic = function(s, t) {\n const hash1 = {}\n | mp3393 | NORMAL | 2021-05-18T01:40:42.066712+00:00 | 2021-05-18T01:41:01.921270+00:00 | 962 | false | `Commentary:`\n- Key idea is to ignore the char-matching but map the pattern via index-footprints\n```\nconst isIsomorphic = function(s, t) {\n const hash1 = {}\n const hash2 = {}\n for(let idx = 0; idx < s.length; idx++){\n\t\tif(hash1[s[idx]] !== hash2[t[idx]]) return false\n hash1[s[idx]] = idx\n ... | 10 | 0 | ['JavaScript'] | 4 |
isomorphic-strings | C++ 3 lines | c-3-lines-by-votrubac-nuwm | We map characters in each string to the last position it occurred. Then we check that next character in two strings occurred in the same position.\n\nNote that | votrubac | NORMAL | 2019-03-03T21:43:01.683667+00:00 | 2019-03-03T21:43:01.683752+00:00 | 650 | false | We map characters in each string to the last position it occurred. Then we check that next character in two strings occurred in the same position.\n\nNote that newly appeared characters are mapped to zero initially, so they will always match.\n\nExample for "eggnog" and "addend":\n```\n1. ms[\'e\'] == mt[\'a\'] == 0, m... | 10 | 0 | [] | 0 |
isomorphic-strings | ✅ Easiest 😎 FAANG Method Ever !!! 💥 | easiest-faang-method-ever-by-adityabhate-ap6o | \n\n# \uD83D\uDCCC Complexity :-\n- Time complexity: O(n)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(n)\n Add your space complexity he | AdityaBhate | NORMAL | 2022-12-23T17:16:10.757220+00:00 | 2022-12-23T17:16:10.757255+00:00 | 8,246 | false | \n\n# \uD83D\uDCCC Complexity :-\n- Time complexity: O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(n)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# \uD83D\uDCCC Code :- Using 2 Unordered Maps\n```\nclass Solution {\npublic:\n bool isIsomorphic(string s, string t)... | 9 | 0 | ['Hash Table', 'String', 'C++', 'Java', 'Python3'] | 6 |
isomorphic-strings | easiest solution || c-plus-plus || map || easy to understand | easiest-solution-c-plus-plus-map-easy-to-xkk6 | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | youdontknow001 | NORMAL | 2022-11-20T05:00:45.127518+00:00 | 2022-11-20T05:00:45.127554+00:00 | 1,781 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 9 | 0 | ['C++'] | 1 |
isomorphic-strings | C# Dictionary Simple Solution | c-dictionary-simple-solution-by-gregskly-72w2 | \npublic class Solution \n{\n public bool IsIsomorphic(string s, string t) \n {\n var dict = new Dictionary<char, char>();\n for(int i = 0 ; | gregsklyanny | NORMAL | 2022-11-01T08:42:35.772463+00:00 | 2022-12-12T15:43:07.862160+00:00 | 2,213 | false | ```\npublic class Solution \n{\n public bool IsIsomorphic(string s, string t) \n {\n var dict = new Dictionary<char, char>();\n for(int i = 0 ; i < s.Length; i++)\n {\n char ss = s[i];\n char st = t[i];\n if(dict.ContainsKey(ss))\n {\n ... | 9 | 0 | ['C#'] | 2 |
isomorphic-strings | Java Solution using Hashmaps | java-solution-using-hashmaps-by-manisha0-2lyd | Runtime: 22 ms, faster than 28.64% of Java online submissions for Isomorphic Strings.\nMemory Usage: 42.9 MB, less than 67.91% of Java online submissions for Is | manisha04 | NORMAL | 2022-09-16T09:11:51.731718+00:00 | 2022-09-16T09:11:51.731754+00:00 | 1,379 | false | **Runtime: 22 ms, faster than 28.64% of Java online submissions for Isomorphic Strings.\nMemory Usage: 42.9 MB, less than 67.91% of Java online submissions for Isomorphic Strings.\n**\n*If this solution was helpful to you , please upvote it*\n```\nclass Solution {\n public boolean isIsomorphic(String s, String t) {\... | 9 | 0 | ['Java'] | 2 |
isomorphic-strings | Java Solution from pratik | java-solution-from-pratik-by-pratik_pati-4c53 | Solution 1: Brute Force Approach\n\nIntuition:\n- Two strings s and t are called isomorphic:\n\t- If there is a one to one mapping possible for every character | pratik_patil | NORMAL | 2019-02-15T15:52:01.366728+00:00 | 2021-10-24T05:29:24.004335+00:00 | 1,175 | false | **Solution 1: Brute Force Approach**\n\n**Intuition:**\n- Two strings `s` and `t` are called **isomorphic**:\n\t- If there is a one to one mapping possible for every character of `s` to every character of `t`, and\n\t- If all occurrences of every character in `s` map to same character in `t`\n- A **brute-force** soluti... | 9 | 0 | [] | 0 |
isomorphic-strings | 3 lines solution for C | 3-lines-solution-for-c-by-snowleo-2ple | bool isIsomorphic(char* s, char* t) {\n for (int i = 0; i < strlen (s); i++)\n if ((strchr (s,s[i]) - s) != (strchr(t,t[i]) - t)) return false;\n | snowleo | NORMAL | 2015-12-09T14:05:30+00:00 | 2015-12-09T14:05:30+00:00 | 872 | false | bool isIsomorphic(char* s, char* t) {\n for (int i = 0; i < strlen (s); i++)\n if ((strchr (s,s[i]) - s) != (strchr(t,t[i]) - t)) return false;\n return true;\n } | 9 | 0 | [] | 1 |
isomorphic-strings | 2 map logic | 2-map-logic-by-sushilmaxbhile-m422 | ApproachMaintain 2 maps and store {s[idx]: t[idx]} and {t[idx]: s[idx]} and check if key value pairs are not duplicate as well as key value pair availableCompl | sushilmaxbhile | NORMAL | 2025-03-21T10:46:56.574380+00:00 | 2025-03-21T10:46:56.574380+00:00 | 90 | false | # Approach
Maintain 2 maps and store {s[idx]: t[idx]} and {t[idx]: s[idx]} and check if key value pairs are not duplicate as well as key value pair available
# Complexity
- Time complexity:
5 ms Beats 18.01%
- Space complexity:
4.56 MB Beats 65.88%
# Code
```golang []
func isIsomorphic(s string, t string) bool {
... | 8 | 0 | ['Go'] | 0 |
isomorphic-strings | ✅Easy✨||C++|| Beats 100% || With Explanation || | easyc-beats-100-with-explanation-by-olak-l4zo | Intuition\n Describe your first thoughts on how to solve this problem. \nThe intuition checks if two strings, s and t, are isomorphic by ensuring a one-to-one c | olakade33 | NORMAL | 2024-04-02T11:00:29.073055+00:00 | 2024-04-02T11:00:29.073088+00:00 | 1,078 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe intuition checks if two strings, s and t, are isomorphic by ensuring a one-to-one correspondence between each character in s and t using two hash maps. It iterates through both strings simultaneously, verifying existing mappings for c... | 8 | 0 | ['C++'] | 0 |
isomorphic-strings | Python one liner | Using set and zip with explanation 🔥🔥🔥 | python-one-liner-using-set-and-zip-with-k0qyo | Intuition\nTo determine if two strings s and t are isomorphic, we need to establish a one-to-one mapping between characters in s and characters in t. One way to | Saketh3011 | NORMAL | 2024-04-02T00:16:15.826311+00:00 | 2024-04-02T00:17:57.407083+00:00 | 864 | false | # Intuition\nTo determine if two strings `s` and `t` are isomorphic, we need to establish a one-to-one mapping between characters in `s` and characters in `t`. One way to approach this is to check if the number of unique characters in `s` and `t` are the same and also if the number of unique mappings between characters... | 8 | 0 | ['Python', 'Python3'] | 0 |
isomorphic-strings | C++ Optimal Solution | c-optimal-solution-by-pryansh-94cb | Intuition\n Describe your first thoughts on how to solve this problem. \nlet understand it by considering an example for say\n> str1: aax\nstr2: tty\n\nso what | pryansh_ | NORMAL | 2023-08-04T06:42:14.670545+00:00 | 2023-08-04T06:42:14.670589+00:00 | 1,285 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nlet understand it by considering an example for say\n> ***str1***: aax\n***str2***: tty\n\nso what if I map `"a"` against `"t"` and then everytime before inserting another pair `{key, value}` into the map I will check that whether the key... | 8 | 0 | ['String', 'C++'] | 1 |
isomorphic-strings | Python3 One Liner beats 95.93% with Proof | python3-one-liner-beats-9593-with-proof-64lj0 | Explanation \n\n- zip function pairs the first item of the first String with first item of the second String.\n\ns = "egg"\nt = "add"\n\nset(zip(s,t) = {(\'e\', | quibler7 | NORMAL | 2023-04-19T09:11:46.837477+00:00 | 2023-04-19T09:11:46.837516+00:00 | 1,231 | false | # Explanation \n\n- `zip` function pairs the first item of the first String with first item of the second String.\n```\ns = "egg"\nt = "add"\n\nset(zip(s,t) = {(\'e\', \'a\'), (\'g\', \'d\')}\n```\nThis was in case when two strings are Isomorphic.\n\nLet\'s see for the string when they are not Isomorphic :\n```\ns = "e... | 8 | 0 | ['String', 'Python', 'Python3'] | 2 |
isomorphic-strings | Scala simple solution | scala-simple-solution-by-xdavidrtx-kgfr | \n def isIsomorphic(s: String, t: String): Boolean = {\n val mapped = s.zip(t).toMap.map(_.swap)\n t.flatMap(mapped.get(_)).mkString == s\n}\n\n | xDavidRTx | NORMAL | 2022-09-09T15:47:46.940654+00:00 | 2022-09-09T15:47:46.940747+00:00 | 213 | false | ```\n def isIsomorphic(s: String, t: String): Boolean = {\n val mapped = s.zip(t).toMap.map(_.swap)\n t.flatMap(mapped.get(_)).mkString == s\n}\n```\n | 8 | 0 | ['Scala'] | 0 |
isomorphic-strings | Mapless TypeScript Solution - 100% Memory | mapless-typescript-solution-100-memory-b-j0n5 | To minimize memory usage, we can eliminate the need to create maps. Instead of tracking what characters map to we can make sure that for each position in the st | WAB2 | NORMAL | 2022-07-04T22:48:55.351941+00:00 | 2022-07-04T22:48:55.351988+00:00 | 1,161 | false | To minimize memory usage, we can eliminate the need to create maps. Instead of tracking what characters map to we can make sure that for each position in the strings the first occurrence of the current character matches for both s and t.\n\n```typescript\nfunction isIsomorphic(s: string, t: string): boolean {\n // i... | 8 | 1 | ['TypeScript'] | 5 |
isomorphic-strings | Easy Mapping C++ | easy-mapping-c-by-tusharkhanna575-yp19 | \nclass Solution {\npublic:\n bool isIsomorphic(string s, string t) {\n if(s.size()!=t.size())\n {\n return 0;\n }\n c | tusharkhanna575 | NORMAL | 2022-06-21T14:51:56.813425+00:00 | 2022-06-21T14:51:56.813467+00:00 | 1,322 | false | ```\nclass Solution {\npublic:\n bool isIsomorphic(string s, string t) {\n if(s.size()!=t.size())\n {\n return 0;\n }\n char map_s[128]={0};\n char map_t[128]={0};\n int length=s.size();\n for(int i=0;i<length;i++)\n {\n if(map_s[s[i]]!=ma... | 8 | 0 | ['C', 'C++'] | 0 |
isomorphic-strings | Python single line beats 97% | python-single-line-beats-97-by-diksha_ch-r5jr | \nclass Solution:\n def isIsomorphic(self, s: str, t: str) -> bool: \n return len(set(s))==len(set(t))==len(set(zip(s,t)))\n \n | diksha_choudhary | NORMAL | 2021-12-16T05:06:45.712236+00:00 | 2021-12-16T05:06:45.712279+00:00 | 855 | false | ```\nclass Solution:\n def isIsomorphic(self, s: str, t: str) -> bool: \n return len(set(s))==len(set(t))==len(set(zip(s,t)))\n \n``` | 8 | 0 | ['Python', 'Python3'] | 1 |
isomorphic-strings | [Python] 2 dicts solution, explained | python-2-dicts-solution-explained-by-dba-33mj | Go symbol by symbol and add direct and inverse connections to hash tables d1 and d2.\n1. If i not in d1 and j in d2, it means, that something is wrong, we have | dbabichev | NORMAL | 2021-07-12T08:17:16.036293+00:00 | 2021-07-12T08:17:16.036327+00:00 | 455 | false | Go symbol by symbol and add direct and inverse connections to hash tables `d1` and `d2`.\n1. If `i not in d1` and `j in d2`, it means, that something is wrong, we have case `a -> x`, `b -> x`, return `False`.\n2. If `i not in d1` and `j not in d2`, it means that we see this pair first time, update both dictionaries.\n3... | 8 | 0 | ['Hash Table'] | 1 |
isomorphic-strings | Python3 - one-liner with index | python3-one-liner-with-index-by-the_snow-0nef | ```\nclass Solution:\n def isIsomorphic(self, s: str, t: str) -> bool:\n \n return [s.index(ch) for ch in s] == [t.index(ch) for ch in t]\n | the_snow | NORMAL | 2021-03-25T13:17:02.077925+00:00 | 2021-03-25T13:24:36.174226+00:00 | 621 | false | ```\nclass Solution:\n def isIsomorphic(self, s: str, t: str) -> bool:\n \n return [s.index(ch) for ch in s] == [t.index(ch) for ch in t]\n | 8 | 0 | ['Python'] | 0 |
isomorphic-strings | C++ 8 ms beats 67.75% one path, two mapping arrays | c-8-ms-beats-6775-one-path-two-mapping-a-x3nh | \tbool isIsomorphic(string s, string t)\n\t{\n\t\tvector mapStoT(127, 0);\n\t\tvector mapTtoS(127, 0);\n\t\tint len = s.length();\n\t\t\n\t\tfor (int i = 0; i < | petrik | NORMAL | 2016-05-20T20:34:53+00:00 | 2016-05-20T20:34:53+00:00 | 1,916 | false | \tbool isIsomorphic(string s, string t)\n\t{\n\t\tvector<char> mapStoT(127, 0);\n\t\tvector<char> mapTtoS(127, 0);\n\t\tint len = s.length();\n\t\t\n\t\tfor (int i = 0; i < len; ++i)\n\t\t{\n\t\t\tchar s_char = s[i], t_char = t[i];\n\t\t\tif (mapStoT[s_char] == 0 && mapTtoS[t_char] == 0)\n\t\t\t{\n\t\t\t\tmapStoT[s_cha... | 8 | 1 | [] | 2 |
isomorphic-strings | Easiest Beginner Friendly Approach | easiest-beginner-friendly-approach-by-am-1bd6 | ✅ Explaination of the Code:
Pehle size compare kiya, agar s aur t ka size alag hai, to directly false return kar diya.
Pehle loop me sabhi characters ko ~ se | aman8558 | NORMAL | 2025-03-31T02:12:42.695013+00:00 | 2025-04-02T12:06:39.633009+00:00 | 739 | false | # **✅ Explaination of the Code:**
1. Pehle size compare kiya, agar s aur t ka size alag hai, to directly false return kar diya.
2. Pehle loop me sabhi characters ko ~ se initialize kiya.
3. Dusre loop me:
- Agar s[i] map me pehli baar aa raha hai (m[s[i]] == '~'), to uska mapping t[i] se kar diya.
- Agar al... | 7 | 0 | ['Hash Table', 'String', 'C++'] | 2 |
isomorphic-strings | 🧩✨ Python Solution | Isomorphic Strings | ⚡ 99% Runtime | 📦 O(n) Space 💡 | python-solution-isomorphic-strings-99-ru-z2d9 | Intuition\n Describe your first thoughts on how to solve this problem. \nThe problem requires checking if two strings s and t are isomorphic, meaning each chara | LinhNguyen310 | NORMAL | 2024-08-12T16:55:59.975515+00:00 | 2024-08-12T16:55:59.975536+00:00 | 652 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe problem requires checking if two strings s and t are isomorphic, meaning each character in s can be replaced to get t, with no two characters mapping to the same character, except possibly to itself.\n\n\n# Approach\n<!-- Describe you... | 7 | 0 | ['Hash Table', 'String', 'Python', 'Python3'] | 0 |
isomorphic-strings | Best/Easiest Java Solution🔥 | besteasiest-java-solution-by-thepriyansh-ab4f | Intuition\nThe idea is to iterate through each character of both strings simultaneously and maintain mappings between characters of string s and characters of s | thepriyanshpal | NORMAL | 2024-04-02T04:11:22.110697+00:00 | 2024-04-02T04:11:22.110718+00:00 | 1,086 | false | # Intuition\nThe idea is to iterate through each character of both strings simultaneously and maintain mappings between characters of string s and characters of string t. We use two hash maps to keep track of mappings in both directions (from s to t and from t to s). At each step, we check if the current characters in ... | 7 | 0 | ['Java'] | 3 |
isomorphic-strings | beats 100% || learn intuition building | beats-100-learn-intuition-building-by-ab-u0lm | Intuition\n Describe your first thoughts on how to solve this problem. \n# pls upvote guys \n# Approach\n Describe your approach to solving the problem. \nAbsol | Abhishekkant135 | NORMAL | 2024-04-02T03:40:21.754525+00:00 | 2024-04-02T03:40:21.754556+00:00 | 1,334 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n# pls upvote guys \n# Approach\n<!-- Describe your approach to solving the problem. -->\nAbsolutely, here\'s a breakdown of the code that determines if two strings `s` and `t` are isomorphic:\n\n**Functionality:**\n\n- It checks if two st... | 7 | 0 | ['Array', 'Java'] | 5 |
isomorphic-strings | Mapping Characters to check for Structural Equality | mapping-characters-to-check-for-structur-wd6x | Intuition\n Describe your first thoughts on how to solve this problem. \n1) The code aims to determine whether two strings s and t are isomorphic, meaning that | harshsri1602 | NORMAL | 2024-04-02T00:59:08.080684+00:00 | 2024-04-02T00:59:08.080703+00:00 | 68 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n1) The code aims to determine whether two strings s and t are isomorphic, meaning that each character in s can be replaced with another character in t while preserving the order.\n2) To achieve this, the code maps each character in both s... | 7 | 1 | ['Hash Table', 'String', 'C++'] | 0 |
isomorphic-strings | Simple and detailed explanation using hashmap | simple-and-detailed-explanation-using-ha-obd2 | Intuition\nWe need to establish bidirectional mappings between characters in the two strings to check if they are isomorphic. By using two unordered maps, we ca | fruity_226 | NORMAL | 2024-03-03T18:18:45.562484+00:00 | 2024-03-03T18:18:45.562535+00:00 | 1,632 | false | # Intuition\nWe need to establish bidirectional mappings between characters in the two strings to check if they are isomorphic. By using two unordered maps, we can track these mappings and return `false` if any inconsistency is found; otherwise, we return `true`.\n\n# Approach\n- `Initialize Maps:` Start by creating tw... | 7 | 0 | ['C++'] | 2 |
isomorphic-strings | C++ easy solution | Beats 100% | Hash Table | Optimised approach | c-easy-solution-beats-100-hash-table-opt-ag1g | Please upvote to motivate me to write more solutions.\n\n\n\nIntuition\nApproach\nComplexity\nTime complexity:\nO(|str1|+|str2|).\n\nSpace complexity:\nO(Number | Kanishq_24je3 | NORMAL | 2024-01-10T18:44:19.832478+00:00 | 2024-01-10T18:44:19.832499+00:00 | 1,630 | false | # Please upvote to motivate me to write more solutions.\n\n\n\nIntuition\nApproach\nComplexity\nTime complexity:\nO(|str1|+|str2|).\n\nSpace complexity:\nO(Number of different characters).\n\n\n# Code\n```\nclass Solution {\npublic:\n bool isIsomorphic(string s, string t) {\n if (s.size() != t.size()) {\n ... | 7 | 0 | ['Hash Table', 'String', 'C++'] | 0 |
isomorphic-strings | ✅|||🔥🔥Faster than 93%🔥🔥|||Simple and easy python solution with explanation ✅✅✅🔥 | faster-than-93simple-and-easy-python-sol-4n4t | PLEASE UPVOTE IT TAKES A LOT OF TIME AND EFFORT TO MAKE THIS\n\n# Intuition\nThe goal is to determine if two strings, s and t, are isomorphic. Two strings are c | user0517qU | NORMAL | 2024-01-10T04:54:55.678558+00:00 | 2024-01-10T04:54:55.678592+00:00 | 1,157 | false | # PLEASE UPVOTE IT TAKES A LOT OF TIME AND EFFORT TO MAKE THIS\n\n# Intuition\nThe goal is to determine if two strings, s and t, are isomorphic. Two strings are considered isomorphic if there exists a one-to-one mapping of characters from one string to the other.\n\n# Approach\nTo solve this problem, we can use two dic... | 7 | 0 | ['Python3'] | 0 |
isomorphic-strings | C# - Hash Map O(n) with Explanation | c-hash-map-on-with-explanation-by-vflawl-3ckx | Intuition\nTo determine if two strings, s and t, are isomorphic, we need to check if we can replace the characters in s with the characters in t while preservin | vFlawless | NORMAL | 2023-05-06T13:32:12.166407+00:00 | 2023-05-08T14:51:56.685196+00:00 | 1,113 | false | # Intuition\nTo determine if two strings, `s` and `t`, are isomorphic, we need to check if we can replace the characters in `s` with the characters in `t` while preserving the order of characters. This implies a one-to-one mapping between characters of `s` and `t`. We can utilize a hash map to keep track of the mapping... | 7 | 0 | ['C#'] | 1 |
isomorphic-strings | Easy to understand Java Solution Using HashMap data structure (Explained !!!) 💡 | easy-to-understand-java-solution-using-h-3j2r | Approach\n- char to char comparision between two strings using two different Hashmaps due to the nature of the datastructure.\n\n# Complexity\n- Time complexity | AbirDey | NORMAL | 2023-04-17T15:09:41.847367+00:00 | 2023-04-17T15:09:41.847413+00:00 | 441 | false | # Approach\n- char to char comparision between two strings using two different Hashmaps due to the nature of the datastructure.\n\n# Complexity\n- Time complexity: O(n)\n\n- Space complexity: O(n)\n\n# Code\n```\nclass Solution {\n public boolean isIsomorphic(String s, String t) {\n \n // Two Hashmaps ... | 7 | 0 | ['Hash Table', 'String', 'Java'] | 1 |
isomorphic-strings | Well Explained Code || 2 HashMaps used in JAVA✅ | well-explained-code-2-hashmaps-used-in-j-sfkk | \n\n# Approach\nThis code is an implementation of a solution to determine if two strings, s and t, are isomorphic. Two strings are considered isomorphic if the | sakshamkaushiik | NORMAL | 2023-02-10T08:42:01.417698+00:00 | 2023-02-10T08:42:01.417744+00:00 | 547 | false | \n\n# Approach\nThis code is an implementation of a solution to determine if two strings, s and t, are isomorphic. Two strings are considered isomorphic if the characters in one string can be replaced to get the other string.\n\nThe approach used in this solution is to use two HashMaps, map1 and map2. map1 maps each ch... | 7 | 0 | ['Hash Table', 'Java'] | 1 |
isomorphic-strings | [Python] Easy Hash Table solution, beats 95% | python-easy-hash-table-solution-beats-95-q95o | \u2705 Upvote if it helps !\n\n# Approach\n Describe your approach to solving the problem. \n- If the sizes of "s" and "t" aren\'t equal, return False\n- I used | jean_am | NORMAL | 2023-01-15T12:29:09.062191+00:00 | 2023-02-14T08:58:57.798961+00:00 | 2,499 | false | ### \u2705 Upvote if it helps !\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n- If the sizes of *"s"* and *"t"* aren\'t equal, ```return False```\n- I used a **Hash Table** called *"equivalence"* in order to track if a character in *"s"* has always the same equivalent character in *"t"*.\n ... | 7 | 0 | ['Hash Table', 'Python'] | 1 |
minimum-increments-for-target-multiples-in-an-array | DP WITH BITMASK ✅✅✅Easy To Understand C++ Code | dp-with-bitmask-easy-to-understand-c-cod-5cj1 | IntuitionKey Insight
Each element in target must have at least one multiple in nums.
Instead of treating each target element individually, we can group them | insane_prem | NORMAL | 2025-02-02T04:07:44.187230+00:00 | 2025-02-02T06:50:39.161373+00:00 | 3,647 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
Key Insight
- Each element in target must have at least one multiple in nums.
- Instead of treating each target element individually, we can group them into subsets and find the least common multiple (LCM) for each subset. This helps us de... | 30 | 1 | ['Dynamic Programming', 'Bit Manipulation', 'Bitmask', 'C++'] | 7 |
minimum-increments-for-target-multiples-in-an-array | [Java/C++/Python] Easy and Concise | Beats 100% | Full Explanation | javacpython-easy-and-concise-by-_ashish_-v96k | Step-by-Step Explanation:
Understanding the Problem:
We are given two arrays:
nums[]: Represents numbers we can modify.
target[]: Contains numbers for whic | _Ashish_Lahane_ | NORMAL | 2025-02-02T05:18:10.471818+00:00 | 2025-02-02T06:15:09.815410+00:00 | 1,957 | false | # **Step-by-Step Explanation**:
1. **Understanding the Problem**:
We are given two arrays:
- `nums[]`: Represents numbers we can modify.
- `target[]`: Contains numbers for which we need to adjust elements in `nums` so that their LCM constraints are met.
The goal is to **modify elements in** `nums[]` by i... | 14 | 1 | ['Dynamic Programming', 'Bitmask', 'Python', 'C++', 'Java'] | 3 |
minimum-increments-for-target-multiples-in-an-array | Combinations | combinations-by-votrubac-ez7h | Intuition
We only have (up to) 4 elements in target.
An element in nums could be a multiple of several elements from target.
Approach
Generate all combinations | votrubac | NORMAL | 2025-02-02T04:23:05.717136+00:00 | 2025-02-02T04:46:31.429295+00:00 | 1,927 | false | # Intuition
1. We only have (up to) 4 elements in `target`.
2. An element in `nums` could be a multiple of several elements from `target`.
# Approach
1. Generate all combinations of target elements.
- [4], [3, 1], [2, 2], [2, 1, 1], and [1, 1, 1, 1]
- we can use `combinations` to do that.
2. For each combinatio... | 13 | 1 | ['Python3'] | 2 |
minimum-increments-for-target-multiples-in-an-array | Striver approach take or nottake C++ Solution | striver-approach-take-or-nottake-c-solut-kfnv | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | aero_coder | NORMAL | 2025-02-03T10:38:57.259108+00:00 | 2025-02-03T10:42:57.821222+00:00 | 1,174 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
`... | 8 | 0 | ['Math', 'Dynamic Programming', 'C++'] | 1 |
minimum-increments-for-target-multiples-in-an-array | C++ | DP + BitMask | Explanation | With Intuition and Approach | Best Solution | c-dp-bitmask-explanation-with-intuition-qthkb | IntuitionThe problem appears to be finding the minimum total increments needed to make each number in nums divisible by at least one number in target. The use o | smitvavliya | NORMAL | 2025-02-02T13:03:08.532797+00:00 | 2025-02-02T13:30:18.239726+00:00 | 531 | false | # Intuition
###### The problem appears to be finding the minimum total increments needed to make each number in nums divisible by at least one number in target. The use of bitmasks suggests we need to track which target numbers we still need to consider for each position, and dynamic programming indicates we need to av... | 7 | 1 | ['Dynamic Programming', 'Memoization', 'Bitmask', 'C++'] | 1 |
minimum-increments-for-target-multiples-in-an-array | [Python3] mask dp | python3-mask-dp-by-ye15-dppt | IntuitionUse DP. Here, we define the states as (i, m) where i indicates the ith number in nums is being looked at and m is a bit mask whose set bits correspond | ye15 | NORMAL | 2025-02-02T04:03:32.455100+00:00 | 2025-02-02T06:24:53.594390+00:00 | 642 | false | # Intuition
Use DP. Here, we define the states as `(i, m)` where `i` indicates the `i`th number in `nums` is being looked at and `m` is a bit mask whose set bits correspond to the numbers in `target` whose multiple is already included. Here, `dp[i][m]` is the minimum ops to make `nums[i:]` to include all multiple of ta... | 7 | 1 | ['Python3'] | 1 |
minimum-increments-for-target-multiples-in-an-array | DP with BitMasking || O(16*16*n) || Must check || LCM of set bits indexed element | dp-with-bitmasking-o1616n-must-check-sim-im1e | Complexity
Time complexity:
O(16∗16∗n)
Space complexity:
O(n)Code | Priyanshu_pandey15 | NORMAL | 2025-02-02T04:02:37.622793+00:00 | 2025-02-03T07:15:26.775310+00:00 | 944 | false |
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
$$O(16*16*n)$$
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
$$O(n)$$
# Code
```java []
class Solution {
static public int minimumIncrements(int[] nums, int[] target) {
Long[][] dp = new Long[... | 6 | 1 | ['Dynamic Programming', 'Bit Manipulation', 'Java'] | 3 |
minimum-increments-for-target-multiples-in-an-array | Simple & Easy to understand Solution | Dynamic Programming | simple-easy-to-understand-solution-dynam-yfq2 | IntuitionSince (1<=m<=4) && (1<=n<=1e9) so a clear intution of bit manipulation was there. Why dp? We can see that after some dry runs it's never sure whether b | Ayu1_2 | NORMAL | 2025-02-04T10:27:43.163949+00:00 | 2025-02-04T10:27:43.163949+00:00 | 257 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
Since (1<=m<=4) && (1<=n<=1e9) so a clear intution of bit manipulation was there. Why dp? We can see that after some dry runs it's never sure whether by taking curr element ans will be optimal or not. So, it's a hint towards dp.
# Approach
... | 5 | 0 | ['Array', 'Math', 'Dynamic Programming', 'Greedy', 'Bit Manipulation', 'Number Theory', 'Bitmask', 'C++'] | 0 |
minimum-increments-for-target-multiples-in-an-array | Scuffed solution | scuffed-solution-by-chitraksh24-a9ev | Code | chitraksh24 | NORMAL | 2025-02-02T04:03:09.661438+00:00 | 2025-02-02T04:03:09.661438+00:00 | 189 | false | # Code
```python3 []
from itertools import permutations
class Solution:
def minimumIncrements(self, nums: List[int], target: List[int]) -> int:
target = list(set(target))
answer = float("inf")
nums.sort(reverse=True)
concretenumslist = list(nums)
for targs in permutations(ta... | 3 | 0 | ['Python3'] | 2 |
minimum-increments-for-target-multiples-in-an-array | Python | Recursion | Memoization | python-recursion-memoization-by-pranav74-uypg | Complexity
Time complexity: O(2M∗M∗N)
Space complexity: O(M∗2M)
Code | pranav743 | NORMAL | 2025-02-06T18:33:42.673847+00:00 | 2025-02-11T06:58:19.409715+00:00 | 98 | false | # Complexity
- Time complexity: $$O(2^
M
∗M∗N
)$$
- Space complexity: $$O(M∗2^
M
)$$
# Code
```python3 []
class Solution:
def minimumIncrements(self, nums: List[int], target: List[int]) -> int:
lcm_map = defaultdict(int)
index_map = {1: 0, 2: 1, 4: 2, 8: 3}
target_len = len(target)
... | 2 | 0 | ['Dynamic Programming', 'Recursion', 'Memoization', 'Bitmask', 'Python3'] | 0 |
minimum-increments-for-target-multiples-in-an-array | DP with Bitmasking | Easy Solution | dp-with-bitmasking-easy-solution-by-prav-5aoo | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | praveen1208 | NORMAL | 2025-02-03T14:34:29.505713+00:00 | 2025-02-03T14:36:31.582663+00:00 | 101 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
`... | 2 | 0 | ['C++'] | 0 |
minimum-increments-for-target-multiples-in-an-array | Java DP | java-dp-by-realstar-48rg | IntuitionIf target length is 1, then just go through nums and find each value's cost, return the min one.
If target legnth is 2, then need at least n * 3 dp val | realstar | NORMAL | 2025-02-03T04:23:49.579169+00:00 | 2025-02-03T04:23:49.579169+00:00 | 120 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
If target length is 1, then just go through nums and find each value's cost, return the min one.
If target legnth is 2, then need at least n * 3 dp value (or 3 value since we only need prev's value, not other historical ones):
First one: sa... | 2 | 0 | ['Java'] | 0 |
minimum-increments-for-target-multiples-in-an-array | EASY TO UNDERSTAND BITMASK DP in C++ with INTUITION and Explanation | easy-to-understand-bitmask-dp-in-c-with-q4olu | IntuitionWe have m+1(where m is size of target array) choices for each nums[i]:
1.Do not change nums[i]
2.Change nums[i] to nearest multiple of target[0].
3.Cha | Kunal_Sobti | NORMAL | 2025-02-07T13:10:23.684518+00:00 | 2025-02-07T13:10:23.684518+00:00 | 72 | false | # Intuition
We have m+1(where m is size of target array) choices for each nums[i]:
1.Do not change nums[i]
2.Change nums[i] to nearest multiple of target[0].
3.Change nums[i] to nearest multiple of target[1].
...and so on.
Hence it is a DP problem.
Now a single nums[i] can be a common multiple of more than one targets... | 1 | 0 | ['Dynamic Programming', 'Bit Manipulation', 'Bitmask', 'C++'] | 1 |
minimum-increments-for-target-multiples-in-an-array | C++ | Beats 96% | Submask Enumeration | Bitmasking | O(n*m*3^m + 2^m) | Better Complexity | c-beats-96-submask-enumeration-bitmaskin-5f14 | Complexity
Time complexity: O(n∗m∗3m)
Please read all-submasks for more details on how to arrive at this complexity.
Code | lord-chicken | NORMAL | 2025-02-05T11:49:02.173682+00:00 | 2025-02-05T13:56:04.275391+00:00 | 69 | false | # Complexity
- Time complexity: $$O(n*m*3^m)$$
> Please read [all-submasks](https://cp-algorithms.com/algebra/all-submasks.html) for more details on how to arrive at this complexity.
# Code
```cpp []
class Solution {
int M, m, n;
vector<long long> mask_to_lcm;
int solve(vector<int>& nums, vector<int>& ... | 1 | 0 | ['C++'] | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.