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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
first-letter-to-appear-twice | using Hashtable | using-hashtable-by-ganjinaveen-1ns0 | 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 | GANJINAVEEN | NORMAL | 2023-02-28T19:16:17.010227+00:00 | 2023-02-28T19:16:17.010268+00:00 | 889 | 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)$$ --... | 4 | 0 | ['Python3'] | 1 |
first-letter-to-appear-twice | Java Easiest Solution | java-easiest-solution-by-janhvi__28-n9th | \n# Complexity\n- Time complexity: O(n)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity:O(1)\n Add your space complexity here, e.g. O(n) \n\n# | Janhvi__28 | NORMAL | 2022-12-08T17:40:14.606893+00:00 | 2022-12-08T19:03:10.068831+00:00 | 401 | false | \n# Complexity\n- Time complexity: O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n public char repeatedCharacter(String s) {\n int[] cnt = new int[26];\n for (char c : s.toC... | 4 | 0 | ['Java'] | 0 |
first-letter-to-appear-twice | Java and C++ solution without using map/set | java-and-c-solution-without-using-mapset-5hj5 | Java solution:\n\npublic char repeatedCharacter(String s) {\n int freq[]=new int[26]; //26 size array to store the occurrence of lowercase characters | dmanocha464 | NORMAL | 2022-09-14T06:46:31.951872+00:00 | 2022-09-14T06:47:03.592583+00:00 | 658 | false | Java solution:\n```\npublic char repeatedCharacter(String s) {\n int freq[]=new int[26]; //26 size array to store the occurrence of lowercase characters \n int temp;\n for(int i=0;i<s.length();i++){\n temp=s.charAt(i)-\'a\'; //will give 0 to 25 for a to z \n if(freq[te... | 4 | 0 | ['String', 'C', 'Java'] | 0 |
first-letter-to-appear-twice | 100% fastest CPP solution using hashing and ascii values | 100-fastest-cpp-solution-using-hashing-a-cozy | \nclass Solution {\npublic:\n char repeatedCharacter(string s) {\n\t\tint n = s.length(); //string length\n int arr[26]={0}; //created an array | sahil1208 | NORMAL | 2022-08-18T18:24:52.014238+00:00 | 2022-08-18T18:30:55.116309+00:00 | 154 | false | ```\nclass Solution {\npublic:\n char repeatedCharacter(string s) {\n\t\tint n = s.length(); //string length\n int arr[26]={0}; //created an array for 26 alphabets from \'a\' to \'z\' and initialize with 0\n for(int i=0;i<n;i++){ //Iterating over given string\n int num = s[i]-\'a\';... | 4 | 0 | ['C'] | 0 |
first-letter-to-appear-twice | Java || HashMap || V. Easy Code || Easy 2 Understand | java-hashmap-v-easy-code-easy-2-understa-wbiq | class Solution {\n\n public char repeatedCharacter(String s) {\n HashMap hm = new HashMap<>();\n int idx = 0;\n for(int i=0;i<s.length() | Muskan_Malhotra | NORMAL | 2022-08-16T16:52:30.553627+00:00 | 2022-08-16T16:52:30.553668+00:00 | 685 | false | class Solution {\n\n public char repeatedCharacter(String s) {\n HashMap<Character,Integer> hm = new HashMap<>();\n int idx = 0;\n for(int i=0;i<s.length();i++){\n char c = s.charAt(i);\n if(hm.containsKey(c) ){\n \n idx = i;\n ... | 4 | 0 | ['Java'] | 1 |
first-letter-to-appear-twice | Python (Simple Set) | python-simple-set-by-rnotappl-6ode | \n def repeatedCharacter(self, s):\n seen = set()\n \n for i in s:\n if i not in seen:\n seen.add(i)\n | rnotappl | NORMAL | 2022-08-16T14:24:48.475868+00:00 | 2022-08-16T14:24:48.475910+00:00 | 307 | false | \n def repeatedCharacter(self, s):\n seen = set()\n \n for i in s:\n if i not in seen:\n seen.add(i)\n else:\n return i\n | 4 | 0 | [] | 0 |
first-letter-to-appear-twice | Python | Easy Solution✅ | python-easy-solution-by-gmanayath-yk8r | \ndef repeatedCharacter(self, s: str) -> str:\n st = set()\n for i in range(len(s)): # s = "abccbaacz"\n if s[i] in st: # condition wi | gmanayath | NORMAL | 2022-08-16T13:12:54.480565+00:00 | 2022-12-22T16:49:14.193121+00:00 | 983 | false | ```\ndef repeatedCharacter(self, s: str) -> str:\n st = set()\n for i in range(len(s)): # s = "abccbaacz"\n if s[i] in st: # condition will be true when i = 3\n return s[i] # return c\n else:\n st.add(s[i]) # st = {a,b,c}\n``` | 4 | 0 | ['Python', 'Python3'] | 0 |
first-letter-to-appear-twice | Simple Java solution 0ms faster than 100% | simple-java-solution-0ms-faster-than-100-1rpy | \nclass Solution {\n public char repeatedCharacter(String s) \n {\n HashSet<Character> set = new HashSet<>();\n char ch;\n for(int i= | nomaanansarii100 | NORMAL | 2022-08-16T10:03:58.446917+00:00 | 2022-08-16T10:03:58.446947+00:00 | 488 | false | ```\nclass Solution {\n public char repeatedCharacter(String s) \n {\n HashSet<Character> set = new HashSet<>();\n char ch;\n for(int i=0; i<s.length();i++)\n {\n ch= s.charAt(i);\n \n if(set.contains(ch))\n return ch;\n \n ... | 4 | 0 | ['Java'] | 0 |
first-letter-to-appear-twice | Python Elegant & Short | O(n) time & O(1) space | Set | python-elegant-short-on-time-o1-space-se-y01x | \tdef repeatedCharacter(self, s: str) -> str:\n\t\tseen = set()\n\n\t\tfor c in s:\n\t\t\tif c in seen:\n\t\t\t\treturn c\n\t\t\tseen.add(c)\n | Kyrylo-Ktl | NORMAL | 2022-08-13T19:14:15.641911+00:00 | 2022-08-13T19:14:27.858099+00:00 | 543 | false | \tdef repeatedCharacter(self, s: str) -> str:\n\t\tseen = set()\n\n\t\tfor c in s:\n\t\t\tif c in seen:\n\t\t\t\treturn c\n\t\t\tseen.add(c)\n | 4 | 0 | ['Ordered Set', 'Python', 'Python3'] | 0 |
first-letter-to-appear-twice | Short JavaScript Solution Using a Set Object | short-javascript-solution-using-a-set-ob-dhvr | Found this solution helpful? Consider showing support by upvoting this post.\nHave a question? Kindly leave a comment below.\nThank you and happy hacking!\n\nva | sronin | NORMAL | 2022-07-24T16:18:39.348258+00:00 | 2022-07-25T05:08:54.096291+00:00 | 474 | false | Found this solution helpful? Consider showing support by upvoting this post.\nHave a question? Kindly leave a comment below.\nThank you and happy hacking!\n```\nvar repeatedCharacter = function(s) {\n let letterSet = new Set()\n \n for(let i = 0; i< s.length;i++){\n if(letterSet.has(s[i])) return s[i]\n... | 4 | 0 | ['Ordered Set', 'JavaScript'] | 0 |
first-letter-to-appear-twice | O(n) time | O(1) | 100% faster | memory usage less than 100% | on-time-o1-100-faster-memory-usage-less-rdc35 | ```\n var repeatedCharacter = function(s) {\n const m = {};\n \n for(let i of s) {\n\t\tm[i] = m[i] + 1 || 1; \n \n if(m[i] == 2) {\n | asadullakkh | NORMAL | 2022-07-24T05:52:38.476161+00:00 | 2022-09-18T18:45:22.763134+00:00 | 579 | false | ```\n var repeatedCharacter = function(s) {\n const m = {};\n \n for(let i of s) {\n\t\tm[i] = m[i] + 1 || 1; \n \n if(m[i] == 2) {\n return i;\n }\n }\n}; | 4 | 0 | ['JavaScript'] | 2 |
first-letter-to-appear-twice | [Python3] mask | python3-mask-by-ye15-cufn | Please pull this commit for solutions of weekly 303. \n\n\nclass Solution:\n def repeatedCharacter(self, s: str) -> str:\n mask = 0 \n for ch i | ye15 | NORMAL | 2022-07-24T04:02:19.906399+00:00 | 2022-07-24T04:17:13.749188+00:00 | 427 | false | Please pull this [commit](https://github.com/gaosanyong/leetcode/commit/d61cd3ed09bbf59fd619802a6e861a516ec17094) for solutions of weekly 303. \n\n```\nclass Solution:\n def repeatedCharacter(self, s: str) -> str:\n mask = 0 \n for ch in s: \n if mask & 1<<ord(ch)-97: return ch \n ... | 4 | 0 | ['Python3'] | 1 |
first-letter-to-appear-twice | simple bit-masking | interesting soln | checkout once... | linear time soln | simple-bit-masking-interesting-soln-chec-5iq8 | \n\n# Code\n\nclass Solution {\npublic:\n char repeatedCharacter(string s) {\n int p=0;\n for(auto it:s){\n if((p&(1<<(it-\'a\'))))r | shivamaurya1910 | NORMAL | 2024-02-15T11:09:51.659403+00:00 | 2024-02-15T11:09:51.659433+00:00 | 140 | false | \n\n# Code\n```\nclass Solution {\npublic:\n char repeatedCharacter(string s) {\n int p=0;\n for(auto it:s){\n if((p&(1<<(it-\'a\'))))return it;\n p=(p|(1<<(it-\'a\')));\n }\n return \'a\';\n }\n};\n``` | 3 | 0 | ['Bit Manipulation', 'C++'] | 0 |
first-letter-to-appear-twice | 💀☠️🔥Easiest Fastest 🔥 Beats 💯.C++ 🔥 Python3 🐍🔥Java 🔥C 🔥 Python🐍🔥Solution Explained 🧠🎯🏆 | easiest-fastest-beats-c-python3-java-c-p-55md | Intuition\n\n\n\n\nC++ []\nclass Solution {\npublic:\n char repeatedCharacter(string s) {\n unordered_map<char, int> mp;\n for (auto& c : s) {\ | Edwards310 | NORMAL | 2024-02-10T08:04:15.436467+00:00 | 2024-04-18T03:51:23.012762+00:00 | 150 | false | # Intuition\n\n\n![Screenshot 2024-03-01 08595... | 3 | 0 | ['Hash Table', 'String', 'Bit Manipulation', 'C', 'Counting', 'Python', 'C++', 'Java', 'Python3'] | 2 |
first-letter-to-appear-twice | Java || 100% beats || HashSet || ❤️ | java-100-beats-hashset-by-saurabh_kumar1-7hy7 | 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 | saurabh_kumar1 | NORMAL | 2023-08-22T15:40:58.305194+00:00 | 2023-08-22T15:40:58.305216+00:00 | 380 | 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:0(N)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:0(1)\n<!-- Add your space complexity here, e.g. $$O... | 3 | 0 | ['Java'] | 1 |
first-letter-to-appear-twice | Easiest solution in python | easiest-solution-in-python-by-mohammad_t-8ki9 | 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 | Mohammad_tanveer | NORMAL | 2023-02-28T15:20:22.945211+00:00 | 2023-02-28T15:20:22.945261+00:00 | 1,384 | 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)$$ --... | 3 | 0 | ['Python3'] | 1 |
first-letter-to-appear-twice | C++ approach O(N) Beats 100% || With Explanation || Without hash | c-approach-on-beats-100-with-explanation-keea | Intuition\n Describe your first thoughts on how to solve this problem. \nCreate a count array which store frequency of all character of string \nCharcter whose | Utkarsh_Raghuvanshi | NORMAL | 2023-02-17T19:35:39.511806+00:00 | 2023-02-17T19:35:39.511832+00:00 | 787 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nCreate a count array which store frequency of all character of string \nCharcter whose frequency becomes 2 return that character \n# Approach\n1> We simply make a count array which store frequency of all character of string \n2> As soon a... | 3 | 0 | ['C++'] | 2 |
first-letter-to-appear-twice | ✅ *HASHMAP*|*HASHSET* | *Easiest One*|*Java*| please Upvote if it helps🆙👆 | hashmaphashset-easiest-onejava-please-up-tst3 | 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 | shivanigam | NORMAL | 2023-01-23T08:19:58.327208+00:00 | 2023-01-23T08:19:58.327254+00:00 | 968 | 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:\no(n)\n- Space complexity:\no(n)\n# Code\n```\nclass Solution {\n public char repeatedCharacter(String s) {\n char ch=\' \'... | 3 | 0 | ['Java'] | 0 |
first-letter-to-appear-twice | ✅Fastest C++ Solution using Hashing | fastest-c-solution-using-hashing-by-adar-3crt | \n# Code\n\nclass Solution {\npublic:\n char repeatedCharacter(string s) {\n\n char ans = \'a\';\n\n // Hashing \n unordered_map<char,int> | Adarsh_Shukla | NORMAL | 2022-12-23T12:33:47.244229+00:00 | 2022-12-23T12:33:47.244273+00:00 | 518 | false | \n# Code\n```\nclass Solution {\npublic:\n char repeatedCharacter(string s) {\n\n char ans = \'a\';\n\n // Hashing \n unordered_map<char,int> mp;\n for(int i=0;i<s.length();++i){\n mp[s[i]]++;\n if(mp[s[i]]==2) {\n ans=s[i];\n break;\n ... | 3 | 0 | ['C++'] | 0 |
first-letter-to-appear-twice | JavaScript using a Set O(1) Time and Space complexity | 92% | javascript-using-a-set-o1-time-and-space-pmjk | We use a Set to keep track of what letters we have already seen. Once we find a letter that is already in our Set we know we found a duplicate letter.\n\nMax 26 | Golyator | NORMAL | 2022-11-28T20:02:32.285226+00:00 | 2022-12-14T21:08:41.333177+00:00 | 349 | false | We use a Set to keep track of what letters we have already seen. Once we find a letter that is already in our Set we know we found a duplicate letter.\n\nMax 26 unique lowercase letters:\nTime: O(1)\nSpace: O(1)\n\nI saw many solutions here claiming a O(n) space and time complexity but they aint correct, it is O(1). Th... | 3 | 0 | ['Ordered Set', 'JavaScript'] | 1 |
first-letter-to-appear-twice | ✨🚀Easiest approach|| ONLY 3 steps || beginner friendly 🚀 Easiest C++ Solution | easiest-approach-only-3-steps-beginner-f-n2b8 | Only 3 Steps\n1. Declare an hashmap\n2. In a loop insert string[i] and keep increasing map count \n3. If its count is more than 1 that means its double hence br | shxbh | NORMAL | 2022-11-26T18:52:48.879288+00:00 | 2022-11-26T18:52:48.879316+00:00 | 244 | false | ## Only 3 Steps\n1. Declare an hashmap\n2. In a loop insert string[i] and keep increasing map count \n3. If its count is more than 1 that means its double hence break and return the char\n```\nclass Solution {\npublic:\n char repeatedCharacter(string s) {\n char c;\n\t\t//Declare an hashmap\n map<char,... | 3 | 0 | ['C'] | 0 |
first-letter-to-appear-twice | Java Faster than 100% (3 Solutions) | java-faster-than-100-3-solutions-by-adit-fq8y | Solution 1: Faster than 100%\n\nclass Solution {\n public char repeatedCharacter(String s) {\n for(int i=1; i<s.length(); i++){\n if(s.inde | aditigupta2048 | NORMAL | 2022-10-09T08:12:35.678088+00:00 | 2022-10-09T08:12:35.678138+00:00 | 1,176 | false | Solution 1: Faster than 100%\n```\nclass Solution {\n public char repeatedCharacter(String s) {\n for(int i=1; i<s.length(); i++){\n if(s.indexOf(s.charAt(i))!=i){\n return s.charAt(i);\n }\n }\n return \' \';\n }\n}\n```\n\nSolution 2: Faster than 100%\n`... | 3 | 0 | ['Java'] | 0 |
first-letter-to-appear-twice | Python Set | Easy understanding | python-set-easy-understanding-by-prithul-r0sn | Idea: We don\'t need to loop totally to get the answer. We just keep track of what letters went ahead by using a set. If any letter is repeated, return the lett | prithuls | NORMAL | 2022-08-16T01:26:36.350655+00:00 | 2022-08-16T01:26:36.350684+00:00 | 269 | false | Idea: We don\'t need to loop totally to get the answer. We just keep track of what letters went ahead by using a set. If any letter is repeated, return the letter.\n```\nclass Solution:\n def repeatedCharacter(self, s: str) -> str:\n hm = set()\n for s_ in s:\n if s_ not in hm:\n ... | 3 | 0 | ['Ordered Set', 'Python'] | 0 |
first-letter-to-appear-twice | python3 code | python3-code-by-blackhole_tiub-ztak | \nvar repeatedCharacter = function(s) {\n let arr = []\n for (let i of s) {\n if (!arr.includes(i)) {\n arr.push(i)\n }\n | Little_Tiub | NORMAL | 2022-07-31T18:26:47.154117+00:00 | 2023-05-06T17:58:41.072742+00:00 | 62 | false | ```\nvar repeatedCharacter = function(s) {\n let arr = []\n for (let i of s) {\n if (!arr.includes(i)) {\n arr.push(i)\n }\n else {\n return i\n }\n }\n}\n``` | 3 | 1 | ['JavaScript'] | 0 |
first-letter-to-appear-twice | c++ || easy || map | c-easy-map-by-abhijoy123-lkr3 | \nclass Solution {\npublic:\n char repeatedCharacter(string s) {\n map<char, int> mp;\n for(int i=0;i<s.length();i++)\n {\n m | abhijoy123 | NORMAL | 2022-07-29T20:26:05.940905+00:00 | 2022-07-29T20:26:05.940942+00:00 | 265 | false | ```\nclass Solution {\npublic:\n char repeatedCharacter(string s) {\n map<char, int> mp;\n for(int i=0;i<s.length();i++)\n {\n mp[s[i]]++;\n if(mp[s[i]]==2)\n return s[i];\n }\n return 0;\n }\n};\n```\n\nplease upvote!! | 3 | 0 | ['C', 'C++'] | 1 |
first-letter-to-appear-twice | Python3 O(n) || O(1) # Runtime: 30ms 90.00% || Memory: 13.9mb 10.00% | python3-on-o1-runtime-30ms-9000-memory-1-8i2s | \nclass Solution:\n# O(n) || O(1)\n# Runtime: 30ms 90.00% || Memory: 13.9mb 10.00%\n def repeatedCharacter(self, string: str) -> str:\n strAlphaFr | arshergon | NORMAL | 2022-07-26T03:38:00.703397+00:00 | 2022-07-26T03:38:00.703428+00:00 | 507 | false | ```\nclass Solution:\n# O(n) || O(1)\n# Runtime: 30ms 90.00% || Memory: 13.9mb 10.00%\n def repeatedCharacter(self, string: str) -> str:\n strAlphaFreq = [0] * 26\n\n for char in string:\n index = ord(char) - ord(\'a\')\n\n strAlphaFreq[index] += 1\n\n if strAlphaFr... | 3 | 0 | ['Python', 'Python3'] | 0 |
first-letter-to-appear-twice | c++ solution O(1) space using bitmask | c-solution-o1-space-using-bitmask-by-dil-uh85 | \nclass Solution {\npublic:\n char repeatedCharacter(string s) {\n int mask=0;\n int n=s.size();\n for(int i=0;i<n;i++)\n {\n | dilipsuthar17 | NORMAL | 2022-07-24T05:25:38.577891+00:00 | 2022-07-24T06:50:49.953937+00:00 | 200 | false | ```\nclass Solution {\npublic:\n char repeatedCharacter(string s) {\n int mask=0;\n int n=s.size();\n for(int i=0;i<n;i++)\n {\n if(mask&(1<<(s[i]-\'a\')))\n {\n return s[i];\n }\n else\n {\n mask|=(1<<(s... | 3 | 0 | ['C', 'C++'] | 0 |
first-letter-to-appear-twice | easy short efficient code | easy-short-efficient-code-by-maverick09-d3pe | \nclass Solution {\n typedef long long ll;\n#define vi(x) vector<x>\npublic:\n char repeatedCharacter(string& s) {\n ll mask=0;\n char res = | maverick09 | NORMAL | 2022-07-24T04:09:02.291816+00:00 | 2022-07-24T04:09:02.291848+00:00 | 257 | false | ```\nclass Solution {\n typedef long long ll;\n#define vi(x) vector<x>\npublic:\n char repeatedCharacter(string& s) {\n ll mask=0;\n char res = \'.\';\n for (char ch : s) {\n if (mask&(1<<(ch-\'a\'))) {\n res = ch;\n break;\n }\n ... | 3 | 0 | ['C', 'Bitmask'] | 0 |
first-letter-to-appear-twice | EASSY JAVA SOLUTION BEATING 100% IN 0ms || USE OF HASHSETS | eassy-java-solution-beating-100-in-0ms-u-dymi | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | ADARSH_GAUTAM_576 | NORMAL | 2025-03-29T06:24:58.074181+00:00 | 2025-03-29T06:24:58.074181+00:00 | 70 | 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 | ['Hash Table', 'String', 'Counting', 'Java'] | 0 |
first-letter-to-appear-twice | Optimal O(n) Solution || Easy to understand | optimal-on-solution-easy-to-understand-b-zdsy | IntuitionWe need to efficiently track the characters we have seen and detect when a character appears for the second time.ApproachWe can use a Set data structur | bibekbarik | NORMAL | 2025-03-28T14:07:01.604814+00:00 | 2025-03-28T14:07:01.604814+00:00 | 37 | false | # Intuition
We need to efficiently track the characters we have seen and detect when a character appears for the second time.
# Approach
We can use a Set data structure to keep track of characters we have already encountered.
1) Iterate through the string character by character.
2) Check if the character is already ... | 2 | 0 | ['Python3'] | 0 |
first-letter-to-appear-twice | 🔥🔥best and easy solution in c++||beat 💯 ..0 ms.. simple✅📌 | best-and-easy-solution-in-cbeast-0-ms-si-tkxw | Code | Kaviyant7 | NORMAL | 2025-03-06T07:39:20.000099+00:00 | 2025-03-06T07:45:27.755342+00:00 | 63 | false |
# Code
```cpp []
class Solution {
public:
char repeatedCharacter(string s) {
unordered_map<char,int>m;
for(char c:s){
m[c]++;
if(m[c]==2) {
return c;
break;
}
}
return 0;
}
};
``` | 2 | 0 | ['C++'] | 0 |
first-letter-to-appear-twice | 0MS 🥇|| BEATS 100% 🥂 || 6 LINE CODE ⛳ || 🌟JAVA ☕ | 0ms-beats-100-6-line-code-java-by-galani-71cn | Code | Galani_jenis | NORMAL | 2025-01-18T08:46:45.497996+00:00 | 2025-01-18T08:46:45.497996+00:00 | 269 | false | 
# Code
```java []
class Solution {
public char repeatedCharacter(String s) {
Set<Character> set = new HashSet<>();
for (char ch : s.toCharArray()) {
... | 2 | 0 | ['Java'] | 0 |
first-letter-to-appear-twice | Beats 100% with O(1) Space | beats-100-with-o1-space-by-hebahamdan296-91he | Intuition\nTo find the first repeated character, I considered using a hash set or map. However, since the input consists of only lowercase letters, I opted for | hebahamdan296 | NORMAL | 2024-09-28T11:08:50.506452+00:00 | 2024-09-28T11:19:22.594980+00:00 | 22 | false | # Intuition\nTo find the first repeated character, I considered using a hash set or map. However, since the input consists of only lowercase letters, I opted for a vector of size 26. This approach is more efficient, as it uses constant space and avoids the overhead of dynamic data structures, making it ideal for tracki... | 2 | 0 | ['C++'] | 0 |
first-letter-to-appear-twice | 🚀Easy Solution✅ Beats100%🚀Beginner-Friendly Solution and Approach 💫 #JAVA ✅ Detailed Explanation✅ | easy-solution-beats100beginner-friendly-f67rg | Intuition\nTo find the first character that appears twice in a string, we keep track of characters we\'ve seen. When we see a character for the second time, we | kanix-1801 | NORMAL | 2024-06-24T17:13:54.120395+00:00 | 2024-06-24T17:13:54.120430+00:00 | 402 | false | # Intuition\n***To find the first character that appears twice in a string, we keep track of characters we\'ve seen. When we see a character for the second time, we shout, "Found you!" and return it.***\n\n$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 2 | 0 | ['Array', 'String', 'Counting', 'Python3'] | 1 |
first-letter-to-appear-twice | Easy Java Solution || Beginner Friendly || HashMap | easy-java-solution-beginner-friendly-has-j6tj | 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 | anikets101 | NORMAL | 2024-04-23T01:25:53.282194+00:00 | 2024-04-23T01:25:53.282215+00:00 | 497 | 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)$$ --... | 2 | 0 | ['Java'] | 0 |
first-letter-to-appear-twice | HashMap Beats 100% solutions | hashmap-beats-100-solutions-by-shreya_ku-5n1d | 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 | Shreya_Kumari_24 | NORMAL | 2024-04-04T12:34:25.877820+00:00 | 2024-04-04T12:34:25.877839+00:00 | 228 | 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)$$ --... | 2 | 0 | ['Java'] | 0 |
first-letter-to-appear-twice | Java | Easy Solution | 0ms | HashMap | java-easy-solution-0ms-hashmap-by-lophiu-ixcl | Intuition\n Describe your first thoughts on how to solve this problem. \nI thought of using a HashMap to find the first letter that occurs twice. If a letter oc | Lophius_ | NORMAL | 2024-03-05T09:02:39.835942+00:00 | 2024-03-05T09:08:34.325594+00:00 | 277 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nI thought of using a HashMap to find the first letter that occurs twice. If a letter occurs for the first time, a HashMap will return $$null$$ if we try to use it as a key. If it does return a value, that means it\'s not occuring for the ... | 2 | 0 | ['Hash Table', 'Java'] | 2 |
first-letter-to-appear-twice | ✨ Simple Python3 Solution with Explanation - Beats 93% ✨ O(n) time ⏱ & O(1) space 🪐 | simple-python3-solution-with-explanation-a2oi | Intuition\nThe question asks us to find the first character that appears twice in the string s. A set would be helpful for us here, because it would allow us to | fionabronwen | NORMAL | 2024-02-22T01:36:54.311484+00:00 | 2024-02-22T02:05:52.050763+00:00 | 255 | false | # Intuition\nThe question asks us to find the first character that appears twice in the string `s`. A set would be helpful for us here, because it would allow us to check for the presence of a character in constant, O(1), time.\n# Approach\n1. Create an empty set called `seen`. We will use this to track which character... | 2 | 0 | ['Python3'] | 1 |
first-letter-to-appear-twice | C - Bit Array - 0ms - 6.37 mb | c-bit-array-0ms-637-mb-by-m4rt_h-hngt | \n\n# Approach\nSince the input is limited to being a-z you could just have an array and store some integers in it and keep track of how many you encouter, and | m4rt_h | NORMAL | 2024-01-17T14:06:25.183517+00:00 | 2024-01-17T14:06:25.183552+00:00 | 50 | false | \n\n# Approach\nSince the input is limited to being a-z you could just have an array and store some integers in it and keep track of how many you encouter, and then return when you first encounter a seccond... | 2 | 0 | ['Bit Manipulation', 'C', 'Bitmask'] | 0 |
first-letter-to-appear-twice | C# solution using HashSet | c-solution-using-hashset-by-dmitriy-maks-22ki | Complexity\n- Time complexity: O(n)\n- Space complexity: O(n)\n\n# Code\n\npublic class Solution\n{\n public char RepeatedCharacter(string s)\n {\n | dmitriy-maksimov | NORMAL | 2023-09-22T08:42:59.817517+00:00 | 2023-09-22T08:42:59.817536+00:00 | 28 | false | # Complexity\n- Time complexity: $$O(n)$$\n- Space complexity: $$O(n)$$\n\n# Code\n```\npublic class Solution\n{\n public char RepeatedCharacter(string s)\n {\n var set = new HashSet<char>();\n\n foreach (var c in s)\n {\n if (set.Contains(c))\n {\n return... | 2 | 0 | ['C#'] | 0 |
first-letter-to-appear-twice | [ Go Solution ]Great explanation and Full Description | go-solution-great-explanation-and-full-d-i37f | Intuition\nThis problem asks to find the first repeated character in a given string. We can solve this problem by scanning the string from left to right and kee | sansaian | NORMAL | 2023-07-27T09:33:42.081648+00:00 | 2023-07-27T09:33:42.081670+00:00 | 204 | false | # Intuition\nThis problem asks to find the first repeated character in a given string. We can solve this problem by scanning the string from left to right and keeping track of the characters we have seen before. As soon as we encounter a character that is already in our record, we return it as the first repeating chara... | 2 | 0 | ['Hash Table', 'String', 'Counting', 'Go'] | 0 |
first-letter-to-appear-twice | O(n) Solution for First Letter to Appear Twice Solution in C++ | on-solution-for-first-letter-to-appear-t-qltt | 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 | The_Kunal_Singh | NORMAL | 2023-05-27T04:36:36.819681+00:00 | 2023-05-27T04:36:36.819726+00:00 | 537 | 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)$$ -->\nO(n)\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$... | 2 | 0 | ['C++'] | 0 |
first-letter-to-appear-twice | Java || Beats 100% || O(1) Space, O(n) Time || Explanation | java-beats-100-o1-space-on-time-explanat-arhg | Intuition\nTo find the first letter that appears twice in the string, we can iterate over the characters in the string and keep track of which letters have been | Laziz_511 | NORMAL | 2023-05-20T09:50:56.520841+00:00 | 2023-05-20T09:50:56.520877+00:00 | 482 | false | # Intuition\nTo find the first letter that appears twice in the string, we can iterate over the characters in the string and keep track of which letters have been seen. Once we encounter a letter that has already been seen, we return it as the answer.\n\n# Approach\n1. We can use an array of booleans, **\'letters\'**, ... | 2 | 0 | ['Java'] | 1 |
first-letter-to-appear-twice | C++ || 0 ms || 100% Faster || | c-0-ms-100-faster-by-dil_da_ni_mada-ufb8 | Intuition\n Describe your first thoughts on how to solve this problem. \nStart iterating on the string and if element is not present on the set then insert it o | its_over | NORMAL | 2023-05-16T06:58:21.097867+00:00 | 2023-05-16T06:58:21.097908+00:00 | 67 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nStart iterating on the string and if element is not present on the set then insert it otherwise if already present then that the first repeating element just return the character.\n\n# Approach\n<!-- Describe your approach to solving the ... | 2 | 0 | ['String', 'Ordered Set', 'C++'] | 0 |
first-letter-to-appear-twice | 5 line java code || Beats 100% || very easy beginner friendly || | 5-line-java-code-beats-100-very-easy-beg-xpbf | 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 | ammar_saquib | NORMAL | 2023-04-17T18:58:38.859931+00:00 | 2023-04-17T18:58:38.859984+00:00 | 297 | 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)$$ --... | 2 | 0 | ['Java'] | 0 |
first-letter-to-appear-twice | Easy Approach || 4 Lines Code || c++ | easy-approach-4-lines-code-c-by-tanveer_-tkgp | 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 | tanveer_965 | NORMAL | 2023-03-06T19:17:24.613026+00:00 | 2023-03-06T19:17:24.613058+00:00 | 657 | 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)$$ --... | 2 | 0 | ['C++'] | 0 |
first-letter-to-appear-twice | C++ Solution || Beats 100% || Runtime 0ms | c-solution-beats-100-runtime-0ms-by-asad-jv6r | 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 | Asad_Sarwar | NORMAL | 2023-02-26T21:37:49.652574+00:00 | 2023-02-26T21:37:49.652622+00:00 | 2,046 | 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: O(n*n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(... | 2 | 0 | ['C++'] | 0 |
first-letter-to-appear-twice | 100% beat...... | 100-beat-by-dhruv_22_gupta-ofrf | 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 | dhruv_22_gupta | NORMAL | 2023-02-10T20:16:45.267098+00:00 | 2023-02-10T20:16:45.267134+00:00 | 516 | 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)$$ --... | 2 | 0 | ['C++'] | 1 |
first-letter-to-appear-twice | 100% beats java solution for java beginners :-) | 100-beats-java-solution-for-java-beginne-palz | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \nusing set in java\n\n# | krishnanshu_dwivedi | NORMAL | 2023-01-10T15:03:53.410188+00:00 | 2023-01-10T15:03:53.410222+00:00 | 449 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nusing set in java\n\n# Complexity\n- Time complexity:\n- O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space comple... | 2 | 0 | ['Java'] | 1 |
first-letter-to-appear-twice | C++ | 0 ms | one liner | c-0-ms-one-liner-by-_kitish-m2oe | \nclass Solution {\npublic:\n char repeatedCharacter(string s) {\n return [&,st=unordered_set<char>{}]()mutable{for(char &_s:s){if(st.count(_s)) retur | _kitish | NORMAL | 2022-12-01T06:59:35.430598+00:00 | 2022-12-01T06:59:35.430639+00:00 | 128 | false | ```\nclass Solution {\npublic:\n char repeatedCharacter(string s) {\n return [&,st=unordered_set<char>{}]()mutable{for(char &_s:s){if(st.count(_s)) return _s; st.insert(_s);} return \'$\';}();\n }\n};\n``` | 2 | 0 | [] | 0 |
first-letter-to-appear-twice | C++ solution 100% faster | c-solution-100-faster-by-om_limbhare-zj1o | \nclass Solution {\npublic:\n char repeatedCharacter(string s) {\n vector <bool> v(26,false);\n for(char a:s){\n if(v[a-\'a\']) retur | om_limbhare | NORMAL | 2022-11-24T21:45:13.907095+00:00 | 2022-11-24T21:45:13.907128+00:00 | 982 | false | ```\nclass Solution {\npublic:\n char repeatedCharacter(string s) {\n vector <bool> v(26,false);\n for(char a:s){\n if(v[a-\'a\']) return a;\n v[a-\'a\']=1;\n }\n return \'a\'; \n }\n};\n\n\n``` | 2 | 0 | ['C', 'C++'] | 0 |
first-letter-to-appear-twice | JavaScript Object/Set | javascript-objectset-by-ian-of-yore-qdil | Intuition\nThis can be solved by using either object or set structure.\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n We can crea | ian-of-yore | NORMAL | 2022-11-19T21:25:14.403597+00:00 | 2022-11-19T21:25:14.403633+00:00 | 378 | false | # Intuition\nThis can be solved by using either object or set structure.\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n We can create a new object/set. Then loop through the string, inside the loop, we first check if the letter has already be added to the object/set. If it is alrea... | 2 | 0 | ['JavaScript'] | 1 |
first-letter-to-appear-twice | Python || 6 Lines || 96.89% Faster || Using Dictionary || O(n) T.C. | python-6-lines-9689-faster-using-diction-331i | \nclass Solution:\n def repeatedCharacter(self, s: str) -> str:\n d={}\n for i in s:\n if i in d: \n d[i]+=1\n | pulkit_uppal | NORMAL | 2022-11-05T09:59:12.860691+00:00 | 2022-11-05T09:59:12.860734+00:00 | 354 | false | ```\nclass Solution:\n def repeatedCharacter(self, s: str) -> str:\n d={}\n for i in s:\n if i in d: \n d[i]+=1\n if d[i]==2: return i\n else: d[i]=1\n```\n\n**Please upvote if you like the solution** | 2 | 0 | ['Python'] | 0 |
first-letter-to-appear-twice | Python | python-by-akhilgullapalli-w0v2 | \nclass Solution(object):\n def repeatedCharacter(self, s):\n """\n :type s: str\n :rtype: str\n """\n twice = {}\n | akhilgullapalli | NORMAL | 2022-10-07T15:22:03.950293+00:00 | 2022-10-07T15:22:03.950328+00:00 | 522 | false | ```\nclass Solution(object):\n def repeatedCharacter(self, s):\n """\n :type s: str\n :rtype: str\n """\n twice = {}\n for i in s:\n if i in twice:\n return i\n else:\n twice[i] = 1\n``` | 2 | 0 | [] | 0 |
first-letter-to-appear-twice | Beats 99.86% [Python 3] | beats-9986-python-3-by-sneh713-rvpv | 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 | Sneh713 | NORMAL | 2022-10-07T06:49:05.287534+00:00 | 2022-10-07T06:50:56.541384+00:00 | 994 | 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- O(N)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n- O(N=26) so O(1)\n<!-- Add your space compl... | 2 | 0 | ['Hash Table', 'Python3'] | 2 |
first-letter-to-appear-twice | Easy and short python solution | easy-and-short-python-solution-by-aastha-t88w | \nd={}\nfor i in range(len(s)):\n\tif s[i] not in d:\n\t\t\td[s[i]]=i\n\telse:\n\t\t\treturn s[i]\n | aastha1916 | NORMAL | 2022-10-06T09:28:57.223957+00:00 | 2022-10-06T09:28:57.223996+00:00 | 116 | false | ```\nd={}\nfor i in range(len(s)):\n\tif s[i] not in d:\n\t\t\td[s[i]]=i\n\telse:\n\t\t\treturn s[i]\n``` | 2 | 0 | ['Python'] | 0 |
first-letter-to-appear-twice | C++|100% Faster|0 ms runtime | c100-faster0-ms-runtime-by-infinix_05-v7ak | UPVOTE AND COMMENT YOUR DOUBTS\n\nclass Solution {\npublic:\n char repeatedCharacter(string s) {\n int i;\n for(i=0;i<s.length();i++){\n | infinix_05 | NORMAL | 2022-09-10T13:59:53.539184+00:00 | 2022-09-10T13:59:53.539230+00:00 | 96 | false | UPVOTE AND COMMENT YOUR DOUBTS\n```\nclass Solution {\npublic:\n char repeatedCharacter(string s) {\n int i;\n for(i=0;i<s.length();i++){\n for(int j=0;j<i;j++){\n if(s[i]==s[j]){\n return s[i];\n break;\n }\n }\... | 2 | 0 | ['C'] | 0 |
first-letter-to-appear-twice | 100% FASTER || HASHMAP || SIMPLE JAVA CODE | 100-faster-hashmap-simple-java-code-by-p-nzmk | \n HashMap<Character,Integer> map= new HashMap<>();\n for(int i=0;i<s.length();i++){\n char c= s.charAt(i);\n if(map.containsKe | priyankan_23 | NORMAL | 2022-08-31T14:48:55.234217+00:00 | 2022-08-31T14:48:55.234247+00:00 | 101 | false | ```\n HashMap<Character,Integer> map= new HashMap<>();\n for(int i=0;i<s.length();i++){\n char c= s.charAt(i);\n if(map.containsKey(c)){\n map.put(c,map.get(c)+1);\n if(map.get(c)==2) return c;\n break;\n \n }\n ... | 2 | 0 | [] | 0 |
first-letter-to-appear-twice | Bit Masking | bit-masking-by-shahan989-krsp | python\nclass Solution:\n def repeatedCharacter(self, s: str) -> str:\n \n #bit masking\n \n value = 0\n \n for i i | shahan989 | NORMAL | 2022-08-31T12:08:42.545810+00:00 | 2022-08-31T12:08:42.545852+00:00 | 45 | false | ```python\nclass Solution:\n def repeatedCharacter(self, s: str) -> str:\n \n #bit masking\n \n value = 0\n \n for i in range(len(s)):\n \n char = s[i]\n \n if value & (1 <<ord( char) - ord("a")):\n return char\n ... | 2 | 0 | ['Bitmask', 'Python'] | 0 |
first-letter-to-appear-twice | bit manipulation c solution | bit-manipulation-c-solution-by-nameldi-5y4h | \nchar repeatedCharacter(char * s){\n int len = strlen(s);\n int bitmask = 0;\n for(int i = 0; i < len; i++){\n if(bitmask & (1 << (s[i]-\'a\')) | nameldi | NORMAL | 2022-08-19T13:24:05.246189+00:00 | 2022-08-19T13:24:05.246239+00:00 | 88 | false | ```\nchar repeatedCharacter(char * s){\n int len = strlen(s);\n int bitmask = 0;\n for(int i = 0; i < len; i++){\n if(bitmask & (1 << (s[i]-\'a\')))\n return s[i];\n bitmask |= (1 << (s[i]-\'a\'));\n }\n return -1;\n}\n``` | 2 | 0 | ['C'] | 0 |
first-letter-to-appear-twice | Java ,0ms Solution, array only | java-0ms-solution-array-only-by-banurr-j9fh | \npublic static char firstUniqChar(String s)\n {\n int[] aa = new int[26];\n for(Character i : s.toCharArray())\n | banurr | NORMAL | 2022-08-17T06:55:56.522601+00:00 | 2022-08-17T06:55:56.522637+00:00 | 164 | false | ```\npublic static char firstUniqChar(String s)\n {\n int[] aa = new int[26];\n for(Character i : s.toCharArray())\n {\n ++aa[i-\'a\'];\n if(aa[i-\'a\']==2) return i;\n }\n return 0;\n ... | 2 | 0 | ['Array', 'Java'] | 0 |
first-letter-to-appear-twice | ✅C++ || Vesy Easy || Map || O(n) | c-vesy-easy-map-on-by-tridibdalui04-bcku | O(n) Solution using map explanation in Comment\n\nApproch :-\n Traverse the whole String from the start and store the charecter & it\'s freqency in a map one by | tridibdalui04 | NORMAL | 2022-08-16T14:18:32.930690+00:00 | 2022-08-16T14:18:32.930728+00:00 | 190 | false | **O(n) Solution using map explanation in Comment**\n\n**Approch :-**\n* Traverse the whole *String* from the start and store the charecter & it\'s freqency in a map one by one\n\n* Travese the map and if there is a charecter with frequency return the current charecter as it is the first what occures 2 times\n\n# Code\n... | 2 | 0 | ['C'] | 1 |
first-letter-to-appear-twice | Java using Set | java-using-set-by-carolinewillis211-yjqx | ```class Solution {\n public char repeatedCharacter(String s) {\n Set set = new HashSet<>();\n \n for(int i = 0; i < s.length(); i++) { | carolinewillis211 | NORMAL | 2022-08-16T00:47:22.154878+00:00 | 2022-08-16T00:47:22.154919+00:00 | 79 | false | ```class Solution {\n public char repeatedCharacter(String s) {\n Set <Character> set = new HashSet<>();\n \n for(int i = 0; i < s.length(); i++) {\n char curr = s.charAt(i);\n if(set.contains(curr)) {\n return curr;\n }\n \n ... | 2 | 0 | [] | 0 |
first-letter-to-appear-twice | C++ || 0 ms || 0(n) Time Complexity || Using Visited Array | c-0-ms-0n-time-complexity-using-visited-vmowl | My approach here was to iterate through the string and increase the count of current character in visitedAlphabets array/vector. If we get the count of any char | mohan792 | NORMAL | 2022-08-08T11:42:25.514563+00:00 | 2022-08-08T11:42:25.514588+00:00 | 30 | false | My approach here was to iterate through the string and increase the count of current character in visitedAlphabets array/vector. If we get the count of any character as 2, it will be the required output.\n\n```\nclass Solution {\npublic:\n char repeatedCharacter(string s) {\n vector<int> visitedAlphabets(26, ... | 2 | 0 | ['C', 'C++'] | 0 |
first-letter-to-appear-twice | Solution Using HashSet | solution-using-hashset-by-bharg4vi-747q | ```\nclass Solution {\n public char repeatedCharacter(String s)\n {\n\n HashSet m = new HashSet();\n for(int i = 0; i < s.length(); i++)\n | bharg4vi | NORMAL | 2022-08-05T13:55:54.384976+00:00 | 2022-08-05T13:55:54.385025+00:00 | 127 | false | ```\nclass Solution {\n public char repeatedCharacter(String s)\n {\n\n HashSet<Character> m = new HashSet<Character>();\n for(int i = 0; i < s.length(); i++)\n {\n if(!m.contains(s.charAt(i)))\n {\n m.add(s.charAt(i));\n }\n else\n ... | 2 | 0 | ['Java'] | 1 |
first-letter-to-appear-twice | [Go] Bitmask | go-bitmask-by-sebnyberg-b5dd | Since there are only 26 lowercase letters in the alphabet, \nwe can use a 32-bit integer to track whether a letter has been seen before.\n\nThe first round, the | sebnyberg | NORMAL | 2022-08-05T10:10:22.008693+00:00 | 2022-08-05T10:10:51.858664+00:00 | 82 | false | Since there are only 26 lowercase letters in the alphabet, \nwe can use a 32-bit integer to track whether a letter has been seen before.\n\nThe first round, the corresponding bit is set. The second round, we return the result.\n\n```go\nfunc repeatedCharacter(s string) byte {\n\t// Use a bitmask to keep track of whethe... | 2 | 0 | ['Bit Manipulation', 'Go'] | 0 |
first-letter-to-appear-twice | C++ || Easy solution | c-easy-solution-by-shuvam_barman-3lo4 | \nclass Solution {\npublic:\n array<int, 26> counter;\n char repeatedCharacter(string s) {\n for (const auto i : s)\n if (counter[i - \' | Shuvam_Barman | NORMAL | 2022-08-03T15:44:10.720170+00:00 | 2022-08-03T15:44:10.720213+00:00 | 121 | false | ```\nclass Solution {\npublic:\n array<int, 26> counter;\n char repeatedCharacter(string s) {\n for (const auto i : s)\n if (counter[i - \'a\']++) return i;\n throw \'a\';\n }\n};\n``` | 2 | 0 | ['C'] | 0 |
first-letter-to-appear-twice | Easy C++ solution || Using set || chill life ✅ | easy-c-solution-using-set-chill-life-by-a2q18 | Idea is traverse the string, if you find the character is set return it if not then insert it. Simple\n\nchar repeatedCharacter(string s) {\n set<char>st | Soumik_Coder | NORMAL | 2022-07-28T19:46:34.218262+00:00 | 2022-07-28T19:46:34.218327+00:00 | 68 | false | Idea is traverse the string, if you find the character is set return it if not then insert it. Simple\n```\nchar repeatedCharacter(string s) {\n set<char>st;\n int i=0;\n for(int i=0; i<s.length(); i++)\n {\n if(st.count(s[i])){\n return s[i];\n }\n ... | 2 | 0 | ['C', 'Ordered Set'] | 1 |
first-letter-to-appear-twice | C++ || 2 easiest solutions | c-2-easiest-solutions-by-girdharnishant-ik8c | First, solving this problem using multiset.\nMultiset is a data structure which stores value and can easily return the count of an element present in the multis | girdharnishant | NORMAL | 2022-07-28T19:23:08.834846+00:00 | 2022-07-28T19:23:08.834877+00:00 | 176 | false | First, solving this problem using multiset.\nMultiset is a data structure which stores value and can easily return the count of an element present in the multiset.\n\n\nclass Solution {\npublic:\n char repeatedCharacter(string s) {\n \n multiset<char> ms; // Creating a multiset.\n for(int i = 0;... | 2 | 0 | ['C', 'C++'] | 1 |
first-letter-to-appear-twice | CPP | O(n) Solution | Easy to understand | cpp-on-solution-easy-to-understand-by-pr-6w3w | class Solution {\npublic:\n char repeatedCharacter(string s) {\n mapmp1;\n for(char c=\'a\';c<=\'z\';c++){\n mp1[c]++;\n mp1[c | prince_7672526 | NORMAL | 2022-07-26T23:14:15.052762+00:00 | 2022-07-27T05:58:34.796292+00:00 | 41 | false | class Solution {\npublic:\n char repeatedCharacter(string s) {\n map<char,int>mp1;\n for(char c=\'a\';c<=\'z\';c++){\n mp1[c]++;\n mp1[c]++;\n }\n for (int i=0;i<s.size();i++){\n mp1[s[i]]--;\n if(mp1[s[i]]==0){\n return s[i];\n }\n }\n ... | 2 | 0 | [] | 2 |
first-letter-to-appear-twice | Easy O(n) solution in Python using set | easy-on-solution-in-python-using-set-by-w7nkb | We create a null/empty set. \nNext, we traverse the string character by character and if the character is not present in set, we add that character in the seen | indranilbhattacharya9874273176 | NORMAL | 2022-07-26T10:20:33.006449+00:00 | 2022-07-26T12:08:17.210551+00:00 | 116 | false | We create a null/empty set. \nNext, we traverse the string character by character and if the character is not present in set, we add that character in the seen set, otherwise the character is in the seen set. Means we can return that character as it is appearing twice.\nNote that the search in a set in Python is O(1) o... | 2 | 0 | ['Ordered Set', 'Python'] | 0 |
first-letter-to-appear-twice | Easy CPP solution | easy-cpp-solution-by-reehan9-ais3 | \nclass Solution {\npublic:\n char repeatedCharacter(string s) {\n int i = 0;\n unordered_map<char , int>check;\n for(i = 0 ; i < s.size | Reehan9 | NORMAL | 2022-07-24T12:34:39.603528+00:00 | 2022-07-24T16:31:18.449303+00:00 | 69 | false | ```\nclass Solution {\npublic:\n char repeatedCharacter(string s) {\n int i = 0;\n unordered_map<char , int>check;\n for(i = 0 ; i < s.size() && ++check[s[i]]<=2; i++ , check[s[i]]++);\n return s[i];\n }\n};\n```\n##### Please upvote if you find this helpful\nhttps://github.com... | 2 | 0 | ['C++'] | 1 |
first-letter-to-appear-twice | Swift - Simple solution | swift-simple-solution-by-evkobak-7p2p | \nclass Solution {\n func repeatedCharacter(_ s: String) -> Character {\n \n var set: Set<Character> = []\n\n for char in s {\n | evkobak | NORMAL | 2022-07-24T10:32:41.324533+00:00 | 2022-07-24T10:32:41.324559+00:00 | 135 | false | ```\nclass Solution {\n func repeatedCharacter(_ s: String) -> Character {\n \n var set: Set<Character> = []\n\n for char in s {\n if set.contains(char) {\n return char\n } else {\n set.insert(char)\n }\n }\n\n return "... | 2 | 0 | ['Swift'] | 1 |
first-letter-to-appear-twice | C++ | Hashing | Easy | c-hashing-easy-by-gamistl0314-7nby | Time Complexity - O(N)\nSpace Complexity - O(26)\n\nchar repeatedCharacter(string s) \n {\n unordered_map<char,int> m;\n int n=s.length();\n | gamistl0314 | NORMAL | 2022-07-24T08:36:11.012876+00:00 | 2022-07-24T08:36:11.012914+00:00 | 20 | false | Time Complexity - **O(N)**\nSpace Complexity - **O(26)**\n```\nchar repeatedCharacter(string s) \n {\n unordered_map<char,int> m;\n int n=s.length();\n char c;\n for(int i=0;i<n;i++)\n {\n if(!m[s[i]]) m[s[i]]++;\n else\n {\n c=s[i];\... | 2 | 0 | ['C'] | 0 |
first-letter-to-appear-twice | simple || like two sum || o(n) | simple-like-two-sum-on-by-mamtachahal-5h7d | ```\nclass Solution {\npublic:\n char repeatedCharacter(string s) {\n unordered_mapm;\n char ans;\n for(int i=0;i<s.size();i++){\n | Mamtachahal | NORMAL | 2022-07-24T06:26:20.355249+00:00 | 2022-07-24T06:26:20.355290+00:00 | 188 | false | ```\nclass Solution {\npublic:\n char repeatedCharacter(string s) {\n unordered_map<char,int>m;\n char ans;\n for(int i=0;i<s.size();i++){\n \n if(m.find(s[i])!=m.end())\n {\n ans= s[i];\n break;\n }\n m[s[i]]++;... | 2 | 0 | ['C', 'C++'] | 1 |
make-a-square-with-the-same-color | Visualized || Brute Force + General Solution || C++ | visualized-brute-force-general-solution-qlhf3 | 1. Brute Force:\n# Intuition \n- Only four 2x2 Squares are possible, check for all of them.\n# Approach \n1. The problem requires determining if it\'s possible | fahad_Mubeen | NORMAL | 2024-04-27T16:03:03.106042+00:00 | 2024-05-06T03:35:01.299726+00:00 | 2,046 | false | ## 1. Brute Force:\n# Intuition \n- Only four **2x2 Squares** are possible, check for all of them.\n# Approach \n1. The problem requires determining if it\'s possible to create a 2x2 square of the same color by changing at most one cell in the given 3x3 grid. \n2. Thus we examines each potential 2x2 square configuratio... | 20 | 1 | ['Math', 'Matrix', 'C++'] | 7 |
make-a-square-with-the-same-color | Python 3 || 4 lines, countOf || T/S: 99% / 23% | python-3-4-lines-countof-ts-99-23-by-spa-4tuu | Here\'s the intuition:\nThe problem is equvalent to determining whether any of the four 2x2 squares in grid do NOT have exactly 2 black (or white) squares.\n\nH | Spaulding_ | NORMAL | 2024-04-27T16:04:10.599980+00:00 | 2024-05-24T17:59:30.524560+00:00 | 470 | false | Here\'s the intuition:\nThe problem is equvalent to determining whether any of the four 2x2 squares in `grid` do NOT have exactly 2 black (or white) squares.\n\nHere\'s the plan:\nWe iterate through each of the four 2x2 squares, determining whether its count of black cells is NOT two. If we find one such square, we ret... | 14 | 0 | ['Python', 'Python3'] | 0 |
make-a-square-with-the-same-color | Easy Video Solution 🔥 || Interview Approach || Brute Force Solution | easy-video-solution-interview-approach-b-vyzd | If you like the solution Please Upvote and subscribe to my youtube channel\n\n# Intuition\n Describe your first thoughts on how to solve this problem. \nDry Run | ayushnemmaniwar12 | NORMAL | 2024-04-27T16:02:42.578469+00:00 | 2024-04-27T17:12:58.581468+00:00 | 1,212 | false | ***If you like the solution Please Upvote and subscribe to my youtube channel***\n\n# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nDry Run few examples and note your observations clearly\n\n\n\n***Easy Video Explanation***\n\nhttps://youtu.be/wo-tlC_Ms1s\n\n# Code\n```\nclass Solution... | 14 | 2 | ['Matrix', 'C++'] | 2 |
make-a-square-with-the-same-color | Easy solution - 27/04/2024 contest | easy-solution-27042024-contest-by-mangeu-2jwj | Intuition\n Describe your first thoughts on how to solve this problem. \nWe just check for the 4 top left square if there is at least 3 square with the same col | MangeurDeSushi | NORMAL | 2024-04-27T16:02:18.035742+00:00 | 2024-04-27T17:19:59.789598+00:00 | 1,400 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWe just check for the 4 top left square if there is at least 3 square with the same color under, on the right, and under on the right, if that\'s the case, we can just modify one of this square to have 4 squares with the same color.\ndon\... | 14 | 0 | ['Array', 'Math', 'Matrix', 'Python', 'C++', 'Java', 'Python3'] | 2 |
make-a-square-with-the-same-color | Simple java solution | simple-java-solution-by-siddhant_1602-aex2 | Complexity\n- Time complexity: O(1)\n\n- Space complexity: O(1)\n\n# Code\n\nclass Solution {\n public boolean canMakeSquare(char[][] grid) {\n for(in | Siddhant_1602 | NORMAL | 2024-04-27T16:01:36.609005+00:00 | 2024-04-27T16:01:36.609027+00:00 | 949 | false | # Complexity\n- Time complexity: $$O(1)$$\n\n- Space complexity: $$O(1)$$\n\n# Code\n```\nclass Solution {\n public boolean canMakeSquare(char[][] grid) {\n for(int i=0;i<=1;i++)\n {\n for(int j=0;j<=1;j++)\n {\n if(check(grid,i,j))\n {\n ... | 13 | 0 | ['Java'] | 2 |
make-a-square-with-the-same-color | Easy Solution - Just Count White and Black Color. | easy-solution-just-count-white-and-black-9suu | Intuition\n- Count the number of white and black cell in each (2 x 2) matrix.\n Describe your first thoughts on how to solve this problem. \n\n# Complexity\n- T | ANMOL_IS_HERE | NORMAL | 2024-04-27T18:22:54.429291+00:00 | 2024-04-27T18:32:05.728821+00:00 | 201 | false | # Intuition\n- Count the number of white and black cell in each (2 x 2) matrix.\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Complexity\n- Time complexity:O(2*2) Since size of matrix is definate (given in Constraints).\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space comple... | 9 | 0 | ['Counting', 'C++'] | 0 |
make-a-square-with-the-same-color | C++ || Pre-Computation 2D Sum | c-pre-computation-2d-sum-by-abhay5349sin-zva6 | Connect with me on LinkedIn: https://www.linkedin.com/in/abhay5349singh/\n\nApproach:\n mapping white:0 and blue:1\n pre-computing sum matrix for rectangle [x1, | abhay5349singh | NORMAL | 2024-04-27T16:01:54.310877+00:00 | 2024-04-27T17:21:13.889423+00:00 | 873 | false | **Connect with me on LinkedIn**: https://www.linkedin.com/in/abhay5349singh/\n\n**Approach:**\n* mapping `white:0` and `blue:1`\n* pre-computing sum matrix for rectangle `[x1, y2] => [x2, y2]`\n* consider square window of size `k` (here it\'s 2) and checking bounded sum\n\t* `sum = 1` (change 1 blue to white), `sum = 3... | 8 | 1 | [] | 1 |
make-a-square-with-the-same-color | [Python3] Simple Solution | python3-simple-solution-by-dolong2110-vsp1 | 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 | dolong2110 | NORMAL | 2024-04-28T07:52:38.383708+00:00 | 2024-04-28T07:52:38.383738+00:00 | 92 | 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: $$O(2 * 2)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(1)$$\n<!-- Add your space complexity ... | 5 | 0 | ['Matrix', 'Python3'] | 0 |
make-a-square-with-the-same-color | check 4 2x2 squares||0ms beats 100% | check-4-2x2-squares0ms-beats-100-by-anwe-ianz | Intuition\n Describe your first thoughts on how to solve this problem. \nThere are 4 2x2 squares.\nCheck every one\n# Approach\n Describe your approach to solvi | anwendeng | NORMAL | 2024-04-27T16:25:25.140626+00:00 | 2024-04-27T16:25:25.140648+00:00 | 170 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThere are 4 2x2 squares.\nCheck every one\n# Approach\n<!-- Describe your approach to solving the problem. -->\nIt needs to check any of the square has number of \'B\' <=1 or >=3 then return true. If none return false\n# Complexity\n- Tim... | 5 | 1 | ['C++'] | 1 |
make-a-square-with-the-same-color | simplest approach | two loops | count | simplest-approach-two-loops-count-by-use-8gnh | Intuition\n Describe your first thoughts on how to solve this problem. \nThe intution is to find what the neighbours of the current cell is doing.\nhere neighbo | user8093wK | NORMAL | 2024-04-28T08:23:47.923657+00:00 | 2024-04-28T08:23:47.923683+00:00 | 104 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe intution is to find what the neighbours of the current cell is doing.\nhere neighbours of grid[ i ][ j ] is\n grid[ i ] [ j+1 ],\n grid[ i+1 ] [ j ],\n grid[ i+1 ] [ j+1 ].\n\n# Approach\n<!-- Describe your approach to solving the pro... | 4 | 0 | ['C++'] | 0 |
make-a-square-with-the-same-color | 💥☠️🔥 Easiest C++✅Python3✅C#✅Java✅Python🐍✅C✅👾 Explained🏆 Contest - 27/04/2024 ⚡💥🔥✨⭐ | easiest-cpython3cjavapythonc-explained-c-ugja | Intuition\n\n\n\n\n\n Describe your first thoughts on how to solve this problem. \nC++ []\nclass Solution {\npublic:\n bool canMakeSquare(vector<vector<char> | Edwards310 | NORMAL | 2024-04-27T16:05:39.790184+00:00 | 2024-04-27T16:43:37.500831+00:00 | 242 | false | # Intuition\n\n\n\n {\n | shishirRsiam | NORMAL | 2024-04-27T16:56:39.262445+00:00 | 2024-04-27T16:56:39.262468+00:00 | 173 | false | # if it\'s help, please up \u2B06 vote! \u2764\uFE0F\n\n\n# Code\n```\nclass Solution {\npublic:\n bool fun2(vector<vector<char>>& grid, int i, int j)\n {\n return (grid[i][j] == grid[i][j+1] and grid[i][j] == grid[i-1][j+1]);\n }\n bool fun(vector<vector<char>>& grid, int i, int j)\n {\n b... | 3 | 0 | ['String', 'Matrix', 'Simulation', 'C++'] | 3 |
make-a-square-with-the-same-color | Easy to Understand | O(1) | 0ms Runtime | Beats 100%🔥😎 | easy-to-understand-o1-0ms-runtime-beats-h27uh | IntuitionCheck if a 2X2 grid for the same color can be formed.ApproachIterate over each cell and check if consecutive one is same.Complexity
Time complexity: O( | tyagideepti9 | NORMAL | 2025-01-27T17:15:10.784530+00:00 | 2025-01-27T17:15:10.784530+00:00 | 66 | false | # Intuition
Check if a 2X2 grid for the same color can be formed.
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
Iterate over each cell and check if consecutive one is same.
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity: O(1)
<!-- Add your time ... | 2 | 0 | ['C#'] | 1 |
make-a-square-with-the-same-color | Solution in C | solution-in-c-by-akcyyix0sj-7b38 | Code | vickyy234 | NORMAL | 2025-01-06T14:57:21.194775+00:00 | 2025-01-06T14:57:21.194775+00:00 | 63 | false | # Code
```c []
bool canMakeSquare(char** grid, int gridSize, int* gridColSize) {
*gridColSize = 3;
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++) {
int w = 0, b = 0;
if (grid[i][j] == 'W')
w++;
else
b++;
if (grid[... | 2 | 0 | ['C'] | 0 |
make-a-square-with-the-same-color | Easy code using 2 If cases only. | easy-code-using-2-if-cases-only-by-sapil-adey | We just traverse through the matrix and look for a 2x2 square by checking if any of the ith element i+1th element , j+1th element and the diagonal / (i+1,j+1)th | LeadingTheAbyss | NORMAL | 2024-11-25T20:26:42.756438+00:00 | 2024-11-25T20:42:15.368468+00:00 | 54 | false | We just traverse through the matrix and look for a `2x2` square by checking if any of the `i`th element `i+1`th element , `j+1`th element and the `diagonal` / `(i+1,j+1)`th element is of the same color , if they are then we can make one change to make a `2x2` box of same color else we can not.\n\n# Code\n```cpp []\ncla... | 2 | 0 | ['C++'] | 0 |
make-a-square-with-the-same-color | Beats 100% of Java + 99% Memory - Hardcoded | beats-100-of-java-99-memory-hardcoded-by-zt2p | Intuition\nIf the problem is small, make it efficient.\n\n# Approach\nWithin the constraints of the problem, outside that this is completely unscalable.\n\n# Co | taylorthurman | NORMAL | 2024-05-10T03:07:49.042879+00:00 | 2024-05-10T03:07:49.042898+00:00 | 154 | false | # Intuition\nIf the problem is small, make it efficient.\n\n# Approach\nWithin the constraints of the problem, outside that this is completely unscalable.\n\n# Complexity\n- Time complexity:\n$$O(n)$$\n\n- Space complexity:\n$$O(n)$$\n\n# Code\n```\nclass Solution {\n public boolean canMakeSquare(char[][] grid) {\n\... | 2 | 1 | ['Java'] | 0 |
make-a-square-with-the-same-color | "Beats 100%: Grid Transformation Trick! 🎨✨" | beats-100-grid-transformation-trick-by-c-fo6i | Intuition\nWhen faced with the task of determining if it\'s possible to create a 2x2 square of the same color in a given grid with the option to change the colo | CosmixCode | NORMAL | 2024-05-01T17:14:30.672286+00:00 | 2024-05-01T17:14:30.672311+00:00 | 142 | false | # Intuition\nWhen faced with the task of determining if it\'s possible to create a 2x2 square of the same color in a given grid with the option to change the color of at most one cell, we can approach the problem by observing the properties of such squares and devising a strategy to identify them.\n\n1. Understanding 2... | 2 | 0 | ['Java'] | 0 |
make-a-square-with-the-same-color | ⚡Clean & Best Code💯 || 🌟O(1) SC | clean-best-code-o1-sc-by-adish_21-5mhg | Complexity\n\n- Time complexity:\nO(1)\n\n- Space complexity:\nO(1)\n\n\n# Code\n## Please Upvote if it helps\uD83E\uDD17\n\nclass Solution {\npublic:\n bool | aDish_21 | NORMAL | 2024-04-30T18:47:46.624054+00:00 | 2024-04-30T18:47:46.624079+00:00 | 204 | false | # Complexity\n```\n- Time complexity:\nO(1)\n\n- Space complexity:\nO(1)\n```\n\n# Code\n## Please Upvote if it helps\uD83E\uDD17\n```\nclass Solution {\npublic:\n bool canMakeSquare(vector<vector<char>>& grid) {\n for(int i = 0 ; i < 2 ; i++){\n for(int j = 0 ; j < 2 ; j++){\n int B... | 2 | 0 | ['Matrix', 'C++'] | 0 |
make-a-square-with-the-same-color | Easy clean C++ code | easy-clean-c-code-by-omsl9850-umw7 | Intuition\nThe problem seems to involve checking whether it\'s possible to form a square by selecting a 2x2 subgrid in the given grid where at least three cells | omsl9850 | NORMAL | 2024-04-30T14:34:02.311491+00:00 | 2024-04-30T14:34:02.311512+00:00 | 36 | false | # Intuition\nThe problem seems to involve checking whether it\'s possible to form a square by selecting a 2x2 subgrid in the given grid where at least three cells have the same color.\n\n# Approach\nThe approach here is to iterate through all possible 2x2 subgrids in the grid. For each subgrid, count the number of whit... | 2 | 0 | ['C++'] | 0 |
make-a-square-with-the-same-color | 3127. 100% Minimalistic Python Solution | 3127-100-minimalistic-python-solution-by-siu8 | py\nclass Solution:\n def canMakeSquare(self, grid: List[List[str]]) -> bool:\n for i in range(2):\n for j in range(2):\n su | ssvadim | NORMAL | 2024-04-27T21:35:25.904681+00:00 | 2024-04-27T21:35:25.904712+00:00 | 166 | false | ```py\nclass Solution:\n def canMakeSquare(self, grid: List[List[str]]) -> bool:\n for i in range(2):\n for j in range(2):\n submatrix = (\n grid[i][j],\n grid[i + 1][j],\n grid[i][j + 1],\n grid[i + 1][j + 1... | 2 | 0 | ['Python3'] | 1 |
make-a-square-with-the-same-color | C++ || BRUTE FORCE ✅✅✅💯💯💯🔥🔥🔥 | c-brute-force-by-_kvschandra_2234-a26c | \n# Code\n\nbool check(unordered_map<char, int>& mp) {\n return (mp[\'W\'] == 3 && mp[\'B\'] == 1) || (mp[\'B\'] == 3 && mp[\'W\'] == 1) || mp[\'B\'] == 4 || | _kvschandra_2234 | NORMAL | 2024-04-27T16:02:40.051672+00:00 | 2024-04-27T16:04:01.285966+00:00 | 12 | false | \n# Code\n```\nbool check(unordered_map<char, int>& mp) {\n return (mp[\'W\'] == 3 && mp[\'B\'] == 1) || (mp[\'B\'] == 3 && mp[\'W\'] == 1) || mp[\'B\'] == 4 || mp[\'W\'] == 4;\n}\n\nclass Solution {\npublic:\n bool canMakeSquare(vector<vector<char>>& grid) {\n unordered_map<char, int> mp1, mp2, mp3, mp4;\... | 2 | 0 | ['C++'] | 0 |
make-a-square-with-the-same-color | c++[easy] 🎊 🔥 | ceasy-by-varuntyagig-5gf8 | Code | varuntyagig | NORMAL | 2025-03-06T09:32:51.655040+00:00 | 2025-03-06T09:32:51.655040+00:00 | 44 | false | # Code
```cpp []
class Solution {
public:
void calculateSum(vector<vector<char>>& grid, int x1, int y1, int x2,
int y2, int& sum) {
for (int i = x1; i < x2; ++i) {
for (int j = y1; j < y2; ++j) {
sum += grid[i][j];
}
}
}
bool canM... | 1 | 0 | ['Array', 'Matrix', 'C++'] | 0 |
make-a-square-with-the-same-color | ☑️ Checking if it is possible to Make a Square with the Same Color. ☑️ | checking-if-it-is-possible-to-make-a-squ-un08 | Code | Abdusalom_16 | NORMAL | 2025-02-21T05:51:19.997542+00:00 | 2025-02-21T05:51:19.997542+00:00 | 24 | false | # Code
```dart []
class Solution {
bool canMakeSquare(List<List<String>> grid) {
List<List<String>> list = [];
for(int i = 1; i < grid.length-1; i++){
list.add([grid[i][i-1], grid[i][i], grid[i-1][i-1], grid[i-1][i] ]);
list.add([grid[i][i], grid[i][i+1], grid[i-1][i], grid[i-1][i+1] ]);
... | 1 | 0 | ['Array', 'Matrix', 'Enumeration', 'Dart'] | 0 |
make-a-square-with-the-same-color | Python Solution | python-solution-by-nirmal1234-p3hw | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | Nirmal_Manoj | NORMAL | 2025-01-27T17:45:28.712163+00:00 | 2025-01-27T17:45:28.712163+00:00 | 41 | 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
`... | 1 | 0 | ['Python3'] | 1 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.