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
bulls-and-cows
[C++] 4ms Straight forward solution two pass O(N) time
c-4ms-straight-forward-solution-two-pass-wt1y
The idea is simple, if two char is match, add aCnt, otherwise, record it and process bCnt in second pass.\n\n class Solution {\n public:\n // only
moumoutsay
NORMAL
2015-10-30T20:25:23+00:00
2018-09-25T10:40:12.248885+00:00
25,878
false
The idea is simple, if two char is match, add aCnt, otherwise, record it and process bCnt in second pass.\n\n class Solution {\n public:\n // only contains digits \n string getHint(string secret, string guess) {\n int aCnt = 0;\n int bCnt = 0;\n vector<int> sVec(10, ...
144
5
[]
18
bulls-and-cows
My 3ms Java solution may help u
my-3ms-java-solution-may-help-u-by-blank-a9ad
public class Solution {\n public String getHint(String secret, String guess) {\n int len = secret.length();\n \t\tint[] secretarr = new int
blankj
NORMAL
2016-02-28T13:17:49+00:00
2018-09-09T01:29:05.470232+00:00
13,763
false
public class Solution {\n public String getHint(String secret, String guess) {\n int len = secret.length();\n \t\tint[] secretarr = new int[10];\n \t\tint[] guessarr = new int[10];\n \t\tint bull = 0, cow = 0;\n \t\tfor (int i = 0; i < len; ++i) {\n \t\t\tif (secret.charAt(i) == gue...
108
0
[]
17
bulls-and-cows
Python 3 lines solution
python-3-lines-solution-by-xcv58-y68d
use Counter to count guess and secret and sum their overlap. Then use zip to count A.\n\n s, g = Counter(secret), Counter(guess)\n a = sum(i == j
xcv58
NORMAL
2015-10-30T23:09:24+00:00
2018-10-19T05:28:37.374434+00:00
20,854
false
use `Counter` to count `guess` and `secret` and sum their overlap. Then use `zip` to count `A`.\n\n s, g = Counter(secret), Counter(guess)\n a = sum(i == j for i, j in zip(secret, guess))\n return '%sA%sB' % (a, sum((s & g).values()) - a)
105
4
['Python']
22
bulls-and-cows
3 lines in Python
3-lines-in-python-by-stefanpochmann-1j1l
def getHint(self, secret, guess):\n bulls = sum(map(operator.eq, secret, guess))\n both = sum(min(secret.count(x), guess.count(x)) for x in set(gu
stefanpochmann
NORMAL
2015-10-30T21:33:43+00:00
2018-10-16T03:07:10.116542+00:00
13,609
false
def getHint(self, secret, guess):\n bulls = sum(map(operator.eq, secret, guess))\n both = sum(min(secret.count(x), guess.count(x)) for x in set(guess))\n return \'%dA%dB\' % (bulls, both - bulls)
89
3
['Python']
21
bulls-and-cows
Very easy solution using two arrays
very-easy-solution-using-two-arrays-by-w-it8i
public class Solution {\n public String getHint(String secret, String guess) {\n int temp = 0;\n int bulls = 0;\n int[] nums1 = new int[
wei130
NORMAL
2015-12-30T21:12:58+00:00
2015-12-30T21:12:58+00:00
9,002
false
public class Solution {\n public String getHint(String secret, String guess) {\n int temp = 0;\n int bulls = 0;\n int[] nums1 = new int[10];\n int[] nums2 = new int[10];\n for(int i = 0; i < secret.length(); i++){\n char s = secret.charAt(i);\n char g = gu...
57
0
[]
9
bulls-and-cows
[Python] Simple solution with counters, explained
python-simple-solution-with-counters-exp-t8hy
Easy, but interesting problem, because it can be solved in different ways.\n\n1. Let us first evaluate number of bulls B: by definition it is number of places w
dbabichev
NORMAL
2020-09-10T07:17:42.321743+00:00
2020-09-10T07:17:42.321773+00:00
4,047
false
Easy, but interesting problem, because it can be solved in different ways.\n\n1. Let us first evaluate number of bulls `B`: by definition it is number of places with the same digit in `secret` and `guess`: so let us just traverse our strings and count it.\n2. Now, let us evaluate both number of cows and bulls: `B_C`: w...
55
6
[]
4
bulls-and-cows
C++, one pass, O(N) time, O(1) space
c-one-pass-on-time-o1-space-by-csosmo-pulm
class Solution {\n public:\n string getHint(string secret, string guess) {\n unordered_map<char, int> s_map;\n unordered_map<cha
csosmo
NORMAL
2015-10-30T21:22:16+00:00
2015-10-30T21:22:16+00:00
7,054
false
class Solution {\n public:\n string getHint(string secret, string guess) {\n unordered_map<char, int> s_map;\n unordered_map<char, int> g_map;\n int n = secret.size();\n int A = 0, B = 0;\n for (int i = 0; i < n; i++)\n {\n c...
47
3
['C++']
9
bulls-and-cows
Java solution with two buckets
java-solution-with-two-buckets-by-jump12-c5wn
public class Solution {\n public String getHint(String secret, String guess) {\n int bull = 0, cow = 0;\n \n int[] sarr
jump1221
NORMAL
2015-11-10T01:54:33+00:00
2018-10-07T21:00:24.333006+00:00
4,652
false
public class Solution {\n public String getHint(String secret, String guess) {\n int bull = 0, cow = 0;\n \n int[] sarr = new int[10];\n int[] garr = new int[10];\n \n for(int i = 0; i < secret.length(); i++){\n if(secret.charAt...
39
2
['Java']
1
bulls-and-cows
Fast and easy to understand Python solution O(n)
fast-and-easy-to-understand-python-solut-bzpy
\nclass Solution:\n def getHint(self, secret: str, guess: str) -> str:\n \n\t\t# The main idea is to understand that cow cases contain the bull cases\
mista2311
NORMAL
2020-04-04T18:31:43.515592+00:00
2020-04-04T18:31:43.515649+00:00
2,805
false
```\nclass Solution:\n def getHint(self, secret: str, guess: str) -> str:\n \n\t\t# The main idea is to understand that cow cases contain the bull cases\n\t\t\n\t\t# This loop will take care of "bull" cases\n bull=0\n for i in range(len(secret)):\n bull += int(secret[i] == guess[i])\n...
26
2
['Python', 'Python3']
3
bulls-and-cows
JavaScript solution
javascript-solution-by-linfongi-pwgj
function getHint(secret, guess) {\n var map = {};\n var A = 0;\n var B = 0;\n for (var i = 0; i < 10; i++) map[i] = 0;\n for (i = 0; i
linfongi
NORMAL
2015-12-13T05:15:30+00:00
2015-12-13T05:15:30+00:00
2,652
false
function getHint(secret, guess) {\n var map = {};\n var A = 0;\n var B = 0;\n for (var i = 0; i < 10; i++) map[i] = 0;\n for (i = 0; i < secret.length; i++) {\n if (secret[i] === guess[i]) A++;\n else {\n map[secret[i]]++;\n B += map[secret[i]] <= 0 ? 1 : 0;\...
25
0
['JavaScript']
0
bulls-and-cows
Java solution without hashing, 3ms
java-solution-without-hashing-3ms-by-sky-90hu
public String getHint(String secret, String guess) {\n \n if(secret.length() == 0){return "0A0B";}\n \n int bull = 0;\n int c
skyzhou012
NORMAL
2016-03-30T21:39:34+00:00
2016-03-30T21:39:34+00:00
3,800
false
public String getHint(String secret, String guess) {\n \n if(secret.length() == 0){return "0A0B";}\n \n int bull = 0;\n int cow = 0;\n int [] result = new int [10];\n \n for(int i = 0;i<secret.length();i++)\n {\n int x = secret.charAt(i) - 48;\n ...
23
0
['Java']
2
bulls-and-cows
PYTHON dict solution
python-dict-solution-by-yiling-imu2
class Solution(object):\n def getHint(self, secret, guess):\n """\n :type secret: str\n :type guess: str\n :r
yiling
NORMAL
2015-11-23T11:42:50+00:00
2015-11-23T11:42:50+00:00
3,176
false
class Solution(object):\n def getHint(self, secret, guess):\n """\n :type secret: str\n :type guess: str\n :rtype: str\n """\n d = {}\n bull, cow = 0,0\n \n for index,s in enumerate(secret):\n if...
18
0
['Python']
3
bulls-and-cows
Python simple solution
python-simple-solution-by-fan50-f880
class Solution(object):\n def getHint(self, secret, guess):\n """\n :type secret: str\n :type guess: str\n :r
fan50
NORMAL
2016-03-22T20:50:22+00:00
2018-08-23T02:12:21.256274+00:00
4,307
false
class Solution(object):\n def getHint(self, secret, guess):\n """\n :type secret: str\n :type guess: str\n :rtype: str\n """\n bulls = 0\n l1, l2 = [0]*10, [0]*10\n nums1, nums2 = map(int, secret), map(int, guess)\n ...
15
0
[]
2
bulls-and-cows
JAVA | HashMap / Frequency Array | Clean ✅
java-hashmap-frequency-array-clean-by-so-jo3z
Please Upvote :D\n##### 1. Using HashMap to store character frequency:\n\nclass Solution {\n public String getHint(String secret, String guess) {\n in
sourin_bruh
NORMAL
2022-10-25T12:52:15.992129+00:00
2022-10-25T12:52:15.992168+00:00
1,184
false
### **Please Upvote** :D\n##### 1. Using HashMap to store character frequency:\n```\nclass Solution {\n public String getHint(String secret, String guess) {\n int bulls = 0, cows = 0;\n\n Map<Character, Integer> secretFreq = new HashMap<>();\n Map<Character, Integer> guessFreq = new HashMap<>();...
14
0
['Array', 'Java']
0
bulls-and-cows
Easy java solution
easy-java-solution-by-danielfang-yx7q
public class Solution {\n public String getHint(String secret, String guess) {\n int bull = 0, cow = 0;\n int[] array = new int[10];\n \
danielfang
NORMAL
2016-01-14T06:25:31+00:00
2016-01-14T06:25:31+00:00
2,338
false
public class Solution {\n public String getHint(String secret, String guess) {\n int bull = 0, cow = 0;\n int[] array = new int[10];\n \n for(int i = 0; i < secret.length(); i++) {\n char s = secret.charAt(i);\n char g = guess.charAt(i);\n if(s == g){\...
14
0
[]
3
bulls-and-cows
Clean and Crisp C++
clean-and-crisp-c-by-vibhoar_bajaj-rwnm
```\nclass Solution {\npublic:\n string getHint(string secret, string guess) {\n unordered_map m;\n int b =0;\n int c=0;\n for(in
Vibhoar_Bajaj
NORMAL
2022-09-30T17:03:40.879961+00:00
2022-09-30T17:03:40.880011+00:00
829
false
```\nclass Solution {\npublic:\n string getHint(string secret, string guess) {\n unordered_map<char, int> m;\n int b =0;\n int c=0;\n for(int i =0;i<secret.size();i++){\n if(secret[i]== guess[i]){\n b++;\n }\n else{\n m[secret...
13
0
['C']
1
bulls-and-cows
C++ Super Simple Solution
c-super-simple-solution-by-debbiealter-0062
\nclass Solution {\npublic:\n string getHint(string secret, string guess)\n {\n map<char,int> secretMap, guessMap;\n int bulls = 0, cows = 0
debbiealter
NORMAL
2020-09-10T09:23:12.694312+00:00
2020-09-10T09:23:33.011902+00:00
1,314
false
```\nclass Solution {\npublic:\n string getHint(string secret, string guess)\n {\n map<char,int> secretMap, guessMap;\n int bulls = 0, cows = 0;\n \n for (size_t i = 0; i < secret.length(); i++)\n {\n if(secret[i] == guess[i])\n {\n bulls++;\...
13
0
['C', 'C++']
0
bulls-and-cows
Java simple solution O(n) with Video explanation
java-simple-solution-on-with-video-expla-wpfh
\n\n```\nclass Solution {\n \n // O(n) time complexity , O(1) =>Space\n public String getHint(String secret, String guess) {\n int bulls =0;\n
learner18
NORMAL
2020-09-10T08:43:33.781189+00:00
2020-09-10T08:43:33.781218+00:00
554
false
<iframe width="650" height="450" src="https://www.youtube.com/embed/sEGa8F2pMS8" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>\n\n```\nclass Solution {\n \n // O(n) time complexity , O(1) =>Space\n public String getHint(String secret, ...
11
3
[]
0
bulls-and-cows
My Concise JAVA Solution
my-concise-java-solution-by-coderoath-7yhu
public String getHint(String secret, String guess) {\n int a=0,b=0;\n int[] digits=new int[10];\n for(int i=0;i<secret.length();i++){\n
coderoath
NORMAL
2015-10-31T08:22:40+00:00
2015-10-31T08:22:40+00:00
2,511
false
public String getHint(String secret, String guess) {\n int a=0,b=0;\n int[] digits=new int[10];\n for(int i=0;i<secret.length();i++){\n if(secret.charAt(i)==guess.charAt(i)) a++;\n else{\n if(++digits[secret.charAt(i)-'0']<=0) b++;\n if(--digi...
11
1
['Java']
2
bulls-and-cows
✔️ 8ms solution | C++
8ms-solution-c-by-coding_menance-gmm4
Here is the code for C++ along with explanation in comments:\n\n# Code\n\nclass Solution {\npublic:\n string getHint(string secret, string guess) {\n
coding_menance
NORMAL
2022-11-04T18:13:39.624589+00:00
2022-11-04T18:13:39.624628+00:00
1,291
false
Here is the code for C++ along with explanation in comments:\n\n# Code\n```\nclass Solution {\npublic:\n string getHint(string secret, string guess) {\n vector<int> cowsS(10, 0);\n vector<int> cowsG(10, 0);\n\n int bulls{0}, cows{0};\n for (int i{0}; i<secret.size(); ++i) {\n /...
10
0
['String', 'C++']
1
bulls-and-cows
✔️ Python O(n) Solution Using Hashmap with Explanation | 99% Faster 🔥
python-on-solution-using-hashmap-with-ex-7qgf
\uD83D\uDD3C IF YOU FIND THIS POST HELPFUL PLEASE UPVOTE \uD83D\uDC4D\n\n\nclass Solution:\n def getHint(self, secret: str, guess: str) -> str:\n # Di
pniraj657
NORMAL
2022-10-20T04:51:02.734201+00:00
2022-10-31T05:29:41.665863+00:00
2,241
false
**\uD83D\uDD3C IF YOU FIND THIS POST HELPFUL PLEASE UPVOTE \uD83D\uDC4D**\n\n```\nclass Solution:\n def getHint(self, secret: str, guess: str) -> str:\n # Dictionary for Lookup\n lookup = Counter(secret)\n \n x, y = 0, 0\n \n # First finding numbers which are at correct posi...
9
0
['Python', 'Python3']
3
bulls-and-cows
JavaScript 93.83% one pass
javascript-9383-one-pass-by-shengdade-1bb9
\n/**\n * @param {string} secret\n * @param {string} guess\n * @return {string}\n */\nvar getHint = function(secret, guess) {\n let bull = 0;\n let cow = 0;\n
shengdade
NORMAL
2020-01-28T01:54:29.154307+00:00
2020-01-28T01:54:29.154361+00:00
1,258
false
```\n/**\n * @param {string} secret\n * @param {string} guess\n * @return {string}\n */\nvar getHint = function(secret, guess) {\n let bull = 0;\n let cow = 0;\n const map = {};\n for (let i = 0; i < secret.length; i++) {\n const s = secret.charAt(i);\n const g = guess.charAt(i);\n if (s === g) {\n bu...
9
0
['JavaScript']
0
bulls-and-cows
4ms C++ One Array Clean Solution
4ms-c-one-array-clean-solution-by-spanla-w741
class Solution {\n public:\n string getHint(string secret, string guess) {\n int map[10] = {0};\n int a = 0, b = 0;\n
spanlabs
NORMAL
2015-11-09T23:53:44+00:00
2015-11-09T23:53:44+00:00
818
false
class Solution {\n public:\n string getHint(string secret, string guess) {\n int map[10] = {0};\n int a = 0, b = 0;\n for (int i = 0; i < guess.size(); ++i) {\n if (guess[i] == secret[i]) ++a;\n ++map[guess[i] - '0'];\n }\n ...
9
0
[]
0
bulls-and-cows
Java without hash( 3 ms)
java-without-hash-3-ms-by-skoy12-muj8
public String getHint(String secret, String guess) {\n char[] s = secret.toCharArray();\n char[] g = guess.toCharArray();\n int a = 0, b =
skoy12
NORMAL
2016-05-31T02:10:07+00:00
2016-05-31T02:10:07+00:00
937
false
public String getHint(String secret, String guess) {\n char[] s = secret.toCharArray();\n char[] g = guess.toCharArray();\n int a = 0, b = 0;\n int[] count = new int[10];\n for(int i = 0; i < s.length; i++){\n if(s[i] == g[i]) a++;\n else{\n if...
9
0
[]
0
bulls-and-cows
java simple solution beats 100% in time
java-simple-solution-beats-100-in-time-b-7y3u
\nclass Solution {\n public String getHint(String secret, String guess) {\n int bull = 0;\n int[] countsSecret = new int[10];\n int[] co
jasonhey93
NORMAL
2020-02-18T16:23:37.768181+00:00
2020-02-18T16:23:37.768215+00:00
817
false
```\nclass Solution {\n public String getHint(String secret, String guess) {\n int bull = 0;\n int[] countsSecret = new int[10];\n int[] countsGuess = new int[10];\n for (int i = 0; i < secret.length(); i++) {\n char a = secret.charAt(i);\n char b = guess.charAt(i);\...
8
0
['Java']
1
bulls-and-cows
a few solutions
a-few-solutions-by-claytonjwong-xueg
For each ith digit in A and B, there are 2 use cases to consider:\n Case 1: if it\'s the same digit, then increment bull for the digit\n Case 2: if it\'s not th
claytonjwong
NORMAL
2019-10-12T00:53:49.414796+00:00
2023-01-01T23:53:35.822214+00:00
312
false
For each `i`<sup>th</sup> digit in `A` and `B`, there are 2 use cases to consider:\n* **Case 1:** if it\'s the same digit, then increment `bull` for the digit\n* **Case 2:** if it\'s *not* the same digit, then increment the digit count for `A` and `B` via `\uD83D\uDDFA` maps `first` and `second` correspondingly\n\nThen...
8
0
[]
1
bulls-and-cows
Python solution using a Counter
python-solution-using-a-counter-by-jddym-xy50
I think the most tricky part is just to understand what cows mean... \n\n class Solution(object):\n def getHint(self, secret, guess):\n """\n
jddymx
NORMAL
2015-11-07T08:07:17+00:00
2015-11-07T08:07:17+00:00
1,068
false
I think the most tricky part is just to understand what cows mean... \n\n class Solution(object):\n def getHint(self, secret, guess):\n """\n :type secret: str\n :type guess: str\n :rtype: str\n """\n from collections import Counter\n c = Counter(secret)\n b...
8
0
['Python']
0
bulls-and-cows
Java: Beats 100%
java-beats-100-by-deleted_user-by93
Java: Beats 100%\n\n\n\n# Code\n\nclass Solution {\n public String getHint(String secret, String guess) {\n int secdigs[] = new int[10];\n int
deleted_user
NORMAL
2024-05-09T11:26:43.356167+00:00
2024-05-09T11:26:43.356206+00:00
416
false
Java: Beats 100%\n![image.png](https://assets.leetcode.com/users/images/9806b74d-019a-4a87-a3f0-a007fb264570_1715253981.3605008.png)\n\n\n# Code\n```\nclass Solution {\n public String getHint(String secret, String guess) {\n int secdigs[] = new int[10];\n int guessdigs[] = new int[10];\n int bul...
7
0
['Java']
0
bulls-and-cows
[Python] Very simple space O(1) solution without fancy tricks
python-very-simple-space-o1-solution-wit-1joa
It\'s straightforward to calculate bulls - if the characters at the same index are identical in two strings, we add 1 to bulls.\nThe core idea to calculate cows
shanetsui
NORMAL
2020-05-18T05:17:59.722121+00:00
2020-05-18T05:25:59.756507+00:00
405
false
It\'s straightforward to calculate bulls - if the characters at the same index are identical in two strings, we add 1 to bulls.\nThe core idea to calculate cows is to match the rest characters (the ones unmatched in bulls) as much as possible. We calculate it as (\'-\' means minus) :\n\n**cows = characters matched at d...
7
0
[]
1
bulls-and-cows
4ms concise c++ solution
4ms-concise-c-solution-by-liankaohk-swgc
class Solution {\n public:\n string getHint(string secret, string guess) {\n vector<int> s(10, 0); // s[i]: number of occurrences of i in s
liankaohk
NORMAL
2015-12-30T08:35:07+00:00
2015-12-30T08:35:07+00:00
1,048
false
class Solution {\n public:\n string getHint(string secret, string guess) {\n vector<int> s(10, 0); // s[i]: number of occurrences of i in secret\n vector<int> g(10, 0); // g[i]: number of occurrences of i in guess\n int A = 0;\n for(int i = 0; i < secret.size();...
7
1
['C++']
2
bulls-and-cows
Easy c++ solution with unordered_map
easy-c-solution-with-unordered_map-by-vo-yzls
string getHint(string secret, string guess) {\n \tunordered_map<char, int> mp;\n \tint n = secret.size(), cA = 0, cB = 0;\n \tfor (int i = 0; i < n; i+
voka
NORMAL
2016-05-24T12:30:52+00:00
2016-05-24T12:30:52+00:00
728
false
string getHint(string secret, string guess) {\n \tunordered_map<char, int> mp;\n \tint n = secret.size(), cA = 0, cB = 0;\n \tfor (int i = 0; i < n; i++) {\n \t\tif (secret[i] == guess[i]) {\n \t\t\tcA++;\n \t\t\tcontinue;\n \t\t}\n \t\tmp[secret[i]]++;\n \t}\n \tfor (int i = 0; i < n;...
7
0
[]
0
bulls-and-cows
299: Time 98.43% and Space 98.71%, Solution with step by step explanation
299-time-9843-and-space-9871-solution-wi-2w8c
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n1. Define the function getHint that takes two strings secret and guess as
Marlen09
NORMAL
2023-02-28T05:06:11.275903+00:00
2023-02-28T05:06:11.275954+00:00
2,422
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n1. Define the function getHint that takes two strings secret and guess as input and returns a string.\n2. Initialize two dictionaries secret_dict and guess_dict to store the frequencies of digits in the secret and guess stri...
6
0
['Hash Table', 'String', 'Counting', 'Python', 'Python3']
1
bulls-and-cows
Bulls and Cows - O(N) time Clear solution
bulls-and-cows-on-time-clear-solution-by-jshh
\nclass Solution:\n \n def getHint(self, secret, guess):\n \n # char freq map for guests\n\t\t\n freqMap = {}\n \n for
onlyfaang
NORMAL
2020-09-10T07:14:25.149513+00:00
2020-09-10T07:15:02.602148+00:00
625
false
```\nclass Solution:\n \n def getHint(self, secret, guess):\n \n # char freq map for guests\n\t\t\n freqMap = {}\n \n for num in guess:\n \n if not num in freqMap:\n freqMap[num] = 0\n \n freqMap[num] += 1\n\t\t\t\n\...
6
1
[]
3
bulls-and-cows
Solution in Python 3 (beats ~98%)
solution-in-python-3-beats-98-by-junaidm-eott
```\nfrom collections import Counter\n\nclass Solution:\n def getHint(self, secret: str, guess: str) -> str:\n \ts, g, i = list(secret), list(guess), 0\n
junaidmansuri
NORMAL
2019-08-04T12:42:58.437542+00:00
2019-08-04T12:46:23.996665+00:00
1,026
false
```\nfrom collections import Counter\n\nclass Solution:\n def getHint(self, secret: str, guess: str) -> str:\n \ts, g, i = list(secret), list(guess), 0\n \twhile i < len(s):\n \t\tif g[i] == s[i]:\n \t\t\tdel s[i], g[i]\n \t\t\ti -= 1\n \t\ti += 1\n \treturn str(len(secret)-len(s))+\'A\'+str(sum...
6
1
['Python', 'Python3']
3
bulls-and-cows
Swift solution 40ms
swift-solution-40ms-by-jesen860-zuct
\nclass Solution {\n func getHint(_ secret: String, _ guess: String) -> String {\n var bull = 0\n var cow = 0\n \n let s = Array(
jesen860
NORMAL
2018-10-07T15:05:55.557693+00:00
2018-10-07T15:05:55.557738+00:00
249
false
```\nclass Solution {\n func getHint(_ secret: String, _ guess: String) -> String {\n var bull = 0\n var cow = 0\n \n let s = Array(secret)\n let g = Array(guess)\n var num = [Character : Int]()\n \n for i in 0 ..< s.count {\n if s[i] == g[i] {\n ...
6
0
[]
0
bulls-and-cows
O(n) time; O(1) space
on-time-o1-space-by-kingkingking888-b6qt
public class Solution {\n public String getHint(String secret, String guess) {\n int bulls=0;\n int cows=0;\n int[] count=new int[10];\n
kingkingking888
NORMAL
2015-10-31T21:38:41+00:00
2015-10-31T21:38:41+00:00
823
false
public class Solution {\n public String getHint(String secret, String guess) {\n int bulls=0;\n int cows=0;\n int[] count=new int[10];\n \n /*loop once \n 1231\n 0230\n \n 0231\n 1230\n \n gor guess, count--; for...
6
2
[]
0
bulls-and-cows
C++ simple solution using array with explaination (4ms)
c-simple-solution-using-array-with-expla-pqkq
If secret[i] and guess[i] match that's a bull - that's simple. Trickier part is about cows.\nWe use array numbers to remember if the any of digits (from 0 to 9)
paul7
NORMAL
2015-11-14T21:34:22+00:00
2015-11-14T21:34:22+00:00
1,198
false
If **secret[i]** and **guess[i]** match that's a bull - that's simple. Trickier part is about cows.\nWe use array **numbers** to remember if the any of digits (from 0 to 9) is found in either *secret* or *guess*.\nWhen digit is found in *secret* we decrement value of **numbers[digit]** if digit is found in *guess* we i...
6
1
['Array', 'C++']
1
bulls-and-cows
My one-pass solution in C++
my-one-pass-solution-in-c-by-nyycbd-0bdz
class Solution {\n public:\n string getHint(string secret, string guess) {\n vector<int>tb_guess(10),tb_secret(10);\n int A=0,B=
nyycbd
NORMAL
2016-04-21T10:38:02+00:00
2016-04-21T10:38:02+00:00
764
false
class Solution {\n public:\n string getHint(string secret, string guess) {\n vector<int>tb_guess(10),tb_secret(10);\n int A=0,B=0;\n for (int i=0;i<secret.size();++i){\n if (secret[i]==guess[i]) A++;\n else {\n tb_guess[gues...
6
0
[]
0
bulls-and-cows
Very straightforward solution
very-straightforward-solution-by-fisherc-pp7c
Also viewable here.\n\n\n public String getHint(String secret, String guess) {\n int[] secretCows = new int[10];\n int[] guessCows = new int[10
fishercoder
NORMAL
2016-10-28T16:58:52.898000+00:00
2016-10-28T16:58:52.898000+00:00
441
false
Also viewable [here](https://github.com/fishercoder1534/Leetcode/blob/master/leetcode-algorithms/src/main/java/com/stevesun/solutions/BullsandCows.java).\n```\n\n public String getHint(String secret, String guess) {\n int[] secretCows = new int[10];\n int[] guessCows = new int[10];\n int bulls =...
6
0
[]
0
bulls-and-cows
Java solution beats 99%, no hashmap, only one loop
java-solution-beats-99-no-hashmap-only-o-980g
\npublic class Solution {\n public String getHint(String secret, String guess) {\n int s, g, size = secret.length();\n int bulls = 0, cows = 0;
ayiayiyo
NORMAL
2016-08-17T18:38:33.336000+00:00
2016-08-17T18:38:33.336000+00:00
1,140
false
```\npublic class Solution {\n public String getHint(String secret, String guess) {\n int s, g, size = secret.length();\n int bulls = 0, cows = 0;\n int [] nums = new int [10];\n for (int i = 0; i < size; i++) {\n s = secret.charAt(i) - '0';\n g = guess.charAt(i) - '...
6
0
[]
1
bulls-and-cows
Java 🔝| 0ms 🔥 | Beat 💯
java-0ms-beat-by-sourabh-jadhav-h6km
\n# Code\n\nclass Solution {\n public String getHint(String secret, String guess) {\n int secdigs[] = new int[10];\n int guessdigs[] = new int[
sourabh-jadhav
NORMAL
2023-02-22T14:09:16.736973+00:00
2023-02-22T14:09:16.737005+00:00
651
false
\n# Code\n```\nclass Solution {\n public String getHint(String secret, String guess) {\n int secdigs[] = new int[10];\n int guessdigs[] = new int[10];\n int bull = 0, cow = 0;\n\n for(int i = 0; i < secret.length() ; i ++) {\n if(secret.charAt(i) == guess.charAt(i)) {\n ...
5
0
['Java']
1
bulls-and-cows
Best JS Sol. - with less runtime ms & 99% memory beat 🙌
best-js-sol-with-less-runtime-ms-99-memo-5k7h
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n1. The approach of th
Rajat310
NORMAL
2023-02-05T12:33:10.964223+00:00
2023-02-05T12:33:10.964279+00:00
280
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\n1. The approach of the function is to compare the characters of the two input strings sec and guess and count the number of matching characters in both the correct p...
5
0
['JavaScript']
0
bulls-and-cows
Easy Python Solution Using Counter
easy-python-solution-using-counter-by-la-77mt
Code\n\nclass Solution:\n def getHint(self, secret: str, guess: str) -> str:\n dic=Counter(secret)-Counter(guess)\n cnt=0\n for i in ran
Lalithkiran
NORMAL
2023-02-01T18:22:19.487459+00:00
2023-02-01T18:22:19.487512+00:00
1,531
false
# Code\n```\nclass Solution:\n def getHint(self, secret: str, guess: str) -> str:\n dic=Counter(secret)-Counter(guess)\n cnt=0\n for i in range(len(secret)):\n if secret[i]==guess[i]:\n cnt+=1\n cnt2=len(secret)-sum(dic.values())-cnt\n return str(cnt)+"A"+...
5
0
['Counting', 'Python3']
0
bulls-and-cows
python3, simple solution, defaultdict() for cows
python3-simple-solution-defaultdict-for-y3iop
ERROR: type should be string, got "https://leetcode.com/submissions/detail/875564006/\\nRuntime: 30 ms, faster than 99.56% of Python3 online submissions for Bulls and Cows. \\nMemory Usage: 14 MB,"
nov05
NORMAL
2023-01-09T05:50:01.345723+00:00
2023-01-10T16:44:58.837885+00:00
896
false
ERROR: type should be string, got "https://leetcode.com/submissions/detail/875564006/\\nRuntime: **30 ms**, faster than 99.56% of Python3 online submissions for Bulls and Cows. \\nMemory Usage: 14 MB, less than 29.43% of Python3 online submissions for Bulls and Cows. \\n```\\nclass Solution:\\n def getHint(self, secret: str, guess: str) -> str:\\n bulls, cows, ds, dg = 0, 0, defaultdict(lambda:0), defaultdict(lambda:0)\\n for s,g in zip(secret, guess):\\n if s==g:\\n bulls += 1\\n continue\\n ds[s]+=1; dg[g]+=1\\n for s in ds:\\n if s in dg:\\n cows += min(ds[s], dg[s])\\n return f\\'{bulls}A{cows}B\\'\\n```"
5
1
['Python', 'Python3']
1
bulls-and-cows
✔Easy Python solution using Hashmap
easy-python-solution-using-hashmap-by-sa-bpxq
Intuition\nFor bulls we have to check for the digits having same position in both the strings i.e. secret and guess, then will count for the rest of the digits
Saumya_Kumar
NORMAL
2023-01-04T16:13:17.710246+00:00
2023-01-04T16:13:17.710299+00:00
676
false
# Intuition\nFor bulls we have to check for the digits having same position in both the strings i.e. secret and guess, then will count for the rest of the digits which are common in both strings.\n\n# Approach\nWe will take **two dictionary** for **counting the frequency** of each digit occured in the respective string...
5
0
['Python3']
0
bulls-and-cows
A simple and clear python-solution
a-simple-and-clear-python-solution-by-m-fqfia
\n\tclass Solution:\n\t\tdef getHint(self, secret: str, guess: str) -> str:\n\t\t\tA = 0\n\t\t\tB = 0\n\t\t\tfor index in range(len(secret) - 1, -1, -1):\n\t\t\
m-d-f
NORMAL
2020-09-13T23:41:18.852243+00:00
2020-09-14T06:09:38.738764+00:00
679
false
\n\tclass Solution:\n\t\tdef getHint(self, secret: str, guess: str) -> str:\n\t\t\tA = 0\n\t\t\tB = 0\n\t\t\tfor index in range(len(secret) - 1, -1, -1):\n\t\t\t\tif secret[index] == guess[index]:\n\t\t\t\t\tA += 1\n\t\t\t\t\tsecret = secret[: index] + secret[index + 1 :]\n\t\t\t\t\tguess = guess[: index] + guess[index...
5
0
['Python3']
2
bulls-and-cows
Short and easy solution in C++, O(N), O(1) space
short-and-easy-solution-in-c-on-o1-space-yb0m
We can calculate count of Bulls easily by just couting where characters matches in the 2 given strings. Also, in the same iteration when characters don\'t match
vikasbhandari162
NORMAL
2020-09-11T06:38:16.657717+00:00
2020-09-11T06:39:22.229592+00:00
636
false
We can calculate count of ```Bulls``` easily by just couting where characters matches in the 2 given strings. Also, in the same iteration when characters don\'t match we can keep their count in mp1(for ```secret``` ) and mp2(for ```guess```) . Then we can iterate one of these constant size array and find the minimum of...
5
0
['Array', 'String', 'C']
1
bulls-and-cows
Python Simple Solution Explained (video + code)
python-simple-solution-explained-video-c-h9kz
\nhttps://www.youtube.com/watch?v=pHm7VOMzJpI\n\nclass Solution:\n def getHint(self, secret: str, guess: str) -> str:\n bulls = 0\n bucket = [0
spec_he123
NORMAL
2020-09-10T15:18:20.417853+00:00
2020-09-10T15:18:20.417893+00:00
712
false
[](https://www.youtube.com/watch?v=pHm7VOMzJpI)\nhttps://www.youtube.com/watch?v=pHm7VOMzJpI\n```\nclass Solution:\n def getHint(self, secret: str, guess: str) -> str:\n bulls = 0\n bucket = [0] * 10\n \n for s, g in zip(secret, guess):\n if s == g:\n bulls += 1\...
5
0
['Python', 'Python3']
0
bulls-and-cows
Clean and clear Java O(n) Solution
clean-and-clear-java-on-solution-by-xula-zc2o
public class Solution {\n public String getHint(String secret, String guess) {\n int A = 0, B = 0;\n int[] cnt = new int[10];\n
xulai_cao
NORMAL
2015-10-31T02:32:00+00:00
2015-10-31T02:32:00+00:00
1,018
false
public class Solution {\n public String getHint(String secret, String guess) {\n int A = 0, B = 0;\n int[] cnt = new int[10];\n for(int i=0; i<secret.length(); ++i){\n if(secret.charAt(i) == guess.charAt(i)) ++A;\n else{\n if(+...
5
0
['Array', 'Java']
0
bulls-and-cows
Two AC C++ solution, 92 ms and 4 ms.
two-ac-c-solution-92-ms-and-4-ms-by-heii-aomz
The basic idea of this problem is calculate Bulls number firstly, then calculate Cows number.\nThis is my first solution code:\n\n string getHint(string s, s
heii0w0rid
NORMAL
2015-11-02T06:55:51+00:00
2015-11-02T06:55:51+00:00
1,038
false
The basic idea of this problem is calculate Bulls number firstly, then calculate Cows number.\nThis is my first solution code:\n\n string getHint(string s, string g) \n {\n \tif (s.empty())\n \t\treturn "0A0B";\n \tint i, j, a, b;\n \tint sz = s.size();\n \ta = b = 0;\n \tvector<int> vs(sz, 1);\...
5
0
['C++']
0
bulls-and-cows
Java solution without HashTable
java-solution-without-hashtable-by-lyxst-anzj
public String getHint(String secret, String guess) {\n\n int bull=0;\n int cow=0;\n int[] marks=new int[10];\n int[] markg=new int[1
lyxstarter
NORMAL
2016-05-09T04:05:07+00:00
2016-05-09T04:05:07+00:00
1,072
false
public String getHint(String secret, String guess) {\n\n int bull=0;\n int cow=0;\n int[] marks=new int[10];\n int[] markg=new int[10];\n for(int i =0;i<secret.length();i++){\n if(secret.charAt(i)==guess.charAt(i))\n bull++;\n marks[secret.charAt(i)-'...
5
0
['Java']
0
bulls-and-cows
simple c++
simple-c-by-astha-vq5z
IntuitionApproachComplexity Time complexity: Space complexity: Code
astha_
NORMAL
2025-01-03T10:34:49.364402+00:00
2025-01-03T10:34:49.364402+00:00
612
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 `...
4
0
['C++']
1
bulls-and-cows
🚀🚀Java Solution Using HashMap with O(n)TC🚀🚀
java-solution-using-hashmap-with-ontc-by-yr5m
Intuition\nThe problem is about comparing two strings, secret and guess, to determine how many characters are "bulls" (correct in both position and character) a
Raghu_ram9000
NORMAL
2024-08-19T16:31:31.812750+00:00
2024-08-19T16:31:31.812776+00:00
187
false
# Intuition\nThe problem is about comparing two strings, secret and guess, to determine how many characters are "bulls" (correct in both position and character) and how many are "cows" (correct in character but not in position). The challenge is to do this efficiently, ensuring that we don\u2019t double-count any chara...
4
0
['Hash Table', 'Math', 'String', 'Brainteaser', 'Counting', 'Java']
0
bulls-and-cows
💥C++ | Beats 100% 🤘🏻 | hashTable 💥| Begineer friendly
c-beats-100-hashtable-begineer-friendly-jwx24
UPVOTE IF SOLUTION SEEMS GOOD TO YOU.\n\n# Code\n\n\nclass Solution {\npublic:\n string getHint(string secret, string guess) {\n int count = 0;\n
Kanishq_24je3
NORMAL
2024-02-23T07:32:23.338935+00:00
2024-02-23T07:32:23.338966+00:00
354
false
# UPVOTE IF SOLUTION SEEMS GOOD TO YOU.\n\n# Code\n```\n\nclass Solution {\npublic:\n string getHint(string secret, string guess) {\n int count = 0;\n int mount = 0; \n string ans = "";\n int hash[256] = {};\n for(int i = 0; i<secret.length();i++) {\n if(secret[i] == gue...
4
0
['C++']
0
bulls-and-cows
Python Easy Solution (Beats 99.5%)
python-easy-solution-beats-995-by-harsh4-u8la
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
Harsh425
NORMAL
2023-01-10T12:57:49.155037+00:00
2023-01-10T12:57:49.155091+00:00
1,109
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']
0
bulls-and-cows
C++ Good Code Quality One pass solution with great explanation.
c-good-code-quality-one-pass-solution-wi-qpja
Explanation:\nThe statement says that bull is a character which matches exactly to the guess position in secret.\nand Cows are character which are not in correc
akgupta0777
NORMAL
2023-01-06T10:03:13.905215+00:00
2023-01-13T09:29:35.870238+00:00
433
false
**Explanation:**\nThe statement says that bull is a character which matches exactly to the guess position in secret.\nand Cows are character which are not in correct position but can be rearranged to form the secret.\nIf we know the appearance of a character in secret appears before or not we can solve this problem eas...
4
0
['Array', 'Hash Table', 'Greedy', 'Counting', 'C++']
0
bulls-and-cows
Easy Java o(N) Solution by counting
easy-java-on-solution-by-counting-by-aay-ou2i
Intuition : Counting bulls and cows\n Describe your first thoughts on how to solve this problem. \n\n\n# Approach : Counting bulls by comparing and cows with th
aayush_sagar
NORMAL
2023-01-03T07:24:07.365526+00:00
2023-01-14T18:18:55.758238+00:00
865
false
# Intuition : Counting bulls and cows\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n\n# Approach : Counting bulls by comparing and cows with the help of an array\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: o(N)\n<!-- Add your time complexity her...
4
0
['Java']
1
bulls-and-cows
Very Easy Implementation in DP with 70% runtime.
very-easy-implementation-in-dp-with-70-r-2zee
\nclass Solution(object):\n def getHint(self, secret, guess):\n """\n :type secret: str\n :type guess: str\n :rtype: str\n
amit321kumar
NORMAL
2022-08-30T13:21:24.093198+00:00
2022-08-30T13:21:24.093235+00:00
428
false
```\nclass Solution(object):\n def getHint(self, secret, guess):\n """\n :type secret: str\n :type guess: str\n :rtype: str\n """\n bulls=0\n cows=0\n d1=collections.Counter(secret)\n d2=collections.Counter(guess)\n for i in d1:\n if i ...
4
0
['Dynamic Programming', 'Python']
0
bulls-and-cows
Layman Approach to understanding the problem statement
layman-approach-to-understanding-the-pro-4u9f
Ok, So let me explain you this in very layman terms.\n\n-So you know how to count for bulls, which ever character(digit) is at same place, you increase counter.
bitbybits
NORMAL
2022-01-26T12:29:58.583612+00:00
2022-01-26T12:29:58.583645+00:00
102
false
Ok, So let me explain you this in very layman terms.\n\n-So you know how to count for bulls, which ever character(digit) is at same place, you increase counter. Straight forward.\n-Coming to count cows. So think it in this way.\n\nIf you have bulls that mean "n" digits are at same place. So assume you removed the match...
4
0
[]
0
bulls-and-cows
2-pass & 1-pass solution Python
2-pass-1-pass-solution-python-by-kryuki-f0lh
2-pass solution\n\nfrom collections import Counter\n\nclass Solution:\n def getHint(self, secret: str, guess: str) -> str:\n secret_non_bull, guess_no
kryuki
NORMAL
2021-12-05T07:44:40.015565+00:00
2021-12-05T07:44:59.154576+00:00
483
false
**2-pass solution**\n```\nfrom collections import Counter\n\nclass Solution:\n def getHint(self, secret: str, guess: str) -> str:\n secret_non_bull, guess_non_bull = [], []\n num_bulls = 0\n for char1, char2 in zip(secret, guess):\n if char1 == char2:\n num_bulls += 1\n...
4
0
['Python', 'Python3']
0
bulls-and-cows
JavaScript / TypeScript Solution
javascript-typescript-solution-by-eddyhd-y8m9
// JS\n// Runtime: 84 ms, faster than 88.14% of JavaScript online submissions for Bulls and Cows.\n// Memory Usage: 39.3 MB, less than 46.05% of JavaScript onli
eddyhdzg
NORMAL
2020-09-11T21:12:23.847357+00:00
2020-09-11T21:12:23.847416+00:00
485
false
// JS\n// Runtime: 84 ms, faster than 88.14% of JavaScript online submissions for Bulls and Cows.\n// Memory Usage: 39.3 MB, less than 46.05% of JavaScript online submissions for Bulls and Cows.\n```\nvar getHint = function (secret, guess) {\n let bulls = 0;\n let cows = 0;\n const hash = {};\n\n for (let i = 0; i ...
4
0
['TypeScript', 'JavaScript']
0
bulls-and-cows
Java with some comments | HashMap | Two Pass
java-with-some-comments-hashmap-two-pass-vam4
\nclass Solution {\n public String getHint(String secret, String guess) {\n // first pass determine the A\n Map<Character, Integer> map1 = new
Hao_Code
NORMAL
2020-09-10T14:38:33.758844+00:00
2020-09-10T14:38:33.758871+00:00
375
false
```\nclass Solution {\n public String getHint(String secret, String guess) {\n // first pass determine the A\n Map<Character, Integer> map1 = new HashMap<>();\n Map<Character, Integer> map2 = new HashMap<>();\n int A = 0;\n for(int i = 0; i < secret.length(); i++) {\n ma...
4
0
['Java']
0
bulls-and-cows
JavaScript one pass with explanation and comments
javascript-one-pass-with-explanation-and-y9dc
\n/*\nbulls : exact\ncows: number match but position does not\n\ncreate a hashmap O(1) since it\'s fixed at most letters in alphabet {num:freq}\niterate through
alexanderywang
NORMAL
2020-09-10T12:43:54.666568+00:00
2020-09-10T12:43:54.666628+00:00
117
false
```\n/*\nbulls : exact\ncows: number match but position does not\n\ncreate a hashmap O(1) since it\'s fixed at most letters in alphabet {num:freq}\niterate through both strings at once, for every bull, keep a counter\n\nif match, don\'t update map. \'lock\' in the position\nelse \nif map[secret letter] is negative (fro...
4
0
[]
0
bulls-and-cows
Python simple intuitive solution
python-simple-intuitive-solution-by-yehu-ho9o
\nclass Solution:\n def getHint(self, secret: str, guess: str) -> str:\n bull, cow = 0, 0\n # keep in dict indexes of each numer:\n my_d
yehudisk
NORMAL
2020-09-10T07:52:45.756649+00:00
2020-09-10T07:52:45.756703+00:00
275
false
```\nclass Solution:\n def getHint(self, secret: str, guess: str) -> str:\n bull, cow = 0, 0\n # keep in dict indexes of each numer:\n my_dict = defaultdict(list)\n for i, num in enumerate(secret):\n my_dict[num].append(i)\n temp = ""\n # find exact matches:\n ...
4
0
['Python3']
0
bulls-and-cows
why is this an easy question?
why-is-this-an-easy-question-by-d00mer-po0h
I think this should be marked as medium, the only easy part of this question is easily messing up edge cases like:\n\n"1122"\n"1222"\n
d00mer
NORMAL
2020-08-19T20:48:43.859827+00:00
2020-08-19T20:49:17.649960+00:00
207
false
I think this should be marked as medium, the only easy part of this question is easily messing up edge cases like:\n```\n"1122"\n"1222"\n```
4
0
[]
1
bulls-and-cows
Decent Python Code Beats 99.77%
decent-python-code-beats-9977-by-xianggg-h8jf
\n def getHint(self, secret: str, guess: str) -> str:\n c, b = 0, 0\n for i in range(len(secret)):\n if secret[i] == guess[i]: b +=
xianggg
NORMAL
2020-06-18T14:37:05.582074+00:00
2020-06-24T14:09:24.056834+00:00
342
false
```\n def getHint(self, secret: str, guess: str) -> str:\n c, b = 0, 0\n for i in range(len(secret)):\n if secret[i] == guess[i]: b += 1\n for i in range(len(secret)):\n if secret[i] in guess:\n c += min(secret.count(secret[i]), guess.count(secret[i]))\n ...
4
1
['Python3']
3
bulls-and-cows
c++ O(n) faster than 99%
c-on-faster-than-99-by-siddharthchabuksw-pdxa
\nclass Solution {\npublic:\n string getHint(string secret, string guess) {\n int bull = 0, cow = 0, i, n = secret.length();\n int countS[10] =
siddharthchabukswar
NORMAL
2019-08-31T07:13:56.678166+00:00
2019-08-31T07:13:56.678201+00:00
423
false
```\nclass Solution {\npublic:\n string getHint(string secret, string guess) {\n int bull = 0, cow = 0, i, n = secret.length();\n int countS[10] = {0};\n int countG[10] = {0};\n for(i=0; i<n; i++){\n if(secret[i] == guess[i]) bull++;\n else{\n countS[s...
4
0
['C++']
0
bulls-and-cows
C# count A first then B
c-count-a-first-then-b-by-bacon-xetb
\npublic class Solution {\n public string GetHint(string secret, string guess) {\n var n = secret.Length;\n\n var countA = 0;\n var coun
bacon
NORMAL
2019-06-02T21:01:32.033831+00:00
2019-06-02T21:01:32.033877+00:00
176
false
```\npublic class Solution {\n public string GetHint(string secret, string guess) {\n var n = secret.Length;\n\n var countA = 0;\n var countB = 0;\n\n var charAndCountSecret = new int[256];\n var charAndCountGuess = new int[256];\n for (int i = 0; i < n; i++) {\n ...
4
0
[]
0
bulls-and-cows
javascript beats 100%. Self explanatory
javascript-beats-100-self-explanatory-by-6b45
``` var getHint = function(secret, guess) { let guessArr = new Array(10).fill(0); let secretArr = new Array(10).fill(0); let bull = 0; let cow = 0; getBul
blbb1111
NORMAL
2018-10-30T21:31:56.665231+00:00
2018-10-30T21:31:56.665288+00:00
416
false
``` var getHint = function(secret, guess) { let guessArr = new Array(10).fill(0); let secretArr = new Array(10).fill(0); let bull = 0; let cow = 0; getBulls(); getCows(); cow = cow - bull; return `${bull}A${cow}B`; function getBulls() { for (let i = 0; i < secret.length; i++) { secretArr[Nu...
4
0
[]
2
bulls-and-cows
Frequency Maps |✅ EZPZ🍋🤏| With Explanation
frequency-maps-ezpz-with-explanation-by-whnge
Intuition\n Describe your first thoughts on how to solve this problem. \nThere are two things to consider:\n1. Correct digits placed in correct locations\n2. Co
jorelm68
NORMAL
2024-11-14T18:24:42.015159+00:00
2024-11-14T18:24:42.015193+00:00
346
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThere are two things to consider:\n1. Correct digits placed in correct locations\n2. Correct digits placed in incorrect locations\nWe will first count the amount of correct digits placed in correct locations. Then, we will use frequency m...
3
0
['Hash Table', 'String', 'Counting', 'C++']
0
bulls-and-cows
C++ ✅ Commented | HashTable
c-commented-hashtable-by-taranum_01-2ew5
\n# Approach\n1. Iterate through the characters of both the secret and guess strings.\n2. For each character:\n a. If the characters at the same index in both
Taranum_01
NORMAL
2024-08-12T10:56:49.892866+00:00
2024-08-12T12:05:40.964003+00:00
549
false
\n# Approach\n1. Iterate through the characters of both the secret and guess strings.\n2. For each character:\n a. If the characters at the same index in both strings match, it\'s a bull (correct digit and position).\n b. If they don\'t match, keep track of the frequency of digits in both secret and guess.\n3. Afte...
3
0
['C++']
0
bulls-and-cows
🐮 Simple hashmap solution | Python
simple-hashmap-solution-python-by-rhuang-mo1s
Complexity\n- Time complexity: O(n)\n\n- Space complexity: O(n)\n\n# Code\n\nfrom collections import Counter\nclass Solution:\n def getHint(self, secret: str
rhuang53
NORMAL
2024-07-26T02:55:11.795251+00:00
2024-07-26T02:55:11.795280+00:00
580
false
# Complexity\n- Time complexity: O(n)\n\n- Space complexity: O(n)\n\n# Code\n```\nfrom collections import Counter\nclass Solution:\n def getHint(self, secret: str, guess: str) -> str:\n bulls = 0\n cows = 0\n\n char_freq = Counter(secret)\n\n for i in range(len(guess)):\n if gu...
3
0
['Hash Table', 'String', 'Counting', 'Python', 'Python3']
0
bulls-and-cows
Beats 100 % users space comlexity 0(1), time complexity 0(n) and dry run example ✅✅💯💯
beats-100-users-space-comlexity-01-time-xv3qj
Intuition\n Describe your first thoughts on how to solve this problem. \nThe first thought will come to your mind of counting then after that of using a map bu
pahadi_rawat
NORMAL
2024-01-11T18:50:10.552555+00:00
2024-01-12T09:13:02.367519+00:00
213
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe first thought will come to your mind of counting then after that of using a map but if we see the question smartly we will find that extra space needed is almost negligible because we have to check digits which are in the form of st...
3
0
['Hash Table', 'String', 'Counting', 'C++']
1
bulls-and-cows
Easy to understand C++ code !! Beginner Friendly
easy-to-understand-c-code-beginner-frien-hso6
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n1. Initialize an unorde
khaderitesh
NORMAL
2023-10-07T04:28:50.200640+00:00
2023-10-07T04:28:50.200668+00:00
334
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. Initialize an unordered_map m to store the frequency of each digit in the secret string.\n2. Initialize bulls and cows counters to 0 to keep track of the number of ...
3
0
['C++']
2
bulls-and-cows
C++ Solution using Map | O(n)
c-solution-using-map-on-by-lakshmi_prabh-j74b
Intuition\nShould find the number of bulls and cows. Can be solved by iterating over secret and guess, and comparing the characters. The comparison to be made f
lakshmi_prabha
NORMAL
2023-05-02T15:33:30.547001+00:00
2023-05-05T11:13:11.044700+00:00
597
false
# Intuition\nShould find the number of *bulls* and *cows*. Can be solved by iterating over $$secret$$ and $$guess$$, and comparing the characters. The comparison to be made for *bull* count and the *cow* count is different.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. we loop through each ...
3
0
['Hash Table', 'String', 'Counting', 'C++']
0
bulls-and-cows
Java Solution | Beats 100% 🔥| O(n)✅
java-solution-beats-100-on-by-ayushmangl-sxyn
UPVOTE \u2B06\uFE0F\uD83D\uDD1D\u2B06\uFE0F\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
ayushmanglik2003
NORMAL
2023-04-22T08:34:48.798142+00:00
2023-04-22T08:34:48.798174+00:00
374
false
# UPVOTE \u2B06\uFE0F\uD83D\uDD1D\u2B06\uFE0F\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 String getHint(String secret, String guess)...
3
0
['Hash Table', 'String', 'Counting', 'Java']
0
bulls-and-cows
Java. Bulls and Cows
java-bulls-and-cows-by-red_planet-x2ys
\n\nclass Solution {\n public String getHint(String secret, String guess) {\n StringBuilder first = new StringBuilder(secret);\n StringBuilder
red_planet
NORMAL
2023-04-03T09:29:33.237204+00:00
2023-04-03T09:29:33.237237+00:00
3,105
false
\n```\nclass Solution {\n public String getHint(String secret, String guess) {\n StringBuilder first = new StringBuilder(secret);\n StringBuilder second = new StringBuilder(guess);\n HashMap<Character, Integer> dict = new HashMap<>();\n int numA = 0;\n int numB = 0;\n for (i...
3
0
['Java']
1
bulls-and-cows
Easiest C++ solution | Intuition explained | w/ comments
easiest-c-solution-intuition-explained-w-5btn
Intuition\nWe need to keep track of only two conditions:\n1. Either the position of a character in both the string is same.(bull++), Or\n2. The position of a ch
arshikamishra
NORMAL
2023-03-29T20:01:27.111576+00:00
2023-04-19T19:26:59.639253+00:00
1,872
false
# Intuition\nWe need to keep track of only two conditions:\n1. Either the position of a character in both the string is same.(bull++), Or\n2. The position of a character is different but it is present in both the strings(cow++)\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n--> We c...
3
0
['Hash Table', 'Counting', 'C++']
0
bulls-and-cows
Solution in C++
solution-in-c-by-ashish_madhup-kt1f
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
ashish_madhup
NORMAL
2023-02-24T13:05:37.341235+00:00
2023-02-24T13:05:37.341279+00:00
475
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
['C++']
0
bulls-and-cows
✅ C++ || Beats 100% || Easy to understand || Beginner friendly
c-beats-100-easy-to-understand-beginner-1iimm
Intuition\nThere will be 3 cases at index i of the string:\n1. the characters of both string are same, then bull will be incremented by 1\n2. the characters of
codecommander03
NORMAL
2023-02-15T12:45:50.119563+00:00
2023-02-15T12:45:50.119605+00:00
183
false
# Intuition\nThere will be 3 cases at index i of the string:\n1. the characters of both string are same, then bull will be incremented by 1\n2. the characters of both strings are different but character present in guess string at index is occuring elsewhere(let\'s say index j, but character in secret string at index j ...
3
0
['String', 'Counting', 'Hash Function', 'C++']
0
bulls-and-cows
JAVA || HASHMAP SOLUTION || EASY
java-hashmap-solution-easy-by-sauravmeht-5ppz
Upvote if you understand !!\n# Code\n\nclass Solution {\n class Pair{\n int val;\n List<Integer> list;\n Pair(int val,List<Integer> list
Sauravmehta
NORMAL
2023-01-09T05:33:41.369050+00:00
2023-01-09T05:33:41.369099+00:00
1,521
false
**Upvote if you understand !!**\n# Code\n```\nclass Solution {\n class Pair{\n int val;\n List<Integer> list;\n Pair(int val,List<Integer> list){\n this.val=val;\n this.list=list;\n }\n }\n public String getHint(String secret, String guess) {\n int A = 0...
3
0
['Java']
0
bulls-and-cows
Microsoft⭐ || Easy Solution✔️ || Challenge🏆
microsoft-easy-solution-challenge-by-nan-yjbe
"Your thoughts are welcome! \uD83D\uDCAD"\n\n#ReviseWithArsh #6Companies30Days challenge 2k23 & 2k24*\nCompany 2 :- Microsoft\n\nDay1 - Q2. Bulls and Cows\n\n\n
nandini-gangrade
NORMAL
2023-01-03T21:09:13.952236+00:00
2024-01-12T12:33:05.156805+00:00
413
false
> ***"Your thoughts are welcome! \uD83D\uDCAD"***\n\n***```#ReviseWithArsh #6Companies30Days challenge 2k23 & 2k24```**\n**`` Company 2 :- Microsoft ``***\n\n*Day1 - Q2. Bulls and Cows*\n\n![3.bulls-and-cows.jpg](https://assets.leetcode.com/users/images/f5e0aa34-3b54-4db7-b070-cafe7e46978e_1672779956.6196964.jpeg)\n\n#...
3
0
['C++']
0
bulls-and-cows
[Java] 2ms, 99% + clear explanations
java-2ms-99-clear-explanations-by-stefan-xhkh
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n1. Traverse the two strings and keep track of the digits count in 2 x int
StefanelStan
NORMAL
2022-12-07T21:22:45.091556+00:00
2022-12-07T21:22:45.091610+00:00
472
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n1. Traverse the two strings and keep track of the digits count in 2 x int[10]\n2. While traversing, if current secret digit matches guess digit, only increment the bulls, but do not mark the digit count. This is because we ...
3
0
['Java']
1
bulls-and-cows
Single passing solution
single-passing-solution-by-lavkush_173-wxt6
public String getHint(String secret, String guess) {\n int bulls = 0;\n int cows = 0;\n int[] numbers = new int[10];\n for (int i = 0; i<secret.leng
Lavkush_173
NORMAL
2022-11-23T17:33:14.608076+00:00
2022-11-23T17:33:14.608114+00:00
221
false
public String getHint(String secret, String guess) {\n int bulls = 0;\n int cows = 0;\n int[] numbers = new int[10];\n for (int i = 0; i<secret.length(); i++) {\n if (secret.charAt(i) == guess.charAt(i)) bulls++;\n else {\n if (numbers[secret.charAt(i)-\'0\']++ < 0) cows++;\n ...
3
0
[]
0
bulls-and-cows
Python | O(N) | Dictionary Count | EZ solution
python-on-dictionary-count-ez-solution-b-bs7f
class Solution(object):\n def getHint(self, secret, guess):\n \n bulls, cows = 0, 0\n lenN = len(secret)\n \n secDic = { s
CosmosYu
NORMAL
2022-10-18T00:17:56.117155+00:00
2022-10-18T00:17:56.117185+00:00
151
false
class Solution(object):\n def getHint(self, secret, guess):\n \n bulls, cows = 0, 0\n lenN = len(secret)\n \n secDic = { str(i) : [0 , 0] for i in range(10)}\n \n for i in range(lenN):\n \n if(secret[i] == guess[i]):\n bulls += 1\n...
3
0
[]
1
bulls-and-cows
C++ SIMPLE SOLUTION USING MAP
c-simple-solution-using-map-by-abhay_123-xsnj
\nclass Solution {\npublic:\n string getHint(string &secret, string &guess) {\n int c = 0, b = 0, i = 0, n = secret.length();\n unordered_map<c
abhay_12345
NORMAL
2022-10-11T17:27:53.407544+00:00
2022-10-11T17:27:53.407589+00:00
822
false
```\nclass Solution {\npublic:\n string getHint(string &secret, string &guess) {\n int c = 0, b = 0, i = 0, n = secret.length();\n unordered_map<char,char> mp;\n for(i = 0; i < n; i++){\n if(secret[i]==guess[i]){\n b++;\n guess[i] = \'#\';\n }e...
3
0
['C', 'C++']
0
bulls-and-cows
Swift Clean Easy Solution
swift-clean-easy-solution-by-jfrsheriff-kqsi
\nclass Solution {\n func getHint(_ secret: String, _ guess: String) -> String {\n\t\n guard secret.count == guess.count else {return ""}\n \n
jfrsheriff
NORMAL
2022-10-09T15:34:06.951394+00:00
2022-10-09T15:34:27.360590+00:00
138
false
```\nclass Solution {\n func getHint(_ secret: String, _ guess: String) -> String {\n\t\n guard secret.count == guess.count else {return ""}\n \n var secretA = Array(secret)\n var guessA = Array(guess)\n \n var sDict : [Character : Int] = [:]\n var gDict : [Character ...
3
0
['Swift']
0
bulls-and-cows
O(N) time
on-time-by-droj-lcvx
\nclass Solution:\n def getHint(self, se: str, gu: str) -> str:\n dcse=defaultdict(lambda:0)\n dcgu=defaultdict(lambda:0)\n a=0\n
droj
NORMAL
2022-09-29T12:29:27.699600+00:00
2022-09-29T12:29:27.699634+00:00
561
false
```\nclass Solution:\n def getHint(self, se: str, gu: str) -> str:\n dcse=defaultdict(lambda:0)\n dcgu=defaultdict(lambda:0)\n a=0\n b=0\n for i in range(len(se)):\n if(se[i]==gu[i]):\n a+=1\n else:\n dcse[se[i]]+=1\n ...
3
0
['Python']
1
bulls-and-cows
✅✅Faster || Easy To Understand || C++ Code
faster-easy-to-understand-c-code-by-__kr-yspj
Using Unordered Map\n\n Time Complexity :- O(N)\n\n Space Complexity :- O(N)\n\n\nclass Solution {\npublic:\n string getHint(string secret, string guess) {\n
__KR_SHANU_IITG
NORMAL
2022-08-09T12:27:46.182139+00:00
2022-08-09T12:27:46.182189+00:00
226
false
* ***Using Unordered Map***\n\n* ***Time Complexity :- O(N)***\n\n* ***Space Complexity :- O(N)***\n\n```\nclass Solution {\npublic:\n string getHint(string secret, string guess) {\n \n int n = secret.size();\n \n // count the frequency of characters of secret\n \n unordered...
3
0
['C', 'C++']
0
bulls-and-cows
Easy C++ Code using Map
easy-c-code-using-map-by-karan252-c43f
\nclass Solution {\npublic:\n string getHint(string secret, string guess) {\n map<char,int> mp;\n int n=secret.size();\n int b=0,c=0;\n
karan252
NORMAL
2022-07-05T19:45:35.480592+00:00
2022-07-05T19:45:35.480668+00:00
382
false
```\nclass Solution {\npublic:\n string getHint(string secret, string guess) {\n map<char,int> mp;\n int n=secret.size();\n int b=0,c=0;\n for(int i=0;i<n;i++)\n {\n if(secret[i]==guess[i])\n b++;\n else\n mp[secret[i]]++;\n ...
3
0
['C', 'C++']
0
bulls-and-cows
C++ | HASING | COUNTING | FASTER
c-hasing-counting-faster-by-harshsinghs1-wotk
\nclass Solution {\npublic:\n string getHint(string secret, string guess) {\n int n = secret.size(), a[10] = {0},b[10] = {0},bulls = 0,cows = 0;\n
UnknownOffline
NORMAL
2022-07-01T02:29:35.979546+00:00
2022-07-01T02:29:35.979576+00:00
221
false
```\nclass Solution {\npublic:\n string getHint(string secret, string guess) {\n int n = secret.size(), a[10] = {0},b[10] = {0},bulls = 0,cows = 0;\n for(int i = 0;i<n;i++)\n if(secret[i] == guess[i]) bulls++;\n else{\n a[secret[i] - \'0\']++;\n b[gue...
3
0
['C', 'Counting']
0
bulls-and-cows
Python beats 100%
python-beats-100-by-kungfupanda30-jeyt
Python solution using Counter\n```from collections import Counter\nclass Solution:\n def getHint(self, secret: str, guess: str) -> str:\n a=0\n
kungfupanda30
NORMAL
2022-01-24T07:44:55.720966+00:00
2022-01-24T07:45:22.866301+00:00
241
false
Python solution using Counter\n```from collections import Counter\nclass Solution:\n def getHint(self, secret: str, guess: str) -> str:\n a=0\n for i,j in zip(secret,guess):\n if (i==j):\n a+=1\n k=Counter(secret)\n l=Counter(guess)\n return "%dA%dB" % (a,...
3
0
['Python']
1
bulls-and-cows
C++|| 0 ms || Easy to Understand
c-0-ms-easy-to-understand-by-tejas03-l2sw
Iterate over the string,\nif secret char == guess char then bull++\notherwise, increase freq of respective char\'s.\nFor cow -\nIterate over the freq and count
Tejas03
NORMAL
2021-07-02T11:29:55.124926+00:00
2021-07-02T11:29:55.124964+00:00
123
false
Iterate over the string,\nif secret char == guess char then bull++\notherwise, increase freq of respective char\'s.\nFor cow -\nIterate over the freq and count of every digit will be min(secret Freq, guess Freq)\n\n```\nclass Solution {\npublic:\nstring getHint(string secret, string guess) {\nint bull = 0;\n// Frequenc...
3
1
['C', 'C++']
1
bulls-and-cows
c++ simple solution
c-simple-solution-by-fangfang_qf-o275
\nclass Solution {\npublic:\n string getHint(string secret, string guess) {\n //count bulls first \n int bulls = 0, cows = 0;\n vector<i
fangfang_qf
NORMAL
2020-12-21T03:10:21.187621+00:00
2020-12-21T03:10:21.187660+00:00
216
false
```\nclass Solution {\npublic:\n string getHint(string secret, string guess) {\n //count bulls first \n int bulls = 0, cows = 0;\n vector<int> sMap(10, 0);\n vector<int> gMap(10, 0);\n \n for (int i = 0; i < guess.size(); i++) {\n if (secret[i] == guess[i]) {\n ...
3
0
['C']
0
bulls-and-cows
Java | Beats 100% | Runtime- 1ms | Use only Array
java-beats-100-runtime-1ms-use-only-arra-nu6l
\nclass Solution {\n public String getHint(String secret, String guess) {\n char [] s = secret.toCharArray();\n char [] g = guess.toCharArray()
abideenzainuel
NORMAL
2020-09-11T01:40:55.347626+00:00
2020-09-11T01:43:12.456655+00:00
246
false
```\nclass Solution {\n public String getHint(String secret, String guess) {\n char [] s = secret.toCharArray();\n char [] g = guess.toCharArray();\n \n int [] count = new int[10];\n int a = 0;\n int b = 0;\n \n StringBuffer sb = new StringBuffer();\n\n ...
3
0
['Java']
0
bulls-and-cows
Python Two Pass - 20ms
python-two-pass-20ms-by-ragav_1302-xzbd
\nclass Solution:\n def getHint(self, secret: str, guess: str) -> str:\n a=0\n b=0\n for i,j in zip(secret,guess):\n if i==j:
ragav_1302
NORMAL
2020-09-10T12:34:05.289060+00:00
2020-09-10T12:34:41.699117+00:00
135
false
```\nclass Solution:\n def getHint(self, secret: str, guess: str) -> str:\n a=0\n b=0\n for i,j in zip(secret,guess):\n if i==j:\n a+=1 \n secret=secret.replace(i,\'*\',1)\n guess=guess.replace(i,\')\',1)\n for j in guess: \n ...
3
0
[]
0
bulls-and-cows
C++ || 99.43% || Simple || Using Vector
c-9943-simple-using-vector-by-priyanshi4-trrw
The solution goes like\n Compare strings to find bulls\n Save the numbers that could be found as cows (i.e. all except the bulls)\n* Compare the guess with the
priyanshi417
NORMAL
2020-09-10T12:23:31.755003+00:00
2020-09-10T12:23:39.852429+00:00
229
false
The solution goes like\n* Compare strings to find bulls\n* Save the numbers that could be found as cows (i.e. all except the bulls)\n* Compare the guess with the possible cows, to get total cows\n\n```\nclass Solution {\npublic:\n string getHint(string secret, string guess) {\n \n string ret;\n ...
3
0
['C']
1
bulls-and-cows
Efficicient C++ Solution | Comments | Faster than 99%
efficicient-c-solution-comments-faster-t-ubf1
\nclass Solution {\npublic:\n int pairs(string str1, string str2, int size){\n // Counting the frequency of numbers in str1 and str2.\n int f1[
ansh_srtv
NORMAL
2020-09-10T11:21:07.323462+00:00
2020-09-11T09:30:56.876909+00:00
438
false
```\nclass Solution {\npublic:\n int pairs(string str1, string str2, int size){\n // Counting the frequency of numbers in str1 and str2.\n int f1[10] = { 0 };\n int f2[10] = { 0 };\n int i, c = 0;\n \n for (i = 0; i < size; i++)\n f1[str1[i] - \'0\']++;\n \n ...
3
0
['C']
1
minimize-the-difference-between-target-and-chosen-elements
[Python] 4 lines solution, explained
python-4-lines-solution-explained-by-dba-kdsp
The idea is that our numbers are very small: mat[i][j] <= 70, and also m, n <= 70. It means, tha final sum of all numbers can be no more than 70**2.\n\nSo, we c
dbabichev
NORMAL
2021-08-22T04:00:44.068219+00:00
2021-08-22T05:21:44.730556+00:00
9,901
false
The idea is that our numbers are very small: `mat[i][j] <= 70`, and also `m, n <= 70`. It means, tha final sum of all numbers can be no more than `70**2`.\n\nSo, we can do almost bruteforce solution: iterate over rows and keep in `nums` all possible sums we get so far.\n\n#### Complexity\nEach time we have in `nums` no...
131
10
[]
39
minimize-the-difference-between-target-and-chosen-elements
DP + Pruning, 4Sum II and All Sums
dp-pruning-4sum-ii-and-all-sums-by-votru-ipl5
Approach 1: DP + Pruning\n\nThe sum of the entire matrix cannot be larger than 70 * 70. We can use this fact for memoisation.\n\nNow, to achieve good runtime (t
votrubac
NORMAL
2021-08-22T04:32:20.195933+00:00
2021-08-22T21:25:01.817461+00:00
12,360
false
#### Approach 1: DP + Pruning\n\nThe sum of the entire matrix cannot be larger than 70 * 70. We can use this fact for memoisation.\n\nNow, to achieve good runtime (the code below is ~80 ms), we need to sort each row and remove duplicates. \n- This way, we can stop after the running sum exceeds the target.\n\n> Update. ...
112
3
[]
20