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
adding-two-negabinary-numbers
Add two numbers, then convert with negative base
add-two-numbers-then-convert-with-negati-t43t
Runtime: 64 ms, faster than 56.20%\nMemory Usage: 14.6 MB, less than 25.62%\n\nclass Solution:\n def addNegabinary(self, arr1, arr2):\n n = (sum(pow(-
evgenysh
NORMAL
2021-06-20T16:19:03.718582+00:00
2021-06-20T16:20:33.862635+00:00
538
false
Runtime: 64 ms, faster than 56.20%\nMemory Usage: 14.6 MB, less than 25.62%\n```\nclass Solution:\n def addNegabinary(self, arr1, arr2):\n n = (sum(pow(-2, i) for i, v in enumerate(arr1[::-1]) if v) +\n sum(pow(-2, i) for i, v in enumerate(arr2[::-1]) if v))\n res = [] if n else [0]\n ...
2
0
['Python', 'Python3']
1
adding-two-negabinary-numbers
[C++] with detailed explanation, easy to understand
c-with-detailed-explanation-easy-to-unde-2gvb
There are four scenarios, a+b=0/1/2/3/4, \nafter summing up the current digit, carry is set to second carry while second carry is set to 0, this is like shiftin
cwpui
NORMAL
2020-11-06T17:39:13.820626+00:00
2020-11-06T17:39:13.820671+00:00
344
false
There are four scenarios, a+b=0/1/2/3/4, \nafter summing up the current digit, carry is set to second carry while second carry is set to 0, this is like shifting the carry\n* 0/1: there is no need to update carry, \n* 2/3: their secondCarry is set to 1 while carry is increased by 1, since 2*(-2)^i = (-2)^(i+1) + (-2)^(...
2
1
[]
0
adding-two-negabinary-numbers
Simple C++ solution
simple-c-solution-by-caspar-chen-hku-z823
\nclass Solution {\npublic:\n vector<int> addNegabinary(vector<int>& arr1, vector<int>& arr2) {\n if (arr1.size() > arr2.size()) swap(arr1,arr2);\n
caspar-chen-hku
NORMAL
2020-05-23T06:38:02.742148+00:00
2020-05-23T06:38:02.742192+00:00
533
false
```\nclass Solution {\npublic:\n vector<int> addNegabinary(vector<int>& arr1, vector<int>& arr2) {\n if (arr1.size() > arr2.size()) swap(arr1,arr2);\n arr2.insert(arr2.begin(), 3, 0);\n for (int i = arr1.size()-1, j = arr2.size()-1; j>=0; i--, j--) {\n if (i>=0) arr2[j]+=arr1[i];\n ...
2
0
[]
0
adding-two-negabinary-numbers
C++ | Similar to Base 2 except carry divided by -2
c-similar-to-base-2-except-carry-divided-rdvm
\nclass Solution {\npublic:\n vector<int> addNegabinary(vector<int>& arr1, vector<int>& arr2) {\n \n int n = arr1.size();\n int m = arr2
wh0ami
NORMAL
2020-05-22T19:04:45.603052+00:00
2020-05-22T19:04:45.603103+00:00
410
false
```\nclass Solution {\npublic:\n vector<int> addNegabinary(vector<int>& arr1, vector<int>& arr2) {\n \n int n = arr1.size();\n int m = arr2.size();\n \n int i = n-1, j = m-1, carry = 0;\n vector<int>res;\n int c = 0;\n \n while (i >= 0 || j >= 0 || carry...
2
0
[]
0
adding-two-negabinary-numbers
Java solution O(n) & 1ms
java-solution-on-1ms-by-colinwei-b1nb
\nclass Solution {\n public int[] addNegabinary(int[] arr1, int[] arr2) {\n int len1 = arr1.length;\n int len2 = arr2.length;\n\n if (le
colinwei
NORMAL
2020-03-01T09:47:51.927223+00:00
2020-03-01T09:52:49.134757+00:00
322
false
```\nclass Solution {\n public int[] addNegabinary(int[] arr1, int[] arr2) {\n int len1 = arr1.length;\n int len2 = arr2.length;\n\n if (len1 == 0) {\n return arr2;\n }\n if (len2 == 0) {\n return arr1;\n }\n int maxLen = (len1 > len2 ? len1 : le...
2
1
[]
0
adding-two-negabinary-numbers
[Python] I HATE BIT OPERATION
python-i-hate-bit-operation-by-zeyuuuuuu-9mb9
\nclass Solution:\n\t# Time Omax(m,n)\n\t# Space O1\n def addBinary(self,arr1,arr2):\n carry = 0\n ans = []\n \n while arr1 or ar
zeyuuuuuuu
NORMAL
2019-07-03T05:57:43.057484+00:00
2019-07-03T08:28:16.831205+00:00
174
false
```\nclass Solution:\n\t# Time Omax(m,n)\n\t# Space O1\n def addBinary(self,arr1,arr2):\n carry = 0\n ans = []\n \n while arr1 or arr2 or carry:\n carry += (arr1 or [0]).pop() + (arr2 or [0]).pop()\n ans.append(carry & 1)\n carry = carry >> 1\n retu...
2
1
[]
2
adding-two-negabinary-numbers
C++ O(N) Time with Explanation (carry = -(sum >> 1))
c-on-time-with-explanation-carry-sum-1-b-2sbq
See more code in my repo LeetCode\n\nWhen adding two numbers in base 2 I use a variable carry to store the carryover.\n\nAssume we are adding two bits a, b and
lzl124631x
NORMAL
2019-06-02T04:55:18.224053+00:00
2019-06-02T06:08:25.360919+00:00
420
false
*See more code in my repo [LeetCode](https://github.com/lzl124631x/LeetCode)*\n\nWhen adding two numbers in base `2` I use a variable `carry` to store the carryover.\n\nAssume we are adding two bits `a`, `b` and `carry`. The `sum` can be `0, 1, 2, 3`, and the leftover bit value is `sum % 2` and the new value of `carry`...
2
0
[]
1
adding-two-negabinary-numbers
Ordinary add and carry works just fine!
ordinary-add-and-carry-works-just-fine-b-ahc0
Ordinary add and carry works just fine! You just need to realize that carry could be some number other than zero or one and that you only have to subtract the r
sladkey
NORMAL
2019-06-02T04:18:13.369019+00:00
2019-06-02T04:22:09.789451+00:00
423
false
Ordinary add and carry works just fine! You just need to realize that carry could be some number other than zero or one and that you only have to subtract the right signed bit if it\'s not even before dividing by 2.\n\n```csharp\npublic class Solution {\n public int[] AddNegabinary(int[] arr1, int[] arr2) {\n ...
2
1
[]
0
adding-two-negabinary-numbers
Just observation
just-observation-by-sohailalamx-643o
IntuitionApproachComplexity Time complexity: O(n); Space complexity: O(1) Code
sohailalamx
NORMAL
2025-02-08T19:10:47.551388+00:00
2025-02-08T19:10:47.551388+00:00
41
false
# Intuition observation <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: O(n); <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: O(1) <!-- Add your space complexity here,...
1
0
['C++']
0
adding-two-negabinary-numbers
Bit Operation with little trick - Beat 100%
bit-operation-with-little-trick-beat-100-74zz
Intuition\n Describe your first thoughts on how to solve this problem. \nthe list of binary will be different with usual binary, the negabinary representation w
muzakkiy
NORMAL
2024-01-31T07:53:32.142248+00:00
2024-01-31T07:53:32.142277+00:00
316
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nthe list of binary will be different with usual binary, the negabinary representation will be like this:\n[...,64,-32,16,-8,4,-2,1]\n\nif there is 1 + 1 (base 10), the result will be 2. on negabinary will be [1,1,0] = 4 + (-2) + 0 = 2\nso...
1
0
['Go']
1
adding-two-negabinary-numbers
Clean Python | High Speed | O(n) time, O(1) space | Beats 98.9%
clean-python-high-speed-on-time-o1-space-q5nh
Code\n\nclass Solution:\n def addBinary(self, A, B):\n res = []\n carry = 0\n while A or B or carry:\n carry += (A or [0]).po
avs-abhishek123
NORMAL
2023-01-26T10:02:35.976903+00:00
2023-01-26T10:02:35.976955+00:00
389
false
# Code\n```\nclass Solution:\n def addBinary(self, A, B):\n res = []\n carry = 0\n while A or B or carry:\n carry += (A or [0]).pop() + (B or [0]).pop()\n res.append(carry & 1)\n carry = carry >> 1\n return res[::-1]\n\n def addNegabinary(self, A, B):\n...
1
0
['Python3']
1
adding-two-negabinary-numbers
Java Solution easy to understand.
java-solution-easy-to-understand-by-hsds-9j2n
At first, \n0+0=1, 1+0=1, 1+1=110.\nSo you have to calculate with carry over 11.\n11+0+0=11, 11+0+1=0, 11+1+1=1.\nThen you have to to calculate with carry over
hsdsh
NORMAL
2022-11-13T11:59:54.635173+00:00
2022-11-13T11:59:54.635218+00:00
182
false
At first, \n0+0=1, 1+0=1, 1+1=110.\nSo you have to calculate with carry over 11.\n11+0+0=11, 11+0+1=0, 11+1+1=1.\nThen you have to to calculate with carry over 1.\n1+0+0=1, 1+0+1=110, 1+1+1 = 111.\nThat\'s all you have to calculate and these are implemented in add.\n```\nclass Solution {\n public void add(int[] r, ...
1
0
['Java']
0
adding-two-negabinary-numbers
🔥 Simple Javascript Solution - Easy to Understand
simple-javascript-solution-easy-to-under-liod
\nfunction addNegabinary(a, b) {\n // reverse first\n a = a.reverse(), b = b.reverse();\n\n // set c as third array, get max as number of loops\n le
joenix
NORMAL
2022-05-25T11:27:15.891085+00:00
2022-05-25T11:27:15.891121+00:00
178
false
```\nfunction addNegabinary(a, b) {\n // reverse first\n a = a.reverse(), b = b.reverse();\n\n // set c as third array, get max as number of loops\n let c = dp(Math.max(a.length, b.length));\n\n // remove 0\n while (c.length > 1 && c[0] == 0) {\n c.shift();\n }\n\n // result\n return c...
1
0
['JavaScript']
0
adding-two-negabinary-numbers
C++ Solution O(N)
c-solution-on-by-ahsan83-zw14
Runtime: 4 ms, faster than 96.48% of C++ online submissions for Adding Two Negabinary Numbers.\nMemory Usage: 19.4 MB, less than 87.32% of C++ online submission
ahsan83
NORMAL
2022-05-14T04:53:37.305122+00:00
2022-05-14T04:53:37.305162+00:00
315
false
Runtime: 4 ms, faster than 96.48% of C++ online submissions for Adding Two Negabinary Numbers.\nMemory Usage: 19.4 MB, less than 87.32% of C++ online submissions for Adding Two Negabinary Numbers.\n\n\n```\nWe can add 2 negabinary number same way we add 2 binary number.\n\nIn case of Base 2 binary number addition we ge...
1
0
['Math', 'C']
0
adding-two-negabinary-numbers
Python 100% fastest with comments
python-100-fastest-with-comments-by-blak-hmvx
\nclass Solution(object):\n def addNegabinary(self, arr1, arr2):\n """\n :type arr1: List[int]\n :type arr2: List[int]\n :rtype:
blakejmas
NORMAL
2022-04-14T16:43:25.189814+00:00
2022-04-14T16:43:25.189856+00:00
237
false
```\nclass Solution(object):\n def addNegabinary(self, arr1, arr2):\n """\n :type arr1: List[int]\n :type arr2: List[int]\n :rtype: List[int]\n """\n # get lengths\n m, n = len(arr1), len(arr2)\n \n # carry for positive and negative places\n c_pos...
1
0
[]
0
adding-two-negabinary-numbers
Java, Easy solution
java-easy-solution-by-tanujatammireddy21-eq3i
```\nclass Solution {\n public int[] addNegabinary(int[] arr1, int[] arr2) {\n \n List result = new ArrayList();\n int pointer_1 = arr1.
tanujatammireddy21
NORMAL
2022-04-03T01:53:55.955941+00:00
2022-04-03T01:53:55.955991+00:00
384
false
```\nclass Solution {\n public int[] addNegabinary(int[] arr1, int[] arr2) {\n \n List<Integer> result = new ArrayList();\n int pointer_1 = arr1.length-1;\n int pointer_2 = arr2.length-1;\n\n int carry = 0;\n int current = 0;\n int sum = 0;\n \n while(po...
1
0
['Java']
0
adding-two-negabinary-numbers
Java Clean Code
java-clean-code-by-shiweiwong-cvlz
\nclass Solution {\n public int[] addNegabinary(int[] arr1, int[] arr2) {\n LinkedList<Integer> res = new LinkedList<>();\n int i = 1, carry =
shiweiwong
NORMAL
2022-03-08T10:37:34.284004+00:00
2022-03-08T10:37:34.284045+00:00
313
false
```\nclass Solution {\n public int[] addNegabinary(int[] arr1, int[] arr2) {\n LinkedList<Integer> res = new LinkedList<>();\n int i = 1, carry = 0;\n while( i <= arr1.length || i <= arr2.length || carry != 0){\n int a = arr1.length - i > -1 ? arr1[arr1.length - i] : 0;\n i...
1
0
['Java']
0
adding-two-negabinary-numbers
[Python] iterative
python-iterative-by-artod-5boy
Here I just sum corresponding bits from the input arrays starting from the right and carry the leftover to the next bit using the rule from lookup dictionary. A
artod
NORMAL
2021-11-15T04:33:49.279519+00:00
2021-11-15T04:33:49.279567+00:00
388
false
Here I just sum corresponding bits from the input arrays starting from the right and carry the leftover to the next bit using the rule from `lookup` dictionary. At the end do not forrget remove leading zeros from the answer.\n\nTime: **O(n)** for iteration\nSpace: **O(1)** if the resulting array is not taken into accou...
1
0
[]
0
adding-two-negabinary-numbers
Python solution (base negative-two conversion)
python-solution-base-negative-two-conver-fp9m
The tricky part might be how to convert a number to base negative-two representation.\n\nclass Solution:\n def addNegabinary(self, arr1, arr2):\n n =
jinghuayao
NORMAL
2021-10-27T21:02:06.115301+00:00
2021-10-27T21:02:06.115360+00:00
501
false
The tricky part might be how to convert a number to base negative-two representation.\n```\nclass Solution:\n def addNegabinary(self, arr1, arr2):\n n = (sum(pow(-2, i) for i, v in enumerate(arr1[::-1]) if v) +\n sum(pow(-2, i) for i, v in enumerate(arr2[::-1]) if v))\n res = self.get_base_...
1
0
[]
0
adding-two-negabinary-numbers
C++, 100 %, Standard negative base addition rules from Wikipedia
c-100-standard-negative-base-addition-ru-7n7x
\n\nclass Solution {\npublic:\n #define pii pair<int,int>\n vector<int> addNegabinary(vector<int>& arr1, vector<int>& arr2) {\n unordered_map<int,
aditya_trips
NORMAL
2021-06-27T06:25:15.799383+00:00
2021-06-27T06:25:15.799414+00:00
640
false
\n```\nclass Solution {\npublic:\n #define pii pair<int,int>\n vector<int> addNegabinary(vector<int>& arr1, vector<int>& arr2) {\n unordered_map<int, pii> mp ;\n mp[-2] = {0,1}, mp[-1] = {1,1}, mp[0] = {0,0}, mp[1] = {1,0}, mp[2] = {0,-1}, mp[3] = {1,-1}; \n vector<int> res ; \n int n ...
1
1
['C']
0
adding-two-negabinary-numbers
Java O(N)
java-on-by-brucezu-pxsl
\n /*\n Idea:\n "Given two numbers arr1 and arr2 in base -2."\n So:\n - for any column it s possible to have -1,0,1.\n - For 2 neighbor columns:\n
brucezu
NORMAL
2021-03-20T05:01:28.586741+00:00
2021-03-20T05:01:28.586785+00:00
258
false
```\n /*\n Idea:\n "Given two numbers arr1 and arr2 in base -2."\n So:\n - for any column it s possible to have -1,0,1.\n - For 2 neighbor columns:\n left:-2^i | right:2^{i-1}:\n -------------------------\n x y\n 1 1\n 0 0\n -1 -1\n ...
1
0
[]
0
adding-two-negabinary-numbers
[Python] Easy to understand solution
python-easy-to-understand-solution-by-tg-77o9
\tarr1[i] + arr2[i] + carry[i] == -1\n\t\t\t\t-> ans.append(1)\n\t\t\t\t-> carry[i+1] = 1\n \tarr1[i] + arr2[i] + carry[i] == 0\n\t\t\t\t-> ans.append(0)\n\t\t\
tgh20
NORMAL
2021-02-20T01:50:51.803894+00:00
2021-02-20T01:50:51.803927+00:00
299
false
* \tarr1[i] + arr2[i] + carry[i] == -1\n\t\t\t\t-> ans.append(1)\n\t\t\t\t-> carry[i+1] = 1\n* \tarr1[i] + arr2[i] + carry[i] == 0\n\t\t\t\t-> ans.append(0)\n\t\t\t\t-> carry[i+1] = 0\n* \tarr1[i] + arr2[i] + carry[i] == 1\n\t\t\t\t-> ans.append(1)\n\t\t\t\t-> carry[i+1] = 0\n* \tarr1[i] + arr2[i] + carry[i] == 2\n\t\t...
1
0
[]
0
adding-two-negabinary-numbers
C++ solution using 2 carry
c-solution-using-2-carry-by-belaid-ektb
\nMy solution using two carry: \n\n\n2* (-2)^i = (-2)^(i+1) + (-2)^(i+2); // current = 0, carry1 = 1 and carry2 = 1\n3* (-2)^i = (-2)^i + (-2)^(i+1) + (-2)^(i+2
belaid
NORMAL
2020-10-16T13:39:12.136176+00:00
2020-10-16T13:39:12.136210+00:00
236
false
\nMy solution using two carry: \n\n```\n2* (-2)^i = (-2)^(i+1) + (-2)^(i+2); // current = 0, carry1 = 1 and carry2 = 1\n3* (-2)^i = (-2)^i + (-2)^(i+1) + (-2)^(i+2) // current = 1, carry1 = 1 and carry2 = 1\n4* (-2)^i = (-2)^(i+2); // current = 0, carry1 = 0 and carry2 = 1\n```\n```\nvector<int> addNegabinary(vector<in...
1
0
[]
0
adding-two-negabinary-numbers
simple java 100%
simple-java-100-by-jjyz-rn0l
\nthe only thing we need to know is that the carry populates to two digits to the left\n [1]\n+ [1]\n--------\n[1,1,0]\n\n\n```\nclass Solution {\n publ
JJYZ
NORMAL
2020-08-18T03:03:16.473023+00:00
2020-08-18T03:32:03.791632+00:00
212
false
```\nthe only thing we need to know is that the carry populates to two digits to the left\n [1]\n+ [1]\n--------\n[1,1,0]\n```\n\n```\nclass Solution {\n public int[] addNegabinary(int[] arr1, int[] arr2) {\n int carry = 0;\n int l1 = arr1.length-1;\n int l2 = arr2.length-1;\n int[] ...
1
1
[]
0
adding-two-negabinary-numbers
C ++ From Wikipedia & Some explaination
c-from-wikipedia-some-explaination-by-ma-4gba
The base algorithm is derived from wikipedia, basically, the majority of bit sum is the same. The main difference is to understand that the sum at each bit loca
marzio
NORMAL
2020-06-12T04:03:56.944545+00:00
2020-06-12T04:08:15.294984+00:00
349
false
The base algorithm is derived from wikipedia, basically, the majority of bit sum is the same. The main difference is to understand that the sum at each bit location, will be decompose to carry, and the bit at current location. So from the wikipedia chart, for example, when bit sum equals to 2, it should be decomposed ...
1
0
[]
0
adding-two-negabinary-numbers
javascript O(n) solution
javascript-on-solution-by-tajinder89-ggtm
\n/**\n * @param {number[]} arr1\n * @param {number[]} arr2\n * @return {number[]}\n */\nvar addNegabinary = function(arr1, arr2) {\n // making array size e
tajinder89
NORMAL
2020-02-09T14:39:16.770808+00:00
2020-02-09T14:40:43.032242+00:00
176
false
```\n/**\n * @param {number[]} arr1\n * @param {number[]} arr2\n * @return {number[]}\n */\nvar addNegabinary = function(arr1, arr2) {\n // making array size equal\n if(arr1.length > arr2.length) {\n arr2 = new Array(arr1.length - arr2.length).fill(0).concat(arr2);\n }\n else {\n ar...
1
0
[]
0
adding-two-negabinary-numbers
Simple Python Solution With Comment
simple-python-solution-with-comment-by-5-s3z1
\nclass Solution:\n def addNegabinary(self, arr1: [int], arr2: [int]) -> [int]:\n result_len = max(len(arr1), len(arr2)) + 2\n\t\t# reverse both array
599hypan
NORMAL
2019-10-06T20:42:37.003948+00:00
2019-10-06T20:42:37.003990+00:00
366
false
```\nclass Solution:\n def addNegabinary(self, arr1: [int], arr2: [int]) -> [int]:\n result_len = max(len(arr1), len(arr2)) + 2\n\t\t# reverse both array\n arr1 = arr1[::-1] + [0] * (result_len - len(arr1))\n arr2 = arr2[::-1] + [0] * (result_len - len(arr2))\n\t\t# simply sum, then deal with 2s...
1
0
['Python']
0
adding-two-negabinary-numbers
My python solution (Vertical Addition with Explanation)
my-python-solution-vertical-addition-wit-or0s
Let say we have two number d1 d2 d3 ... dm, and q1 q2 q3... qm (if the two number have different number of digits, we can always left pad the shorter one with a
dragonrider
NORMAL
2019-06-08T09:50:21.703674+00:00
2019-06-08T09:56:11.152608+00:00
354
false
Let say we have two number d<sub>1</sub> d<sub>2</sub> d<sub>3</sub> ... d<sub>m</sub>, and q<sub>1</sub> q<sub>2</sub> q<sub>3</sub>... q<sub>m</sub> (if the two number have different number of digits, we can always left pad the shorter one with all zeros)\n\nFor k<sup>th</sup> digit d<sub>k</sub> and q<sub>k</sub> th...
1
0
[]
0
adding-two-negabinary-numbers
Standard addition of lists with tricky carry
standard-addition-of-lists-with-tricky-c-mmh7
Here we use the same technique as for adding two lists with carry\nbut the tricky part is the calculation of the carry.\nIf the sum is positive then just take t
todor91
NORMAL
2019-06-07T10:28:45.007599+00:00
2019-06-07T10:28:45.007657+00:00
176
false
Here we use the same technique as for adding two lists with carry\nbut the tricky part is the calculation of the carry.\nIf the sum is positive then just take the remainer as carry and multiply it to -1.\nIf the sum is -1 then the carry becomes 1.\n```\n vector<int> addNegabinary(vector<int>& arr1, vector<int>& arr2...
1
0
[]
1
adding-two-negabinary-numbers
simple python solution beats 100%
simple-python-solution-beats-100-by-mrde-63hl
\n def addNegabinary(self, arr1, arr2):\n """\n :type arr1: List[int]\n :type arr2: List[int]\n :rtype: List[int]\n """\n
mrdelhi
NORMAL
2019-06-02T15:46:41.301141+00:00
2019-06-02T15:46:41.301175+00:00
91
false
```\n def addNegabinary(self, arr1, arr2):\n """\n :type arr1: List[int]\n :type arr2: List[int]\n :rtype: List[int]\n """\n def num2dec(arr):\n n = 0\n for i, num in enumerate(arr[::-1]):\n n+= ((-2)**i)*num\n return n\n ...
1
0
[]
0
adding-two-negabinary-numbers
Java Add (allow overflow) then adjust
java-add-allow-overflow-then-adjust-by-b-3kv0
Add directly, each digit will be between 0-2\n2. Adjust if overflow, for digit[i] if it\'s >=2\na) if digit[i-1]>=1, digit[i-1]--;\nb) else digit[i - 1]++; digi
bluesky999
NORMAL
2019-06-02T05:48:41.349974+00:00
2019-06-02T05:48:41.350021+00:00
123
false
1. Add directly, each digit will be between 0-2\n2. Adjust if overflow, for digit[i] if it\'s >=2\na) if digit[i-1]>=1, digit[i-1]--;\nb) else digit[i - 1]++; digit[i - 2]++;\n\n```\n\tpublic int[] addNegabinary(int[] arr1, int[] arr2) {\n\t\tint[] ret = new int[1020];\n\t\tfor (int i = 0; i < ret.length; i++) {\n\t\t\...
1
1
[]
0
adding-two-negabinary-numbers
Adjust or Carry method ( C++, with explanation )
adjust-or-carry-method-c-with-explanatio-a87g
Intitution:\nLet\'s just add elements of both numbers in any array to get sum of arr1 and arr2 ( I took result ).\n\nIf an elem of result vector is greater than
amitnsky
NORMAL
2019-06-02T05:33:28.212173+00:00
2019-06-03T12:06:57.970971+00:00
244
false
# Intitution:\nLet\'s just add elements of both numbers in any array to get sum of arr1 and arr2 ( I took result ).\n\nIf an elem of result vector is greater than 2, it can be balanced in two ways:\n(assuming here that leftmost place is highest bit and rightmost place is lowest bit)\n1. By cancelling values of next pla...
1
1
[]
1
adding-two-negabinary-numbers
Simple python solution
simple-python-solution-by-merciless-e1mm
```\nclass Solution:\n def addNegabinary(self, arr1: List[int], arr2: List[int]) -> List[int]:\n\t\t#convert Negabinary Numbers to int\n def helper(ar
merciless
NORMAL
2019-06-02T05:11:09.784892+00:00
2019-06-02T06:47:02.892699+00:00
160
false
```\nclass Solution:\n def addNegabinary(self, arr1: List[int], arr2: List[int]) -> List[int]:\n\t\t#convert Negabinary Numbers to int\n def helper(arr):\n ans = j = 0\n for i in arr[::-1]:\n ans += i * (-2) ** j\n j += 1\n return ans\n \n\...
1
1
[]
0
adding-two-negabinary-numbers
Java O(n), straight forward,
java-on-straight-forward-by-ansonluo-rtja
\nclass Solution {\n public int[] addNegabinary(int[] arr1, int[] arr2) {\n int length1 = arr1.length;\n int length2 = arr2.length;\n in
ansonluo
NORMAL
2019-06-02T04:27:11.865151+00:00
2019-06-02T04:27:11.865196+00:00
267
false
```\nclass Solution {\n public int[] addNegabinary(int[] arr1, int[] arr2) {\n int length1 = arr1.length;\n int length2 = arr2.length;\n int length = Math.max(length1, length2);\n int[] result = new int[length + 2]; // the result \n for (int i = 0; i < length; i++) {\n ...
1
1
[]
0
adding-two-negabinary-numbers
Python Easy Understand - Convert 2 times
python-easy-understand-convert-2-times-b-gwy6
\nclass Solution:\n def addNegabinary(self, arr1, arr2):\n num1 = self.convert_to_int(arr1)\n num2 = self.convert_to_int(arr2)\n num = s
zt586
NORMAL
2019-06-02T04:15:23.882336+00:00
2019-06-02T04:15:23.882380+00:00
168
false
```\nclass Solution:\n def addNegabinary(self, arr1, arr2):\n num1 = self.convert_to_int(arr1)\n num2 = self.convert_to_int(arr2)\n num = self.convert_to_neg(num1+num2)\n return [int(d) for d in str(num)]\n \n def convert_to_int(self, arr):\n ans = i = 0\n for j in ran...
1
0
[]
0
adding-two-negabinary-numbers
PHP Solution
php-solution-by-neilchavez-dqv5
IntuitionApproachComplexity Time complexity: Space complexity: Code
Neilchavez
NORMAL
2025-03-04T00:21:26.427096+00:00
2025-03-04T00:21:26.427096+00:00
2
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 `...
0
0
['PHP']
0
adding-two-negabinary-numbers
great
great-by-ivan_1999-v92t
IntuitionApproachComplexity Time complexity: Space complexity: Code
ivan_1999
NORMAL
2025-02-18T12:01:08.396303+00:00
2025-02-18T12:01:08.396303+00:00
2
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 `...
0
0
['Go']
0
adding-two-negabinary-numbers
Easy solution
easy-solution-by-koushik_55_koushik-46ng
IntuitionApproachComplexity Time complexity: Space complexity: Code
Koushik_55_Koushik
NORMAL
2025-02-04T14:24:28.258502+00:00
2025-02-04T14:24:28.258502+00:00
17
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 `...
0
0
['Python3']
0
adding-two-negabinary-numbers
easiest solution in c++
easiest-solution-in-c-by-prateek_verma14-fkdt
IntuitionAs length of array are too big so we cannot convert it to decimal , so we need to think direct additionApproachComplexityO(n) Time complexity: O(n) Sp
prateek_verma145
NORMAL
2025-01-14T06:35:34.567678+00:00
2025-01-14T06:35:34.567678+00:00
14
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> As length of array are too big so we cannot convert it to decimal , so we need to think direct addition # Approach <!-- Describe your approach to solving the problem. --> # Complexity$$O(n)$$ - Time complexity: $$O(n)$$ <!-- Add your time...
0
0
['Array', 'Math', 'C++']
0
adding-two-negabinary-numbers
Simple(Optimized) Java Solution
simpleoptimized-java-solution-by-angaria-0aac
Code
angaria_vansh
NORMAL
2025-01-11T17:34:51.887514+00:00
2025-01-11T17:34:51.887514+00:00
7
false
# Code ```java [] class Solution { public int[] addNegabinary(int[] arr1, int[] arr2) { int i1 = arr1.length - 1, i2 = arr2.length - 1, carry = 0; List<Integer> resultList = new ArrayList<Integer>(); // 1. calculate sum of arr1 and arr2 while (i1 >= 0 || i2 >= 0 || carry != 0) { int n1 = i1...
0
0
['Java']
0
adding-two-negabinary-numbers
1073. Adding Two Negabinary Numbers
1073-adding-two-negabinary-numbers-by-g8-i3lw
IntuitionApproachComplexity Time complexity: Space complexity: Code
G8xd0QPqTy
NORMAL
2025-01-11T16:39:26.711264+00:00
2025-01-11T16:39:26.711264+00:00
13
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 `...
0
0
['Python3']
0
adding-two-negabinary-numbers
My solution
my-solution-by-huyle010504-zjy8
IntuitionWe simply add the numbers in the same pattern as binary, but now, instead of multiplying by 1, we multiply by -2. To add two negabinary numbers, you ca
huyle010504
NORMAL
2025-01-03T22:45:30.254265+00:00
2025-01-03T22:45:30.254265+00:00
7
false
# Intuition We simply add the numbers in the same pattern as binary, but now, instead of multiplying by 1, we multiply by -2. To add two negabinary numbers, you can use the following formula: at each digit position (from least significant bit/rightmost bit), sum the corresponding bits from both numbers along with the c...
0
0
['Array', 'Math', 'C++']
0
adding-two-negabinary-numbers
Just like regular binary addition, except carry can be -1
just-like-regular-binary-addition-except-b4xk
Intuition Just like regular binary addition, except carry can be -1 or 1. Add current two digits, and carry c, the sum can be 0,1,2,3,-1 if 0,2, the resulting d
lambdacode-dev
NORMAL
2024-12-24T20:11:01.686397+00:00
2024-12-24T20:11:01.686397+00:00
8
false
# Intuition - Just like regular binary addition, except carry can be -1 or 1. - Add current two digits, and carry `c`, the sum can be `0,1,2,3,-1` - if `0,2`, the resulting digit will be `0`, and `1` if `1, 3`. - next carry `c` will be `-1` if `2,3`. - if the sum is `-1`, convert it to `-1 = -2 + 1`, so current sum di...
0
0
['C++']
0
adding-two-negabinary-numbers
Time: Beats %100, Memory: Beats 82.76%
time-beats-100-memory-beats-8276-by-sobe-5tm0
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
sobeitfk
NORMAL
2024-11-21T00:00:12.184656+00:00
2024-11-21T00:00:12.184694+00:00
4
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)$$ --...
0
0
['Java']
0
adding-two-negabinary-numbers
scala solution
scala-solution-by-vititov-bwuv
https://en.wikipedia.org/wiki/Negative_base#Addition\nscala []\nobject Solution {\n val nMap = Map(\n -2 -> (0,1), -1 -> (1,1), 0 -> (0,0),\n 1 -> (1,0),
vititov
NORMAL
2024-11-02T18:52:17.405157+00:00
2024-11-02T18:52:17.405186+00:00
0
false
https://en.wikipedia.org/wiki/Negative_base#Addition\n```scala []\nobject Solution {\n val nMap = Map(\n -2 -> (0,1), -1 -> (1,1), 0 -> (0,0),\n 1 -> (1,0), 2 -> (0,-1), 3 -> (1,-1)\n )\n def addNegabinary(arr1: Array[Int], arr2: Array[Int]): Array[Int] = {\n def f(seq:Seq[(Int,Int)], c: Int = 0, \n ...
0
0
['Scala']
0
adding-two-negabinary-numbers
Beats 99% Cases Python
beats-99-cases-python-by-elenazzhao-iryt
Intuition\nWe can break down the numbers mathematically and see what happens to each digit at each stage. For example, adding [1] and [1] is performing \n\n$(-2
elenazzhao
NORMAL
2024-10-20T16:24:00.497421+00:00
2024-10-20T16:24:00.497465+00:00
24
false
# Intuition\nWe can break down the numbers mathematically and see what happens to each digit at each stage. For example, adding [1] and [1] is performing \n\n$(-2)^0 + (-2)^0 = (2)(-2)^0 = (-2)^1 + (4-2)(-2)^0 = (-2)^2 + (-2)^1$\n\nwhich encoded in negabinary as [1, 1, 0].\n\nWe apply this arithmetic knowledge to all ...
0
0
['Python3']
0
adding-two-negabinary-numbers
0ms Runtime - Beats 100% in terms of Runtime
0ms-runtime-beats-100-in-terms-of-runtim-yw5n
Intuition\nWe observe that 1+1 in this context is not 10 but 110 (4-2+0=2) as the base is -2. So we can do it if we maintain two carries for each bit addition.\
guptakushagra343
NORMAL
2024-10-11T07:13:26.357710+00:00
2024-10-11T07:13:26.357743+00:00
3
false
# Intuition\nWe observe that 1+1 in this context is not 10 but 110 (4-2+0=2) as the base is -2. So we can do it if we maintain two carries for each bit addition.\n\n# Approach\nWe start with initialising the two carries c1, c3 to 0. (c2 stores the value of c3 for the next iteration). Then we do bit addition updating th...
0
0
['C++']
0
adding-two-negabinary-numbers
Python. Time: O(n), Space: O(1)
python-time-on-space-o1-by-iitjsagar-s38h
Approach\n Describe your approach to solving the problem. \nFor any index/bit in two arrays, following scenarios apply:\n1. Sum of their coefficients [0,1], the
iitjsagar
NORMAL
2024-08-28T06:12:59.725878+00:00
2024-08-28T06:12:59.725914+00:00
2
false
# Approach\n<!-- Describe your approach to solving the problem. -->\nFor any index/bit in two arrays, following scenarios apply:\n1. Sum of their coefficients [0,1], then leave it as is in result.\n2. Sum of their coefficients is > 1. In this situation, next higher bit can have coefficient contribution of -(current coe...
0
0
['Python']
0
adding-two-negabinary-numbers
Not a clear solution C#
not-a-clear-solution-c-by-bogdanonline44-hfep
\n# Complexity\n- Time complexity: O(max(n, m))\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(max(n, m)\n Add your space complexity here,
bogdanonline444
NORMAL
2024-07-05T11:24:58.195275+00:00
2024-07-05T11:24:58.195297+00:00
3
false
\n# Complexity\n- Time complexity: O(max(n, m))\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(max(n, m)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\npublic class Solution {\n public int[] AddNegabinary(int[] arr1, int[] arr2) {\n List<int> result = ...
0
0
['Array', 'Math', 'C#']
0
adding-two-negabinary-numbers
Beats 100%, negabinary to decimal then decimal to negabinary
beats-100-negabinary-to-decimal-then-dec-ewus
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
vsrfiles
NORMAL
2024-06-09T07:06:06.717094+00:00
2024-06-09T07:06:06.717131+00:00
6
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)$$ --...
0
0
['Ruby']
0
adding-two-negabinary-numbers
Scala version
scala-version-by-igstan-w63e
Scala\n\n\nobject Solution {\n def addNegabinary(a: Array[Int], b: Array[Int]): Array[Int] = {\n var large: Array[Int] = a\n var small: Array[Int] = b\n\
igstan
NORMAL
2024-05-09T18:32:16.213681+00:00
2024-05-09T18:32:16.213716+00:00
4
false
# Scala\n\n```\nobject Solution {\n def addNegabinary(a: Array[Int], b: Array[Int]): Array[Int] = {\n var large: Array[Int] = a\n var small: Array[Int] = b\n\n if (a.length < b.length) {\n large = b\n small = a\n }\n\n val result = Array.ofDim[Int](large.length + 2)\n var carry0 = 0\n va...
0
0
['Scala']
0
adding-two-negabinary-numbers
1073. Adding Two Negabinary Numbers.cpp
1073-adding-two-negabinary-numberscpp-by-tkdy
Code\n\nclass Solution {\npublic:\n vector<int> addNegabinary(vector<int>& arr1, vector<int>& arr2) { \n int i = arr1.size()-1;\n int j
202021ganesh
NORMAL
2024-04-30T09:51:56.684574+00:00
2024-04-30T09:51:56.684628+00:00
6
false
**Code**\n```\nclass Solution {\npublic:\n vector<int> addNegabinary(vector<int>& arr1, vector<int>& arr2) { \n int i = arr1.size()-1;\n int j = arr2.size()-1;\n vector<int>bits = {0,1,0,1,0,1};\n vector<int>carries = {1,1,0,0,-1,-1}; \n vector<int>res; \n ...
0
0
['C']
0
adding-two-negabinary-numbers
BEST C++ SOLUTION WITH 7MS OF RUNTIME !
best-c-solution-with-7ms-of-runtime-by-r-mjsj
\n# Code\n\nclass Solution {\n public:\n vector<int> addNegabinary(vector<int>& arr1, vector<int>& arr2) {\n deque<int> ans;\n int carry = 0;\n int i
rishabnotfound
NORMAL
2024-04-28T09:11:21.099676+00:00
2024-04-28T09:11:21.099706+00:00
60
false
\n# Code\n```\nclass Solution {\n public:\n vector<int> addNegabinary(vector<int>& arr1, vector<int>& arr2) {\n deque<int> ans;\n int carry = 0;\n int i = arr1.size() - 1;\n int j = arr2.size() - 1;\n\n while (carry || i >= 0 || j >= 0) {\n if (i >= 0)\n carry += arr1[i--];\n if (j >= 0...
0
0
['C++']
0
adding-two-negabinary-numbers
Column Addition
column-addition-by-che011-y43h
Intuition\n Describe your first thoughts on how to solve this problem. \nBased on concept of Column Addition. \n\n# Approach\n Describe your approach to solving
che011
NORMAL
2024-03-30T10:33:23.102084+00:00
2024-03-30T10:33:23.102122+00:00
92
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nBased on concept of Column Addition. \n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nFrom right to left, add along the column. If the added value exceeds 1, add to the next columns. \n\n# Complexity\n- Time comple...
0
0
['Python3']
0
adding-two-negabinary-numbers
Solution for 1073. Adding Two Negabinary Numbers
solution-for-1073-adding-two-negabinary-e7a8a
Intuition\n Describe your first thoughts on how to solve this problem. \nTo me, Key thing is to understand mechanism of base -2 operation. Note to handle the sp
user2988N
NORMAL
2024-03-28T11:14:28.996423+00:00
2024-03-28T11:14:28.996457+00:00
3
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nTo me, Key thing is to understand mechanism of base -2 operation. Note to handle the special cases \n1. -1 carry at the end\n2. handling -1 as sum of digits. \n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nInitial...
0
0
['C++']
0
adding-two-negabinary-numbers
Solution Adding Two Negabinary Numbers
solution-adding-two-negabinary-numbers-b-5y9t
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
Suyono-Sukorame
NORMAL
2024-03-16T02:28:01.777397+00:00
2024-03-16T02:28:01.777422+00:00
5
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)$$ --...
0
0
['PHP']
0
adding-two-negabinary-numbers
Python beats 98%
python-beats-98-by-axxeny-ub6f
Intuition\nSimple long addition. Go through digits from right to left, remember to carry. Take special care with carry, which can be both +1 and -1, and remembe
axxeny
NORMAL
2024-02-25T15:55:45.416562+00:00
2024-02-25T15:55:45.416600+00:00
77
false
# Intuition\nSimple long addition. Go through digits from right to left, remember to carry. Take special care with carry, which can be both +1 and -1, and remember to flip carry sign.\n\n# Complexity\n- Time complexity: $O(n)$\n\n- Space complexity: $O(1)$\n\n# Code\n```\nclass Solution:\n def addNegabinary(self, ar...
0
0
['Python3']
0
adding-two-negabinary-numbers
Python (Simple Maths)
python-simple-maths-by-rnotappl-i5ad
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
rnotappl
NORMAL
2024-02-24T16:23:37.047553+00:00
2024-02-24T16:23:37.047578+00:00
67
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)$$ --...
0
0
['Python3']
0
adding-two-negabinary-numbers
💎Python3 | Beats 93% | Detailed Explanation💎
python3-beats-93-detailed-explanation-by-zj1d
Intuition\nSo in normal binary addition, we have the concept of carrying if we overflow the current slot. However, we need to represent the overflow correctly i
jessicawyn
NORMAL
2024-01-30T05:34:22.295737+00:00
2024-01-30T05:42:47.176556+00:00
63
false
# Intuition\nSo in normal binary addition, we have the concept of carrying if we overflow the current slot. However, we need to represent the overflow correctly in this problem... One key insight: overflow works here is THE OPPOSITE of how it works in normal binary. If we overflow the bit, it means we are actually elim...
0
0
['Python3']
0
adding-two-negabinary-numbers
Beats 97.86% of solution With C++ ||*****JAI PEER DATNA******
beats-9786-of-solution-with-c-jai-peer-d-kwy0
Bold# 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-
Hi_coders786
NORMAL
2024-01-18T06:39:27.620973+00:00
2024-01-18T06:39:27.620999+00:00
66
false
***Bold***# 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. $...
0
0
['Array', 'Math', 'Divide and Conquer', 'Recursion', 'Sorting', 'Counting', 'Shortest Path', 'C++', 'Ruby', 'JavaScript']
0
adding-two-negabinary-numbers
best Approach 100% beat
best-approach-100-beat-by-manish_patil05-bs3m
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
Manish_patil05
NORMAL
2023-12-27T10:15:28.723404+00:00
2023-12-27T10:15:28.723461+00:00
41
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)$$ --...
0
0
['Bit Manipulation', 'Java']
0
adding-two-negabinary-numbers
Unique Approach 100% beat
unique-approach-100-beat-by-vijay_patil-nxc2
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
Vijay_patil
NORMAL
2023-12-27T10:07:53.070735+00:00
2023-12-27T10:07:53.070764+00:00
18
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)$$ --...
0
0
['Bit Manipulation', 'Java']
0
adding-two-negabinary-numbers
Python O(n) space and time solution 2 approaches
python-on-space-and-time-solution-2-appr-t17o
First, I tried to solve the problem a simple way:\n\n1. Convert the negabinary numbers to a decimal\n2. Sum the decimal numbers \n3. Convert the decimal number
GrishaZohrabyan
NORMAL
2023-12-21T12:23:17.579244+00:00
2023-12-21T12:23:17.579267+00:00
27
false
First, I tried to solve the problem a simple way:\n\n1. Convert the negabinary numbers to a decimal\n2. Sum the decimal numbers \n3. Convert the decimal number back to a negabinary number\n\n```\nn1 = self.toDecimal(arr1)\nn2 = self.toDecimal(arr2)\nn = n1 + n2\nres = self.toNegabinary(n)\n```\n\n**The most important p...
0
0
['Python3']
0
adding-two-negabinary-numbers
Adding Two Negabinary Numbers || JAVASCRIPT || Solution by Bharadwaj
adding-two-negabinary-numbers-javascript-gafv
Approach\nSimulating Negabinary Addition\n\n# Complexity\n- Time complexity:\nO(max(n, m))\n\n- Space complexity:\nO(max(n, m))\n\n# Code\n\nvar addNegabinary =
Manu-Bharadwaj-BN
NORMAL
2023-12-21T07:55:49.522898+00:00
2023-12-21T07:55:49.522928+00:00
21
false
# Approach\nSimulating Negabinary Addition\n\n# Complexity\n- Time complexity:\nO(max(n, m))\n\n- Space complexity:\nO(max(n, m))\n\n# Code\n```\nvar addNegabinary = function(arr1, arr2) {\n // Initialize variables for carry, result, and array indices\n let carry = 0;\n let ans = [];\n let x = arr1.length -...
0
0
['JavaScript']
0
adding-two-negabinary-numbers
ee
ee-by-user3043sb-tdp5
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
user3043SB
NORMAL
2023-12-16T13:08:25.272372+00:00
2023-12-16T13:08:25.272394+00:00
11
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)$$ --...
0
0
['Java']
0
adding-two-negabinary-numbers
[JavaScript] 1073. Adding Two Negabinary Numbers
javascript-1073-adding-two-negabinary-nu-5sae
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\nTrial & error to get below:\n-1 => reminder is 1 and carry is 1\n\n# Comp
pgmreddy
NORMAL
2023-12-05T10:56:11.320171+00:00
2023-12-05T10:56:11.320201+00:00
10
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nTrial & error to get below:\n`-1 => reminder is 1 and carry is 1`\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. $...
0
0
['JavaScript']
0
adding-two-negabinary-numbers
Handle sum for different case
handle-sum-for-different-case-by-marcust-wyic
Intuition\n Describe your first thoughts on how to solve this problem. \nThe solution to this problem is to figure out the math behind it, once that is done it
marcustut
NORMAL
2023-11-05T11:37:42.998091+00:00
2023-11-05T11:37:42.998113+00:00
22
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe solution to this problem is to figure out the math behind it, once that is done it is simple to solve.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nIf you think about it, there\'s only a few cases for the bi...
0
0
['C++']
0
adding-two-negabinary-numbers
Best Java Solution || Beats 80%
best-java-solution-beats-80-by-ravikumar-4iqk
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
ravikumar50
NORMAL
2023-09-26T08:35:57.891350+00:00
2023-09-26T08:35:57.891382+00:00
37
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)$$ --...
0
0
['Java']
0
adding-two-negabinary-numbers
Rust Solution
rust-solution-by-rchaser53-kljl
Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(n)\n\n# Code\n\nimpl Solution {\n pub fn add_negabinary(mut arr1: Vec<i32>, mut arr2: Vec<i32>)
rchaser53
NORMAL
2023-09-05T13:45:30.513662+00:00
2023-09-05T13:45:30.513685+00:00
20
false
# Complexity\n- Time complexity:\n$$O(n)$$\n\n- Space complexity:\n$$O(n)$$\n\n# Code\n```\nimpl Solution {\n pub fn add_negabinary(mut arr1: Vec<i32>, mut arr2: Vec<i32>) -> Vec<i32> {\n arr1.reverse();\n arr2.reverse();\n let n = arr1.len();\n let m = arr2.len();\n let mut result = vec![0;n.max(m)+5];...
0
0
['Rust']
0
adding-two-negabinary-numbers
Rule based
rule-based-by-vegetabird-y6z3
Intuition\n Describe your first thoughts on how to solve this problem. \nRule based solution\n\n\n\n\n# Complexity\n- Time complexity: O(n)\n Add your time comp
vegetabird
NORMAL
2023-08-26T10:23:19.087083+00:00
2023-08-26T10:23:19.087103+00:00
44
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nRule based solution\n\n\n\n\n# Complexity\n- Time complexity: $$O(n)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n- Space complexity: $$O(n)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solu...
0
0
['Python3']
0
adding-two-negabinary-numbers
C++ 4ms solution
c-4ms-solution-by-vegabird-6gcw
\n# Code\n\nclass Solution {\npublic:\n vector<int> addNegabinary(vector<int>& arr1, vector<int>& arr2) { \n std::reverse(arr1.begin(), arr1.en
vegabird
NORMAL
2023-08-16T15:13:35.843997+00:00
2023-08-16T15:13:35.844020+00:00
78
false
\n# Code\n```\nclass Solution {\npublic:\n vector<int> addNegabinary(vector<int>& arr1, vector<int>& arr2) { \n std::reverse(arr1.begin(), arr1.end());\n std::reverse(arr2.begin(), arr2.end());\n const int dataSize = std::max(arr1.size(), arr2.size());\n const int ansSize = dataSiz...
0
0
['C++']
0
adding-two-negabinary-numbers
Fast and Easy O(n) Solution
fast-and-easy-on-solution-by-hitesh22ran-92l3
Complexity\n- Time complexity: O(n)\n\n- Space complexity: O(n)\n\n# Code\n\nclass Solution {\npublic:\n pair<int, int> calculateBitAndCarry(int num) {\n
hitesh22rana
NORMAL
2023-08-15T17:54:58.228951+00:00
2023-08-15T17:54:58.228984+00:00
63
false
# Complexity\n- Time complexity: $$O(n)$$\n\n- Space complexity: $$O(n)$$\n\n# Code\n```\nclass Solution {\npublic:\n pair<int, int> calculateBitAndCarry(int num) {\n int bit = 0;\n int carry = 0;\n\n switch(num) {\n case 1:\n bit = 1;\n carry = 0;\n ...
0
0
['Array', 'Math', 'C++']
0
adding-two-negabinary-numbers
C# Solution Run time beat 100%
c-solution-run-time-beat-100-by-jack0001-4w7t
Intuition\nIn such case, we observe\n1 + 1 = 110\n11 + 01 = 00\n\nAlso we can prove that any bits with a carryforward value will never greater than 3(sum <= 3 h
jack0001
NORMAL
2023-07-29T21:06:22.595149+00:00
2023-07-30T17:07:14.911198+00:00
16
false
# Intuition\nIn such case, we observe\n1 + 1 = 110\n11 + 01 = 00\n\nAlso we can prove that any bits with a carryforward value will never greater than 3(sum <= 3 holds true)\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: O(k), k = Max(m, n);\n- k is the maximum...
0
0
['C#']
0
adding-two-negabinary-numbers
My Solutions
my-solutions-by-hope_ma-su4r
Solution I\n\n/**\n * Time Complexity: O(max(n1, n2))\n * Space Complexity: O(1)\n * where `n1` is the length of the vector `arr1`\n * `n2` is the length
hope_ma
NORMAL
2023-07-17T15:38:51.605684+00:00
2023-07-19T00:57:23.848688+00:00
22
false
**Solution I**\n```\n/**\n * Time Complexity: O(max(n1, n2))\n * Space Complexity: O(1)\n * where `n1` is the length of the vector `arr1`\n * `n2` is the length of the vector `arr2`\n */\nclass Solution {\n public:\n vector<int> addNegabinary(const vector<int> &arr1, const vector<int> &arr2) {\n constexpr int...
0
0
[]
0
adding-two-negabinary-numbers
Java solution - 2ms
java-solution-2ms-by-goldrushkl168-3qmz
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
goldrushkl168
NORMAL
2023-07-17T09:56:31.384604+00:00
2023-07-17T09:56:31.384634+00:00
49
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)$$ --...
0
0
['Java']
0
adding-two-negabinary-numbers
[C++] - Beats 100%, While Loop
c-beats-100-while-loop-by-leetcodegrindt-zd0n
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
leetcodegrindtt
NORMAL
2023-07-02T19:53:17.496011+00:00
2023-07-02T19:53:17.496037+00:00
60
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)$$ --...
0
0
['C++']
0
adding-two-negabinary-numbers
[C++] Observation that (1 + 1) == (4 + -2) and (-2 + -2) == (-8 + 4)
c-observation-that-1-1-4-2-and-2-2-8-4-b-d0hb
(1 + 1) == (4 + -2) \n2. (-2 + -2) == (-8 + 4)\n3. 001 + 001 == 110\n4. Add carry for bit + 1 and bit + 2.\n\nJust do a normal bit addition for base 2. But if
pr0d1g4ls0n
NORMAL
2023-06-29T15:48:57.681458+00:00
2023-07-02T05:26:27.596064+00:00
45
false
1. `(1 + 1) == (4 + -2)` \n2. `(-2 + -2) == (-8 + 4)`\n3. `001` + `001` == `110`\n4. Add carry for bit + 1 and bit + 2.\n\nJust do a normal bit addition for base 2. But if there is a carry, carry applies for ith + 1 and ith + 2 position.\n\n```\nclass Solution {\npublic:\n vector<int> addNegabinary(vector<int>& arr...
0
0
['Bit Manipulation']
1
adding-two-negabinary-numbers
Java no stack
java-no-stack-by-yuhui4-nb6i
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \nHandle the carryover by
yuhui4
NORMAL
2023-06-29T13:02:07.873549+00:00
2023-06-29T13:02:07.873573+00:00
97
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nHandle the carryover by positive/negative\n# Complexity\n- Time complexity: O(N)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(N)\n<!...
0
0
['Java']
0
adding-two-negabinary-numbers
Solution
solution-by-deleted_user-mu8f
C++ []\nclass Solution {\npublic:\n vector<int> addNegabinary(vector<int> &arr1, vector<int> &arr2)\n {\n reverse(arr1.begin(), arr1.end());\n
deleted_user
NORMAL
2023-05-29T12:36:07.150184+00:00
2023-05-29T13:33:07.212198+00:00
143
false
```C++ []\nclass Solution {\npublic:\n vector<int> addNegabinary(vector<int> &arr1, vector<int> &arr2)\n {\n reverse(arr1.begin(), arr1.end());\n reverse(arr2.begin(), arr2.end());\n if (arr1.size() < arr2.size())\n swap(arr1, arr2);\n int carry = 0;\n for (int i = 0;...
0
0
['C++', 'Java', 'Python3']
0
adding-two-negabinary-numbers
[LC-1073-M | Python3] A Plain Solution
lc-1073-m-python3-a-plain-solution-by-dr-trb7
It can be treated as a direct follow-up of LC-1017.\n\nPython3 []\nclass Solution:\n def addNegabinary(self, arr1: List[int], arr2: List[int]) -> List[int]:\
drsv
NORMAL
2023-05-18T13:12:35.171024+00:00
2023-05-18T13:12:35.171067+00:00
95
false
It can be treated as a direct follow-up of [LC-1017](https://leetcode.cn/problems/convert-to-base-2/).\n\n```Python3 []\nclass Solution:\n def addNegabinary(self, arr1: List[int], arr2: List[int]) -> List[int]:\n v1 = v2 = 0\n i1 = i2 = 0\n for num1 in arr1[::-1]:\n v1 += num1 * (-2)*...
0
0
['Python3']
0
adding-two-negabinary-numbers
SIMPLE TO UNDERSTAND
simple-to-understand-by-anshumanraj252-uf6j
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
anshumanraj252
NORMAL
2023-04-17T17:43:25.823594+00:00
2023-04-17T17:43:25.823630+00:00
98
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)$$ --...
0
0
['Java']
0
adding-two-negabinary-numbers
python basic math
python-basic-math-by-achildxd-grtb
Intuition\n Describe your first thoughts on how to solve this problem. \nAssumption from basic math\n\n9 = a * (-2) ** x + b * (-2) ** (x-1) + c * (-2) ** (x-2)
achildxd
NORMAL
2023-04-17T06:40:26.249715+00:00
2023-04-17T06:40:26.249738+00:00
112
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nAssumption from basic math\n\n9 = a * (-2) ** x + b * (-2) ** (x-1) + c * (-2) ** (x-2) + ... + 1 \n=> do mod 2 to find last digit => will get 1\n=> new total will be 9 // 2 = 4\n4 = a ** (-2) ** (x-1) + b ** (-2) ** (x-2) + ... + -k => -...
0
0
['Python3']
0
adding-two-negabinary-numbers
2s complement | Commented and Explained | Convert from -2 base then convert back
2s-complement-commented-and-explained-co-tfs1
Intuition\n Describe your first thoughts on how to solve this problem. \nWe want to first know what values we have \nThen, we want to know what we sum up to \nT
laichbr
NORMAL
2023-03-28T20:36:45.436278+00:00
2023-03-28T20:36:45.436322+00:00
134
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWe want to first know what values we have \nThen, we want to know what we sum up to \nThen, we want to convert from where we are to where we want to go \nWe can do this with two functions and a few calls as detailed below. \n\n# Approach\...
0
0
['Python3']
0
sales-analysis-iii
simple MySQL solution
simple-mysql-solution-by-henryz14-vur4
\nSELECT s.product_id, product_name\nFROM Sales s\nLEFT JOIN Product p\nON s.product_id = p.product_id\nGROUP BY s.product_id\nHAVING MIN(sale_date) >= CAST(\'2
henryz14
NORMAL
2019-06-20T15:28:35.145827+00:00
2019-06-23T00:05:35.282009+00:00
30,892
false
```\nSELECT s.product_id, product_name\nFROM Sales s\nLEFT JOIN Product p\nON s.product_id = p.product_id\nGROUP BY s.product_id\nHAVING MIN(sale_date) >= CAST(\'2019-01-01\' AS DATE) AND\n MAX(sale_date) <= CAST(\'2019-03-31\' AS DATE)\n```
158
1
[]
28
sales-analysis-iii
✔️EASIEST solution EVER!
easiest-solution-ever-by-namratanwani-1u0r
\n# Wherever you are given a range, keep MIN() and MAX() in mind\nSELECT Product.product_id, Product.product_name FROM Product \nJOIN Sales \nON Product.product
namratanwani
NORMAL
2022-06-22T23:39:20.863483+00:00
2022-06-24T19:16:00.322769+00:00
24,642
false
```\n# Wherever you are given a range, keep MIN() and MAX() in mind\nSELECT Product.product_id, Product.product_name FROM Product \nJOIN Sales \nON Product.product_id = Sales.product_id \nGROUP BY Sales.product_id \nHAVING MIN(Sales.sale_date) >= "2019-01-01" AND MAX(Sales.sale_date) <= "2019-03-31";\n```
119
0
[]
24
sales-analysis-iii
Beat 95% Simple subquery
beat-95-simple-subquery-by-zzzzhu-nfrx
\nSELECT product_id, product_name \nFROM Product \nWHERE product_id IN\n(SELECT product_id\nFROM Sales\nGROUP BY product_id\nHAVING MIN(sale_date) >= \'2019-01-
zzzzhu
NORMAL
2019-10-05T00:58:11.521965+00:00
2019-10-05T00:58:11.522002+00:00
9,927
false
```\nSELECT product_id, product_name \nFROM Product \nWHERE product_id IN\n(SELECT product_id\nFROM Sales\nGROUP BY product_id\nHAVING MIN(sale_date) >= \'2019-01-01\' AND MAX(sale_date) <= \'2019-03-31\')\n```
63
0
[]
6
sales-analysis-iii
Superb Logic with Min and Max
superb-logic-with-min-and-max-by-ganjina-orsa
\n# Logic min and max\n\nselect product_id,product_name\nfrom product natural join sales\ngroup by product_id\nhaving min(sale_date)>=\'2019-01-01\' and max(sal
GANJINAVEEN
NORMAL
2023-04-23T16:15:01.874026+00:00
2023-04-23T16:15:01.874065+00:00
7,215
false
\n# Logic min and max\n```\nselect product_id,product_name\nfrom product natural join sales\ngroup by product_id\nhaving min(sale_date)>=\'2019-01-01\' and max(sale_date)<=\'2019-03-31\'\n\n```\n# please upvote me it would encourage me alot\n
38
0
['MySQL']
4
sales-analysis-iii
✅MySQL || Beginner level || Faster than 98%||Simple-Short -Solution✅
mysql-beginner-level-faster-than-98simpl-d6uc
Please upvote to motivate me in my quest of documenting all leetcode solutions. HAPPY CODING:)\nAny suggestions and improvements are always welcome.\n==========
Anos
NORMAL
2022-08-31T19:50:56.737440+00:00
2022-08-31T19:50:56.737468+00:00
5,708
false
**Please upvote to motivate me in my quest of documenting all leetcode solutions. HAPPY CODING:)\nAny suggestions and improvements are always welcome.***\n*====================================================================*\n\u2705 **MySQL Code :**\n Your runtime beats 98.65 % of mysql submissions.\n```\nSELECT produ...
37
0
['MySQL']
4
sales-analysis-iii
MS SQL + 99.01% faster + Group by + Having
ms-sql-9901-faster-group-by-having-by-dd-y746
\nselect s.product_id, p.product_name\nfrom sales s, product p\nwhere s.product_id = p.product_id\ngroup by s.product_id, p.product_name\nhaving min(s.sale_date
ddeeps2610
NORMAL
2020-06-25T19:42:31.211291+00:00
2020-06-25T19:42:31.211338+00:00
5,580
false
```\nselect s.product_id, p.product_name\nfrom sales s, product p\nwhere s.product_id = p.product_id\ngroup by s.product_id, p.product_name\nhaving min(s.sale_date) >= \'2019-01-01\' \n and max(s.sale_date) <= \'2019-03-31\'\n```
37
0
[]
6
sales-analysis-iii
1084. Sales Analysis III
1084-sales-analysis-iii-by-spaulding-s8em
```\nSELECT product_id, product_name FROM Sales \nJOIN Product USING(product_id)\nGROUP BY product_id\nHAVING MIN(sale_date) >= \'2019-01-01\' AND MAX(sale_date
Spaulding_
NORMAL
2022-09-07T18:46:19.522886+00:00
2022-09-07T18:46:19.522927+00:00
3,204
false
```\nSELECT product_id, product_name FROM Sales \nJOIN Product USING(product_id)\nGROUP BY product_id\nHAVING MIN(sale_date) >= \'2019-01-01\' AND MAX(sale_date) <= \'2019-03-31\' ;
21
0
['MySQL']
0
sales-analysis-iii
MySQL solution | | Easy solution
mysql-solution-easy-solution-by-im_obid-yhfj
\n# Code\n\nselect product_id,product_name \nfrom Product where product_id not \nin \n(\n select p.product_id from Product p left join Sales s \n on p.pro
im_obid
NORMAL
2023-01-06T08:03:13.844296+00:00
2023-01-06T08:03:13.844340+00:00
6,335
false
\n# Code\n```\nselect product_id,product_name \nfrom Product where product_id not \nin \n(\n select p.product_id from Product p left join Sales s \n on p.product_id=s.product_id \n where s.sale_date <date(\'2019-01-01\') \n or\n s.sale_date >date(\'2019-03-31\') \n or\n s.seller_id is null \n);\n``...
20
0
['MySQL']
3
sales-analysis-iii
✅ 100% EASY || FAST 🔥|| CLEAN SOLUTION 🌟
100-easy-fast-clean-solution-by-kartik_k-cz62
\n\n# Code\n\nSELECT product_id, product_name FROM Product \n\nWHERE product_id IN(SELECT product_id FROM Sales \n\nGROUP BY product_id HAVING MIN(sale_date) >=
kartik_ksk7
NORMAL
2024-06-03T12:35:26.146669+00:00
2024-06-03T12:35:55.577222+00:00
1,625
false
\n\n# Code\n```\nSELECT product_id, product_name FROM Product \n\nWHERE product_id IN(SELECT product_id FROM Sales \n\nGROUP BY product_id HAVING MIN(sale_date) >= \'2019-01-01\'\n \nAND MAX(sale_date) <= \'2019-03-31\')\n```\n![5kej8w.jpg](https://assets.leetcode.com/users/images/87145625-632b-485e-90f7-09e96d3ede52_1...
19
0
['Oracle']
0
sales-analysis-iii
simple mysql solution
simple-mysql-solution-by-merciless-shck
\nSELECT product_id, product_name\nFROM product\nJOIN SALES\nUSING(product_id)\nGROUP BY product_id\nHAVING sum(CASE WHEN sale_date between \'2019-01-01\' and \
merciless
NORMAL
2019-06-14T03:55:12.517323+00:00
2019-06-14T03:55:12.517358+00:00
4,370
false
```\nSELECT product_id, product_name\nFROM product\nJOIN SALES\nUSING(product_id)\nGROUP BY product_id\nHAVING sum(CASE WHEN sale_date between \'2019-01-01\' and \'2019-03-31\' THEN 1 ELSE 0 end) > 0\nAND sum(CASE WHEN sale_date between \'2019-01-01\' and \'2019-03-31\' THEN 0 else 1 end) = 0\n```
14
0
[]
5
sales-analysis-iii
pandas || 2 lines, groupby and merge || T/S: 99% / 99%
pandas-2-lines-groupby-and-merge-ts-99-9-3rds
\nimport pandas as pd\n\ndef sales_analysis(product: pd.DataFrame, \n sales: pd.DataFrame) -> pd.DataFrame:\n\n df = sales.groupby([\'produ
Spaulding_
NORMAL
2024-05-15T23:33:09.487498+00:00
2024-05-22T16:16:33.681611+00:00
1,024
false
```\nimport pandas as pd\n\ndef sales_analysis(product: pd.DataFrame, \n sales: pd.DataFrame) -> pd.DataFrame:\n\n df = sales.groupby([\'product_id\'], as_index = False\n ).agg(min=(\'sale_date\', \'min\'), max=(\'sale_date\', \'max\'))\n\n return df[(df[\'min\'] >=\'2019-01-01\') &\...
13
0
['Pandas']
0
sales-analysis-iii
Absolutely the simplest solution
absolutely-the-simplest-solution-by-zcae-r8gp
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
Zcaelum
NORMAL
2023-01-12T06:42:02.420857+00:00
2023-01-12T06:42:02.420930+00:00
4,164
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)$$ --...
13
0
['MySQL']
3
sales-analysis-iii
Solution without JOIN using NOT IN and NOT BETWEEN
solution-without-join-using-not-in-and-n-ldvl
\nSELECT Product.product_id, Product.product_name\nFROM Product\nWHERE product_id NOT IN (SELECT product_id FROM Sales WHERE sale_date NOT BETWEEN \'2019-01-01\
tresmegistos
NORMAL
2019-10-29T23:48:39.621406+00:00
2019-10-29T23:48:39.621459+00:00
2,187
false
```\nSELECT Product.product_id, Product.product_name\nFROM Product\nWHERE product_id NOT IN (SELECT product_id FROM Sales WHERE sale_date NOT BETWEEN \'2019-01-01\' AND \'2019-03-31\');\n```
13
0
[]
6
sales-analysis-iii
[MySQL] || SubQuery || LEFT JOIN
mysql-subquery-left-join-by-comauro7511-2w65
Write your MySQL query statement below\n\n\nWITH cte AS\n(SELECT product_id FROM Sales\nWHERE sale_date > \'2019-03-31\'\nOR sale_date < \'2019-01-01\')\n\nSELE
comauro7511
NORMAL
2022-10-13T19:28:15.712648+00:00
2022-10-14T15:56:18.841752+00:00
3,013
false
# Write your MySQL query statement below\n```\n\nWITH cte AS\n(SELECT product_id FROM Sales\nWHERE sale_date > \'2019-03-31\'\nOR sale_date < \'2019-01-01\')\n\nSELECT DISTINCT s.product_id , p.product_name\nFROM Sales s\nLEFT JOIN Product p\nON s.product_id=p.product_id \nWHERE s.product_id NOT \nIN(SELECT product_id...
10
0
['MySQL']
1
sales-analysis-iii
[ MYSQL ] ✅✅ Simple MYSQL Solution Using Having Clause || Group By 🥳✌👍
mysql-simple-mysql-solution-using-having-qxki
If You like the Solution, Don\'t Forget To UpVote Me, Please UpVote! \uD83D\uDD3C\uD83D\uDE4F\n# Runtime: 998 ms, faster than 87.37% of MySQL online submissions
ashok_kumar_meghvanshi
NORMAL
2022-07-16T18:35:07.274533+00:00
2022-07-16T18:35:07.274576+00:00
942
false
# If You like the Solution, Don\'t Forget To UpVote Me, Please UpVote! \uD83D\uDD3C\uD83D\uDE4F\n# Runtime: 998 ms, faster than 87.37% of MySQL online submissions for Sales Analysis III.\n# Memory Usage: 0B, less than 100.00% of MySQL online submissions for Sales Analysis III.\n\n\tselect p.product_id, p.product_name\n...
10
0
['MySQL']
0
sales-analysis-iii
MSSQL Solution
mssql-solution-by-vdmhunter-r8jn
\nSELECT\n product_id,\n product_name\nFROM\n Product\nWHERE\n product_id IN\n (\n SELECT\n product_id\n FROM\n
vdmhunter
NORMAL
2022-06-14T22:47:03.748351+00:00
2022-06-14T22:47:03.748387+00:00
1,236
false
```\nSELECT\n product_id,\n product_name\nFROM\n Product\nWHERE\n product_id IN\n (\n SELECT\n product_id\n FROM\n Sales\n GROUP BY\n product_id\n HAVING\n MAX(sale_date) <= \'2019-03-31\'\n AND MIN(sale_date) >= \'2019-01...
9
0
['MySQL', 'MS SQL Server']
0
sales-analysis-iii
mysql +having
mysql-having-by-meskaj-292c
```\nSELECT \n p.product_id, p.product_name\nFROM \n product p\nJOIN \n Sales s\nON \n p.product_id = s.product_id \n\nGROUP BY s.pr
Meskaj
NORMAL
2021-08-20T04:43:33.283345+00:00
2021-08-20T04:48:51.954309+00:00
1,576
false
```\nSELECT \n p.product_id, p.product_name\nFROM \n product p\nJOIN \n Sales s\nON \n p.product_id = s.product_id \n\nGROUP BY s.product_id\n \n HAVING max(s.sale_date)<= \'2019-03-31\'\n AND MIN(s.sale_date)>=\'2019-01-01\';
9
0
['MySQL']
2