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
remove-colored-pieces-if-both-neighbors-are-the-same-color
🗓️ Daily LeetCoding Challenge October, Day 2
daily-leetcoding-challenge-october-day-2-ar5p
This problem is the Daily LeetCoding Challenge for October, Day 2. Feel free to share anything related to this problem here! You can ask questions, discuss what
leetcode
OFFICIAL
2023-10-02T00:00:05.698280+00:00
2023-10-02T00:00:05.698330+00:00
2,952
false
This problem is the Daily LeetCoding Challenge for October, Day 2. Feel free to share anything related to this problem here! You can ask questions, discuss what you've learned from this problem, or show off how many days of streak you've made! --- If you'd like to share a detailed solution to the problem, please cr...
5
0
[]
36
remove-colored-pieces-if-both-neighbors-are-the-same-color
Javascript Solution
javascript-solution-by-sunitmody-dkry
The trick here is to figure out how many total moves Alice and Bob will get in this game. If Alice has more moves than Bob then Alice wins. Otherwise Bob wins.\
sunitmody
NORMAL
2022-10-11T19:30:42.851205+00:00
2022-10-11T19:30:42.851241+00:00
271
false
The trick here is to figure out how many total moves Alice and Bob will get in this game. If Alice has more moves than Bob then Alice wins. Otherwise Bob wins.\n\ne.g. \'AAAABBBBAAA\'\n\n* We have four A\'s in a row in the beginning.\n\t* This means that Alice can do two moves here.\n* Then we have four B\'s in a row.\...
5
0
['JavaScript']
0
remove-colored-pieces-if-both-neighbors-are-the-same-color
[Python]: Count AAA and BBB and "return AAA > BBB"
python-count-aaa-and-bbb-and-return-aaa-9pivt
The basic idea here is that we count how many three consecutive AAA and BBB since Alice is only allowed to remove \'A\' if its neigbors are \'A\', i.e., AAA. Th
abuomar2
NORMAL
2021-10-17T16:49:11.756385+00:00
2021-10-17T16:49:11.756410+00:00
559
false
The basic idea here is that we count how many three consecutive AAA and BBB since Alice is only allowed to remove \'A\' if its neigbors are \'A\', i.e., A**A**A. Thus, we count how many \'AAA\' and \'BBB\' and whoever has more will defintely win since the other one will run out of characters to remove earlier/faster. \...
5
0
['Python', 'Python3']
0
remove-colored-pieces-if-both-neighbors-are-the-same-color
[JAVA] 100% fast, with explanation in detail
java-100-fast-with-explanation-in-detail-m7vi
\'\'\'\nclass Solution {\n public boolean winnerOfGame(String colors) {\n \n if(colors.length() <=2)\n {\n return false; //
Shourya112001
NORMAL
2021-10-16T18:05:58.903597+00:00
2021-10-16T18:05:58.903633+00:00
564
false
\'\'\'\nclass Solution {\n public boolean winnerOfGame(String colors) {\n \n if(colors.length() <=2)\n {\n return false; // BOB will win if "AA" or "BB" or "A" or "B"\n }\n \n int[] triple = triplets(colors); //Calculating all the triplets in the string AAA, BBB\...
5
1
['Java']
2
remove-colored-pieces-if-both-neighbors-are-the-same-color
O(N) python
on-python-by-saurabht462-fa4d
```\ndef winnerOfGame(self, colors: str) -> bool:\n alice=0\n bob =0\n for i in range(1,len(colors)-1):\n if colors[i]=="A":\n
saurabht462
NORMAL
2021-10-16T16:00:39.012654+00:00
2021-10-16T16:01:27.945025+00:00
399
false
```\ndef winnerOfGame(self, colors: str) -> bool:\n alice=0\n bob =0\n for i in range(1,len(colors)-1):\n if colors[i]=="A":\n if colors[i-1]=="A" and colors[i+1]=="A":\n alice+=1\n else:\n if colors[i-1]=="B" and colors[i+1]=="...
5
2
[]
0
remove-colored-pieces-if-both-neighbors-are-the-same-color
Simple C++ solution using only counts. Detailed Explanation
simple-c-solution-using-only-counts-deta-uy0k
Intuition\n Describe your first thoughts on how to solve this problem. \nHello y\'all. So this problem states that there are 2 people Alice and Bob who are play
chandu_345
NORMAL
2023-10-02T08:47:15.896783+00:00
2023-10-02T16:57:04.352643+00:00
215
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nHello y\'all. So this problem states that there are 2 people $$Alice$$ and $$Bob$$ who are playing a 2 - player turn based game. The idea of the game is to remove a color (represented by $$\'A\'$$ or $$\'B\'$$) from a string of colors . A...
4
0
['C++']
1
remove-colored-pieces-if-both-neighbors-are-the-same-color
NOOB CODE : Easy to Understand
noob-code-easy-to-understand-by-harshava-k18z
Approach\n\n1. It initializes two variables al and bo to 0 to keep track of the number of consecutive colors for player \'A\' and player \'B\', respectively.\n\
HARSHAVARDHAN_15
NORMAL
2023-10-02T07:19:45.393147+00:00
2023-10-02T07:19:45.393181+00:00
118
false
# Approach\n\n1. It initializes two variables `al` and `bo` to 0 to keep track of the number of consecutive colors for player \'A\' and player \'B\', respectively.\n\n2. It then iterates through the string `colors` from the second character (index 1) to the second-to-last character (index `len(colors) - 2`).\n\n3. Insi...
4
0
['Python3']
0
remove-colored-pieces-if-both-neighbors-are-the-same-color
Video Solution | Explanation With Drawings | In Depth | C++ | Java | Python 3
video-solution-explanation-with-drawings-87b4
Intuition and approach discussed in detail in video solution\nhttps://youtu.be/Pkywd65nA6Q\n\n# Code\nC++\n\nclass Solution {\npublic:\n bool winnerOfGame(st
Fly_ing__Rhi_no
NORMAL
2023-10-02T02:02:13.498505+00:00
2023-10-02T02:02:13.498523+00:00
139
false
# Intuition and approach discussed in detail in video solution\nhttps://youtu.be/Pkywd65nA6Q\n\n# Code\nC++\n```\nclass Solution {\npublic:\n bool winnerOfGame(string colors) {\n int threeA = 0;\n int threeB = 0;\n int sz = colors.size();\n for(int indx = 1; indx < sz - 1; indx++){\n ...
4
0
['C++', 'Java', 'Python3']
0
remove-colored-pieces-if-both-neighbors-are-the-same-color
Maintain 1 score Greedy
maintain-1-score-greedy-by-glamour-1wim
Intuition\nWe do not need to maintain two scores. Only one alice_over_bob is enough.\n\n\n# Approach\n Describe your approach to solving the problem. \n\n# Comp
glamour
NORMAL
2023-10-02T01:46:21.820208+00:00
2023-10-02T01:46:21.820229+00:00
31
false
# Intuition\nWe do not need to maintain two scores. Only one `alice_over_bob` is enough.\n\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: $$O(n)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(1)$$\n<!-- Add your space com...
4
0
['Kotlin']
0
remove-colored-pieces-if-both-neighbors-are-the-same-color
🔥💥 Easy Simple C++ Code With O(n) Time Complexity & O(1) Space Complexity 💥🔥
easy-simple-c-code-with-on-time-complexi-q5jd
Intuition\n Describe your first thoughts on how to solve this problem. \nThe goal is to determine the winner of a game based on a sequence of colors denoted by
eknath_mali_002
NORMAL
2023-10-02T00:41:20.028165+00:00
2023-10-02T00:41:20.028183+00:00
240
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe goal is to determine the winner of a game based on a sequence of colors denoted by \'A\' and \'B\'. We aim to count the occurrences of \'A\' and \'B\' sequences of length 3 or more. The player with the most such occurrences is declare...
4
0
['String', 'Greedy', 'Game Theory', 'C++']
0
remove-colored-pieces-if-both-neighbors-are-the-same-color
Java | String | Counting | Simple Solution
java-string-counting-simple-solution-by-y925w
\nclass Solution {\n public boolean winnerOfGame(String colors) {\n int as=0,bs=0; \n for (int i=1;i<colors.length()-1;i++) {\n
Divyansh__26
NORMAL
2022-09-16T08:03:51.236672+00:00
2022-09-16T08:03:51.236710+00:00
815
false
```\nclass Solution {\n public boolean winnerOfGame(String colors) {\n int as=0,bs=0; \n for (int i=1;i<colors.length()-1;i++) {\n if(colors.charAt(i-1)==\'A\' && colors.charAt(i)==\'A\' && colors.charAt(i+1)==\'A\') \n as++;\n if(colors.charAt(i-1)==\'B\' &&...
4
0
['String', 'Counting', 'Java']
1
remove-colored-pieces-if-both-neighbors-are-the-same-color
Python simple solution
python-simple-solution-by-mukeshr-8jtb
Just scan the array and count the number of consecutive A\'s or B\'s of length 3\n\n\nclass Solution:\n def winnerOfGame(self, colors: str) -> bool:\n
mukeshR
NORMAL
2022-08-02T02:30:25.480448+00:00
2022-08-02T02:30:25.480477+00:00
332
false
Just scan the array and count the number of consecutive A\'s or B\'s of length 3\n\n```\nclass Solution:\n def winnerOfGame(self, colors: str) -> bool:\n \n num_3consecutive_As = 0\n num_3consecutive_Bs = 0\n \n for i in range(0, len(colors)-2):\n \n if colors...
4
0
[]
0
remove-colored-pieces-if-both-neighbors-are-the-same-color
Sliding window | Single Pass | O(1) space
sliding-window-single-pass-o1-space-by-s-u0ro
\n# Approach\nUsing sliding window of size if size>2 then add size-2 in the index of Alice/freqa[0] or Bob/freqb[1] else add 0 our window is not useful\n\n\n# C
seal541
NORMAL
2024-01-08T03:27:42.022794+00:00
2024-01-08T03:27:42.022823+00:00
6
false
\n# Approach\nUsing sliding window of `size` if size>2 then add `size-2` in the index of `Alice`/`freqa[0]` or `Bob`/`freqb[1]` else add `0` our window is not useful\n\n\n# Complexity\n- Time complexity:\n`O(n)`\n\n- Space complexity:\n`O(1)`\n\n# Code\n```\nclass Solution {\npublic:\n bool winnerOfGame(string color...
3
0
['String', 'Sliding Window', 'C++']
0
remove-colored-pieces-if-both-neighbors-are-the-same-color
1 Liner Easy | Java | Explained✅
1-liner-easy-java-explained-by-4ryangaut-3uab
colors.replaceAll("A{3,}", "AA"): This part of the code uses the replaceAll method to search for substrings of "A" that appear three or more times consecutively
4ryangautam
NORMAL
2023-10-02T07:01:43.814967+00:00
2023-10-02T07:09:17.901115+00:00
145
false
- colors.replaceAll("A{3,}", "AA"): This part of the code uses the replaceAll method to search for substrings of "A" that appear three or more times consecutively and replace them with "AA". In regular expressions, "{3,}" means "three or more occurrences." So, this part of the code is essentially replacing sequences of...
3
0
['Game Theory', 'Java']
0
remove-colored-pieces-if-both-neighbors-are-the-same-color
Medium problem made easy! JavaScript solution (Slow though)
medium-problem-made-easy-javascript-solu-6yxd
Intuition\nThe problem seems to involve counting the number of consecutive sequences of the same color ("A" or "B") and determining the winner based on these co
shaakilkabir
NORMAL
2023-10-02T07:00:06.786339+00:00
2023-10-02T07:00:06.786370+00:00
198
false
# Intuition\nThe problem seems to involve counting the number of consecutive sequences of the same color ("A" or "B") and determining the winner based on these counts.\n\n# Approach\nWe can traverse the input string, keeping track of consecutive occurrences of each color ("A" or "B"). We\'ll count the number of each in...
3
0
['JavaScript']
0
remove-colored-pieces-if-both-neighbors-are-the-same-color
C++ Solution || Beats 99% || Easy To Understand
c-solution-beats-99-easy-to-understand-b-unwy
Easy To Understand Solution\n\n# Approach: Count\n\n# Intuition\nThere are two very important things to notice about this game that will allow us to easily sol
BruteForce_03
NORMAL
2023-10-02T06:25:34.499702+00:00
2023-10-02T06:31:45.993045+00:00
50
false
# Easy To Understand Solution\n\n# Approach: Count\n\n# Intuition\nThere are two very important things to notice about this game that will allow us to easily solve the problem:\n\nWhen one player removes a letter, it will never create a new removal opportunity for the other player. For example, let\'s say you had *"AB...
3
0
['Greedy', 'Game Theory', 'C++']
0
remove-colored-pieces-if-both-neighbors-are-the-same-color
c++, Time:O(N), space:O(1) beginner friendly solution
c-timeon-spaceo1-beginner-friendly-solut-2nep
Intuition\nconsider an examples "AA" or "BB" or "A" or "B".From all this example we can understand string length should be greater than or equal to 3.Because wh
satya_siva_prasad
NORMAL
2023-10-02T05:41:50.939244+00:00
2023-10-02T05:41:50.939263+00:00
84
false
# Intuition\nconsider an examples "AA" or "BB" or "A" or "B".From all this example we can understand string length should be greater than or equal to 3.Because when string length is lessthan 3 we cann\'t find 3 consecutive A\'s. \nThis problems is as simple as finding number of 3 consecutive A\'s and \nnumber of 3 cons...
3
0
['String', 'C++']
1
remove-colored-pieces-if-both-neighbors-are-the-same-color
Sliding Windows approach | Easy CPP
sliding-windows-approach-easy-cpp-by-him-hhj9
Upvote is you like the approach \n# Code\n\nclass Solution {\npublic:\n bool winnerOfGame(string colors) {\n int n=colors.size();\n if(n<=2) re
himanshumude01
NORMAL
2023-10-02T05:24:43.890310+00:00
2023-10-02T05:24:43.890343+00:00
85
false
## Upvote is you like the approach \n# Code\n```\nclass Solution {\npublic:\n bool winnerOfGame(string colors) {\n int n=colors.size();\n if(n<=2) return false;\n int i=0,j=2;\n int cA=0,cB=0;\n while(j<n)\n {\n if(colors[i]==\'A\' and colors[i+1]==\'A\' and color...
3
0
['C++']
2
remove-colored-pieces-if-both-neighbors-are-the-same-color
✅ JavaScript - 94%, one pass, O(n)
javascript-94-one-pass-on-by-daria_abdul-b62c
Approach\n Describe your approach to solving the problem. \nWe can count the result of the game before the start because any turn of one player can\'t add new p
daria_abdulnasyrova
NORMAL
2023-04-01T08:02:25.676948+00:00
2023-04-01T08:07:06.287152+00:00
103
false
# Approach\n<!-- Describe your approach to solving the problem. -->\nWe can count the result of the game before the start because any turn of one player can\'t add new possible turns to another player. We count amount of possible turns for A and B in one pass, then compare it.\n\nTime complexity: $$O(n)$$.\n<!-- Add yo...
3
0
['JavaScript']
0
remove-colored-pieces-if-both-neighbors-are-the-same-color
Java Solution using Sliding Window
java-solution-using-sliding-window-by-so-mvv9
\nclass Solution {\n public boolean winnerOfGame(String colors) {\n int countA = 0;\n int countB = 0;\n \n for (int i = 0; i < co
solved
NORMAL
2022-03-26T16:32:09.544445+00:00
2022-03-26T16:32:09.544480+00:00
328
false
```\nclass Solution {\n public boolean winnerOfGame(String colors) {\n int countA = 0;\n int countB = 0;\n \n for (int i = 0; i < colors.length() - 2; i++) {\n char c1 = colors.charAt(i);\n char c2 = colors.charAt(i + 1);\n char c3 = colors.charAt(i + 2);\...
3
0
['Sliding Window', 'Java']
0
remove-colored-pieces-if-both-neighbors-are-the-same-color
C++ easiest solution!
c-easiest-solution-by-anchal_soni-vdjt
\nclass Solution {\npublic:\n bool winnerOfGame(string colors) {\n \n int n=colors.size();\n if(n<=2) return false;\n\t\t\n int a
anchal_soni
NORMAL
2021-10-20T14:12:15.642662+00:00
2021-10-20T14:12:15.642706+00:00
369
false
```\nclass Solution {\npublic:\n bool winnerOfGame(string colors) {\n \n int n=colors.size();\n if(n<=2) return false;\n\t\t\n int a=0;\n int b=0;\n \n for(int i=1;i<n-1;++i)\n {\n if(colors[i]==\'A\' and colors[i-1]==\'A\' and colors[i+1]==\'A\') a+...
3
0
['C', 'C++']
1
remove-colored-pieces-if-both-neighbors-are-the-same-color
JavaScript - JS
javascript-js-by-mlienhart-zk0p
\n/**\n * @param {string} colors\n * @return {boolean}\n */\nvar winnerOfGame = function (colors) {\n let a = 0;\n let b = 0;\n\n for (let i = 1; i < colors.
mlienhart
NORMAL
2021-10-18T21:21:57.560884+00:00
2021-10-18T21:21:57.560925+00:00
222
false
```\n/**\n * @param {string} colors\n * @return {boolean}\n */\nvar winnerOfGame = function (colors) {\n let a = 0;\n let b = 0;\n\n for (let i = 1; i < colors.length - 1; i++) {\n if (colors[i - 1] === colors[i] && colors[i + 1] === colors[i]) {\n colors[i] === "A" ? a++ : b++;\n }\n }\n\n return a > b...
3
0
[]
0
remove-colored-pieces-if-both-neighbors-are-the-same-color
C++ Solution
c-solution-by-sanchitjain-gjop
\nclass Solution {\npublic:\n bool winnerOfGame(string c) {\n int a = 0,b =0;\n for(int i = 1 ; i < c.length()-1 ; i++){\n\t\t// Counting the n
sanchitjain
NORMAL
2021-10-16T16:19:38.317831+00:00
2021-10-25T11:19:22.122988+00:00
143
false
```\nclass Solution {\npublic:\n bool winnerOfGame(string c) {\n int a = 0,b =0;\n for(int i = 1 ; i < c.length()-1 ; i++){\n\t\t// Counting the number of \'AAA\' & \'BBB\'\n if( c[i] == \'A\' && c[i-1] == \'A\' && c[i+1] == \'A\' ){\n a++;\n }else if(c[i] == \'B\'...
3
0
['C']
0
remove-colored-pieces-if-both-neighbors-are-the-same-color
O(n) Time | Count consecutive AAAs & BBBs
on-time-count-consecutive-aaas-bbbs-by-i-u1cq
\nC++\n\nclass Solution {\npublic:\n bool winnerOfGame(string colors) {\n int cntA=0,cntB=0;\n for(int i=1;i<colors.size()-1;i++){\n\t\t\t// Co
inomag
NORMAL
2021-10-16T16:19:01.279596+00:00
2021-10-16T16:23:38.939769+00:00
267
false
\n***C++***\n```\nclass Solution {\npublic:\n bool winnerOfGame(string colors) {\n int cntA=0,cntB=0;\n for(int i=1;i<colors.size()-1;i++){\n\t\t\t// Count of Consecutive \'AAA\'s which Alice can remove\n if(colors[i]==\'A\'&&colors[i-1]==\'A\'&&colors[i+1]==\'A\')cntA++;\n\t\t\t\n\t\t\t// C...
3
0
['C', 'Java']
0
remove-colored-pieces-if-both-neighbors-are-the-same-color
understandable
understandable-by-user7868kf-o64j
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
user7868kf
NORMAL
2023-10-18T14:19:25.549171+00:00
2023-10-18T14:19:25.549191+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)$$ --...
2
0
['Java']
0
remove-colored-pieces-if-both-neighbors-are-the-same-color
C++ Solution
c-solution-by-pranto1209-ywpm
Complexity\n- Time complexity:\n Add your time complexity here, e.g. O(n) \n O(N)\n\n- Space complexity:\n Add your space complexity here, e.g. O(n) \n O(
pranto1209
NORMAL
2023-10-05T09:05:47.502873+00:00
2023-10-05T09:05:47.502890+00:00
4
false
# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n O(N)\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n O(1)\n\n# Code\n```\nclass Solution {\npublic:\n bool winnerOfGame(string colors) {\n int alice = 0, bob = 0;\n for(int i...
2
0
['C++']
0
remove-colored-pieces-if-both-neighbors-are-the-same-color
Very easily understandable
very-easily-understandable-by-ritwik24-hox5
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
ritwik24
NORMAL
2023-10-03T15:40:43.488291+00:00
2023-10-03T15:40:43.488309+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)$$ --...
2
0
['C++']
1
remove-colored-pieces-if-both-neighbors-are-the-same-color
🔥🔥🔥Easiest Approach || O(n) time and O(1) space || beginner friendly solution 🔥🔥🔥
easiest-approach-on-time-and-o1-space-be-id18
Intuition\n Describe your first thoughts on how to solve this problem. \nTry to think as subarray problem having length >= 3.\n\n# Approach\n Describe your appr
pandeyashutosh02
NORMAL
2023-10-03T04:19:35.867194+00:00
2023-10-03T04:19:35.867218+00:00
6
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nTry to think as subarray problem having length >= 3.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nTake all the subarrays of A and B having length greater than or equal to 3 and store them into a final variable (...
2
0
['C++']
0
remove-colored-pieces-if-both-neighbors-are-the-same-color
✅Simplest Solution 🤎 Y O U #TGM
simplest-solution-y-o-u-tgm-by-eliminate-hkvk
\n Describe your first thoughts on how to solve this problem. \n\n\n# Approach\n Describe your approach to solving the problem. \nStep-1 -> Intialize Alice and
EliminateCoding
NORMAL
2023-10-02T17:14:22.186339+00:00
2023-10-02T17:14:22.186371+00:00
17
false
\n<!-- Describe your first thoughts on how to solve this problem. -->\n<i>\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nStep-1 -> Intialize Alice and Bob and iterate over input array from 1st index to last but one to avoid array index out of bounds exception \nStep-2 -> Start comparing previo...
2
0
['String', 'Java']
1
remove-colored-pieces-if-both-neighbors-are-the-same-color
Simple Approach and Answer. No fancy code
simple-approach-and-answer-no-fancy-code-rjut
\n\n# Approach\n Describe your approach to solving the problem. \nSimply we can count the number of times Alice can pop and the number of times Bob can pop. And
siddd7
NORMAL
2023-10-02T17:04:14.234125+00:00
2023-10-02T17:04:51.014757+00:00
48
false
\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nSimply we can count the number of times Alice can pop and the number of times Bob can pop. And return whether Alice has the more count or not.\n\n# Complexity\n- Time complexity: O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Spa...
2
0
['Math', 'String', 'Greedy', 'Game Theory', 'Python3']
0
remove-colored-pieces-if-both-neighbors-are-the-same-color
🐍😱 Really Scary Python One-Liner! 🎃
really-scary-python-one-liner-by-galimov-zcxo
Faster than 98.94% of all solutions\n\n# Code\n\nclass Solution:\n def winnerOfGame(self, colors: str) -> bool:\n return sum((len(i) - 2)*(1 if i[0] i
galimovdv
NORMAL
2023-10-02T16:01:39.047460+00:00
2023-10-02T16:03:21.878197+00:00
143
false
**Faster than 98.94% of all solutions**\n\n# Code\n```\nclass Solution:\n def winnerOfGame(self, colors: str) -> bool:\n return sum((len(i) - 2)*(1 if i[0] is \'A\' else -1) for i in filter(lambda x: len(x) > 2, colors.replace(\'AB\', \'AxB\').replace(\'BA\', \'BxA\').split("x"))) > 0\n```
2
0
['Python3']
5
remove-colored-pieces-if-both-neighbors-are-the-same-color
✅☑[C++] || O(n) || Easiest Solutions || EXPLAINED🔥
c-on-easiest-solutions-explained-by-mark-3d7p
\n\n\n# PLEASE UPVOTE IF IT HELPED\n\n---\n\n# Approach\n(Also explained in the code)\n1. The function winnerOfGame takes a string colors as input, which repres
MarkSPhilip31
NORMAL
2023-10-02T15:43:44.179146+00:00
2023-10-02T15:43:44.179172+00:00
106
false
\n\n\n# *PLEASE UPVOTE IF IT HELPED*\n\n---\n\n# Approach\n***(Also explained in the code)***\n1. The function `winnerOfGame` takes a string `colors` as input, which represents a sequence of colors played in a game.\n\n1. It initializes `a` and `b` to zero. These variables are used to count the consecutive triplets of ...
2
0
['Math', 'String', 'Greedy', 'Game Theory', 'C++']
0
remove-colored-pieces-if-both-neighbors-are-the-same-color
Most optimal solution with complete exaplanation
most-optimal-solution-with-complete-exap-n5og
\n# Approach\nThe solution iterates through the input string colors. For each position i, it checks if the character at that position and its neighboring charac
priyanshu11_
NORMAL
2023-10-02T12:55:04.195030+00:00
2023-10-02T12:55:04.195053+00:00
67
false
\n# Approach\nThe solution iterates through the input string colors. For each position i, it checks if the character at that position and its neighboring characters (at positions i-1 and i+1) satisfy the conditions mentioned in the game rules. If the conditions are met, Alice or Bob can make a move, and their correspon...
2
0
['Math', 'String', 'Greedy', 'Game Theory', 'Python', 'C++', 'Java', 'Python3']
1
remove-colored-pieces-if-both-neighbors-are-the-same-color
simple solution
simple-solution-by-hrushikeshmahajan044-k44e
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
HrushikeshMahajan044
NORMAL
2023-10-02T10:48:15.116709+00:00
2023-10-02T10:48:15.116732+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)$$ --...
2
0
['C++']
0
remove-colored-pieces-if-both-neighbors-are-the-same-color
✅100%🔥Kotlin🔥Easy Solution
100kotlineasy-solution-by-umairzahid907-4zk3
Intuition\nThe goal is to determine the winner of the game where Alice and Bob take alternating turns removing pieces with specific color conditions. Alice can
umairzahid907
NORMAL
2023-10-02T10:29:30.120324+00:00
2023-10-02T10:29:30.120348+00:00
10
false
# Intuition\nThe goal is to determine the winner of the game where Alice and Bob take alternating turns removing pieces with specific color conditions. Alice can only remove a piece colored \'A\' if both of its neighbors are also \'A\', and Bob can only remove a piece colored \'B\' under the same condition. The player ...
2
0
['Kotlin']
0
remove-colored-pieces-if-both-neighbors-are-the-same-color
Easy solution with single counter || Beats 99.52% from memory usage || Python
easy-solution-with-single-counter-beats-xht81
Code\n\nclass Solution:\n def winnerOfGame(self, colors: str) -> bool:\n c = 0\n\n for i in range(1, len(colors)-1):\n if colors[i-1
sheshan25
NORMAL
2023-10-02T08:22:11.693631+00:00
2023-10-02T08:23:15.781457+00:00
19
false
# Code\n```\nclass Solution:\n def winnerOfGame(self, colors: str) -> bool:\n c = 0\n\n for i in range(1, len(colors)-1):\n if colors[i-1]=="A" and colors[i]=="A" and colors[i+1]=="A":\n c +=1\n elif colors[i-1]=="B" and colors[i]=="B" and colors[i+1]=="B":\n ...
2
0
['Math', 'String', 'Greedy', 'Game Theory', 'Python3']
0
remove-colored-pieces-if-both-neighbors-are-the-same-color
Easy Python solution with Explanation | O(n) O(1) Beats 99.93%
easy-python-solution-with-explanation-on-9cjf
\n# Approach\n Describe your approach to solving the problem. \nSince we need to have 3 A\'s or 3 B\'s in a sequence, We will first calculate the number of thos
ramakrishna1607
NORMAL
2023-10-02T06:17:43.475616+00:00
2023-10-02T06:17:43.475647+00:00
6
false
\n# Approach\n<!-- Describe your approach to solving the problem. -->\nSince we need to have 3 A\'s or 3 B\'s in a sequence, We will first calculate the number of those occurences.\nBut if the given string length is less than 3, there is no possibility of starting the game. So we return False\nWe now compare the number...
2
0
['Python3']
0
remove-colored-pieces-if-both-neighbors-are-the-same-color
🔥 C++ Solution || O(n) time and O(1) space || Greedy approach
c-solution-on-time-and-o1-space-greedy-a-coq4
\n# Code\n\nclass Solution {\npublic:\n bool winnerOfGame(string colors) {\n int aliceTurns = 0, bobTurns = 0;\n int n = colors.size();\n\n
ravi_verma786
NORMAL
2023-10-02T06:05:27.860476+00:00
2023-10-02T06:05:27.860495+00:00
51
false
\n# Code\n```\nclass Solution {\npublic:\n bool winnerOfGame(string colors) {\n int aliceTurns = 0, bobTurns = 0;\n int n = colors.size();\n\n for(int i=2;i<n;i++){\n if(colors[i] == \'A\' && colors[i-1] == \'A\' && colors[i-2] == \'A\'){\n aliceTurns++;\n }\...
2
0
['String', 'Greedy', 'C++']
0
remove-colored-pieces-if-both-neighbors-are-the-same-color
✅ Easy and straightforward || One Loop 🔁, Indicators 🚦 || and animation 🎮"
easy-and-straightforward-one-loop-indica-w3tp
Intuition\n\n\n\n# Approach\n Describe your approach to solving the problem. \n1. Initialize three variables: am and bm to keep track of the scores of players A
Tyrex_19
NORMAL
2023-10-02T05:53:25.115999+00:00
2023-10-02T07:18:43.528559+00:00
29
false
# Intuition\n![ezgif.com-video-to-gif (11).gif](https://assets.leetcode.com/users/images/f467437b-101c-49f5-a320-7e2d38f751e5_1696229474.0028176.gif)\n\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. Initialize three variables: **am** and **bm** to keep track of the scores of players A and B ...
2
0
['C++']
0
remove-colored-pieces-if-both-neighbors-are-the-same-color
#3_Line Solution For Begginers simple One With explanation ✔️✔️✅
3_line-solution-for-begginers-simple-one-l6ii
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\ncount the Alice\'s play and Bob\'s play is alice\'s turn is greater then
nandunk
NORMAL
2023-10-02T05:01:02.668478+00:00
2023-10-02T05:01:02.668503+00:00
3
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\ncount the Alice\'s play and Bob\'s play is alice\'s turn is greater then he win else he lose the game \n# Complexity\n- Time complexity:\n $$O(n)$$ -\n\n- Space complexity:\n$$O(1)$$ \n\n# Code\n```\nclass Solution {\npublic...
2
0
['C++']
0
remove-colored-pieces-if-both-neighbors-are-the-same-color
🔥Beats 100% | ✅ Line by Line Expl. | [PY/Java/C++/C#/C/JS/Rust/Go]
beats-100-line-by-line-expl-pyjavacccjsr-1blo
python []\nclass Solution:\n def winnerOfGame(self, colors: str) -> bool:\n totalA = 0 # Initialize a variable to store the total points of player A.
Neoni_77
NORMAL
2023-10-02T04:48:07.235486+00:00
2023-10-02T04:48:07.235520+00:00
345
false
```python []\nclass Solution:\n def winnerOfGame(self, colors: str) -> bool:\n totalA = 0 # Initialize a variable to store the total points of player A.\n totalB = 0 # Initialize a variable to store the total points of player B.\n currA = 0 # Initialize a variable to count the current consec...
2
0
['C', 'C++', 'Java', 'Go', 'Python3', 'Rust', 'JavaScript', 'C#']
2
remove-colored-pieces-if-both-neighbors-are-the-same-color
✅"2" Lines of Code with "2" Step Explanation❤️💯🔥
2-lines-of-code-with-2-step-explanation-1rzl9
Approach\nStep 1: Initialization and Loop\n- Two integer variables a and b are initialized to 0. These variables will be used to keep track of the number of con
ReddySaiNitishSamudrala
NORMAL
2023-10-02T04:08:27.621673+00:00
2023-10-02T04:08:27.621699+00:00
19
false
# Approach\nStep 1: Initialization and Loop\n- Two integer variables `a` and `b` are initialized to 0. These variables will be used to keep track of the number of consecutive triplets \'AAA\' and \'BBB\' in the input string `s`, respectively.\n- The code then enters a `for` loop that iterates over the characters of the...
2
0
['Java']
1
remove-colored-pieces-if-both-neighbors-are-the-same-color
Bests Java Solution || Beats 80%
bests-java-solution-beats-80-by-ravikuma-9exq
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-10-02T03:41:30.347319+00:00
2023-10-02T03:41:30.347346+00:00
391
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
2
0
['Java']
0
remove-colored-pieces-if-both-neighbors-are-the-same-color
O(n) time O(1) space solution greedy
on-time-o1-space-solution-greedy-by-saks-a25u
Intuition\n Describe your first thoughts on how to solve this problem. \n\nAfter seeing the question the first thing that comes to mind is number of moves for a
sakshamag_16
NORMAL
2023-10-02T03:36:05.132301+00:00
2023-10-02T03:36:05.132323+00:00
32
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\nAfter seeing the question the first thing that comes to mind is number of moves for alice should be greater than number of moves Bob for ALice to win. Hence we need to find number of moves of both the players.\n\n# Approach\n<!-- Descri...
2
0
['Math', 'Greedy', 'C++']
0
remove-colored-pieces-if-both-neighbors-are-the-same-color
🐢Slow and Unintuitive Python Solution | Slower than 95%🐢
slow-and-unintuitive-python-solution-slo-qy77
\nThe top solution explains how this game is not very complicated and you can determine the winner by counting the number of As and Bs. This is like a more comp
JeliHacker
NORMAL
2023-10-02T02:21:02.982913+00:00
2023-10-02T02:21:02.982939+00:00
61
false
\nThe top solution explains how this game is not very complicated and you can determine the winner by counting the number of As and Bs. This is like a more complicated version of that solution.\uD83D\uDE0E \n\n```\nclass Solution:\n def winnerOfGame(self, colors: str) -> bool:\n count = 0 # 0 if Alice\'s turn...
2
0
['Python3']
1
remove-colored-pieces-if-both-neighbors-are-the-same-color
Beats 96.22% in speed || Two Pointer Approach || Very Short
beats-9622-in-speed-two-pointer-approach-c466
Intuition\nThe code appears to be implementing a function winnerOfGame that takes a string colors as input. This function aims to determine the winner of a game
NinjaFire
NORMAL
2023-10-02T02:17:40.178897+00:00
2023-10-02T02:18:29.918533+00:00
186
false
# Intuition\nThe code appears to be implementing a function winnerOfGame that takes a string colors as input. This function aims to determine the winner of a game based on certain rules related to consecutive color sequences.\n\n# Approach\nThe code uses a while loop to iterate over the characters of the colors string....
2
0
['Two Pointers', 'String', 'Counting', 'Game Theory', 'C++']
1
remove-colored-pieces-if-both-neighbors-are-the-same-color
Easy to understand.
easy-to-understand-by-mukeshgupta-7k9j
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach Using Loop.\n Describe your approach to solving the problem. \n\n# Complex
mukeshgupta_
NORMAL
2023-10-02T00:46:36.934465+00:00
2023-10-02T00:46:36.934484+00:00
5
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach Using Loop.\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add your space complexity ...
2
0
['Java']
0
remove-colored-pieces-if-both-neighbors-are-the-same-color
3'A >3'B Solution...
3a-3b-solution-by-striver_011-i6ru
Intuition\n Describe your first thoughts on how to solve this problem. \nThe thing is to obsever the three consecutive A\'s && B\'s hence the turn will take one
striver_011
NORMAL
2023-05-26T14:00:33.007896+00:00
2023-05-26T14:00:33.007941+00:00
487
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe thing is to obsever the three consecutive A\'s && B\'s hence the turn will take one by one right..! hence the count of consecutive A\'s are greater than the consecutive B\'s then definately Alice win which of consecutive A\'s right..!...
2
1
['C++']
3
remove-colored-pieces-if-both-neighbors-are-the-same-color
2 solutions | Counting & Stack | C++
2-solutions-counting-stack-c-by-tusharbh-e7cd
Counting\n\nclass Solution {\npublic:\n bool winnerOfGame(string colors) {\n long long cntA = 0, cntB = 0, alice = 0, bob = 0;\n for(char c : c
TusharBhart
NORMAL
2023-03-25T11:04:31.980457+00:00
2023-03-25T11:04:31.980488+00:00
802
false
# Counting\n```\nclass Solution {\npublic:\n bool winnerOfGame(string colors) {\n long long cntA = 0, cntB = 0, alice = 0, bob = 0;\n for(char c : colors) {\n if(c == \'A\') {\n cntA++;\n if(cntA >= 3) alice += cntA - 2;\n cntB = 0;\n }...
2
0
['Stack', 'Counting', 'C++']
0
remove-colored-pieces-if-both-neighbors-are-the-same-color
Cpp Solution O(n) || Simple Solution
cpp-solution-on-simple-solution-by-indom-nyem
Intuition\nCount the Number of "AAA" and "BBB"\n\n# Approach\n-> Count number of "AAA" and "BBB" and store them in a variable\n\n-> If count of "AAA" is more th
Indominous1
NORMAL
2022-11-08T10:22:55.066787+00:00
2022-11-17T19:08:45.393112+00:00
592
false
# Intuition\nCount the Number of "AAA" and "BBB"\n\n# Approach\n-> Count number of "AAA" and "BBB" and store them in a variable\n\n-> If count of "AAA" is more than "BBB" than than Alice wins otherwise Bob wins Why?\n\n> If count of "AAA" is less than "BBB" than Bob have more pieces to remove, and if count of both "AAA...
2
0
['Math', 'String', 'C', 'Counting', 'C++']
0
remove-colored-pieces-if-both-neighbors-are-the-same-color
Solution : Remove Colored Pieces if Both Neighbors are the Same Color
solution-remove-colored-pieces-if-both-n-x6u5
```class Solution {\n public boolean winnerOfGame(String c) {\n int a = 0;\n int b = 0; \n for(int i = 1; i <= c.length() - 2; i++){\n
rahul_m
NORMAL
2022-08-17T22:36:07.038890+00:00
2022-08-17T22:37:07.147855+00:00
249
false
```class Solution {\n public boolean winnerOfGame(String c) {\n int a = 0;\n int b = 0; \n for(int i = 1; i <= c.length() - 2; i++){\n if((c.charAt(i) == c.charAt(i-1)) && (c.charAt(i) == c.charAt(i+1))){\n if(c.charAt(i) == \'A\') {\n a++;\n ...
2
0
['Math', 'Java']
0
remove-colored-pieces-if-both-neighbors-are-the-same-color
[C++] & [Python] || O(N)|| Easy to understand
c-python-on-easy-to-understand-by-ritesh-nvez
C++\n\nclass Solution {\npublic:\n bool winnerOfGame(string colors) {\n int l = colors.length();\n int ca=0, cb=0;\n if(l<3) return fals
RiteshKhan
NORMAL
2022-07-03T16:29:29.138926+00:00
2022-07-03T16:34:01.810896+00:00
472
false
**C++**\n```\nclass Solution {\npublic:\n bool winnerOfGame(string colors) {\n int l = colors.length();\n int ca=0, cb=0;\n if(l<3) return false;\n for(int i=0; i<=l-3; ++i){\n if(colors[i]==colors[i+1] && colors[i+1]==colors[i+2]){\n if(colors[i] == \'A\') ca++;...
2
0
['C', 'Python']
0
remove-colored-pieces-if-both-neighbors-are-the-same-color
C++ (single pass)
c-single-pass-by-dakre-euyl
\n bool winnerOfGame(string colors) {\n int a = 0, b = 0, s = colors.size();\n for (int i = 0; i < s-2; ++i) {\n if (colors[i] == \'
dakre
NORMAL
2022-05-18T00:04:02.875344+00:00
2022-05-18T00:04:02.875389+00:00
154
false
```\n bool winnerOfGame(string colors) {\n int a = 0, b = 0, s = colors.size();\n for (int i = 0; i < s-2; ++i) {\n if (colors[i] == \'A\' && colors[i+1] == \'A\' && colors[i+2] == \'A\')\n a++;\n else if (colors[i] == \'B\' && colors[i+1] == \'B\' && colors[i+2] ==...
2
0
['C']
1
remove-colored-pieces-if-both-neighbors-are-the-same-color
Easy Python
easy-python-by-true-detective-pund
\nclass Solution:\n def winnerOfGame(self, colors: str) -> bool:\n def continuous_pieces(color):\n ans = cur = 0\n for c in colo
true-detective
NORMAL
2022-05-17T07:19:18.395318+00:00
2022-05-17T07:19:18.395349+00:00
159
false
```\nclass Solution:\n def winnerOfGame(self, colors: str) -> bool:\n def continuous_pieces(color):\n ans = cur = 0\n for c in colors:\n if c == color:\n cur += 1\n else:\n if cur > 2: \n ans += cu...
2
0
[]
0
remove-colored-pieces-if-both-neighbors-are-the-same-color
Python 3 | Greedy
python-3-greedy-by-jose-milanes-x512
When either of them makes a move, it does not affect the other person being able to make a move in any way, so it is enough to check how many moves they can mak
Jose-Milanes
NORMAL
2022-04-11T19:20:54.110226+00:00
2022-04-11T20:52:21.582244+00:00
164
false
When either of them makes a move, it does not affect the other person being able to make a move in any way, so it is enough to check how many moves they can make. \n```\nclass Solution:\n def winnerOfGame(self, colors: str) -> bool:\n a,b = 0, 0\n for i in range(1, len(colors) - 1):\n if col...
2
0
['Greedy']
0
remove-colored-pieces-if-both-neighbors-are-the-same-color
Simple C++ Solution || O(n)
simple-c-solution-on-by-purohit800-hnrk
\nclass Solution {\npublic:\n bool winnerOfGame(string colors) \n {\n int a=0,b=0;\n if(colors.size()<3)\n return false;\n
purohit800
NORMAL
2022-01-27T17:00:50.096137+00:00
2022-01-27T17:00:50.096182+00:00
110
false
```\nclass Solution {\npublic:\n bool winnerOfGame(string colors) \n {\n int a=0,b=0;\n if(colors.size()<3)\n return false;\n for(int i=0;i<colors.size()-2;i++)\n {\n if(colors[i]==\'A\' and colors[i+1]==\'A\' and colors[i+2]==\'A\')\n a++;\n ...
2
0
['C']
0
remove-colored-pieces-if-both-neighbors-are-the-same-color
Count Together A's and B's || Easy
count-together-as-and-bs-easy-by-ankursh-yvy0
```\n bool winnerOfGame(string colors) {\n \n int cntA = 1 , cntB = 1;\n int totA = 0 , totB = 0;\n string s = colors ;\n \n
ankursharma6084
NORMAL
2021-10-19T06:33:35.997999+00:00
2021-10-19T06:33:35.998049+00:00
86
false
```\n bool winnerOfGame(string colors) {\n \n int cntA = 1 , cntB = 1;\n int totA = 0 , totB = 0;\n string s = colors ;\n \n for(int i=1 ; i<colors.size() ; i++ )\n {\n if(s[i] == s[i-1])\n {\n if(s[i] == \'A\') cntA++;\n ...
2
0
[]
0
remove-colored-pieces-if-both-neighbors-are-the-same-color
Java Simple & Easy Approach
java-simple-easy-approach-by-rohitkumars-wpjf
\nclass Solution {\n public boolean winnerOfGame(String colors) {\n \n int len=colors.length();\n \n int acount=0;\n int b
rohitkumarsingh369
NORMAL
2021-10-18T06:25:29.662286+00:00
2021-10-18T06:27:30.109514+00:00
127
false
```\nclass Solution {\n public boolean winnerOfGame(String colors) {\n \n int len=colors.length();\n \n int acount=0;\n int bcount=0;\n \n for(int i=1;i<len-1;i++){\n if(colors.charAt(i-1)==colors.charAt(i) && colors.charAt(i+1)==colors.charAt(i) )\n ...
2
0
['Java']
1
remove-colored-pieces-if-both-neighbors-are-the-same-color
[Python3] greedy 5-line
python3-greedy-5-line-by-ye15-aqul
\n\nclass Solution:\n def winnerOfGame(self, colors: str) -> bool:\n diff = 0 \n for k, grp in groupby(colors): \n if k == "A": diff
ye15
NORMAL
2021-10-16T16:01:01.512243+00:00
2021-10-16T16:01:01.512276+00:00
247
false
\n```\nclass Solution:\n def winnerOfGame(self, colors: str) -> bool:\n diff = 0 \n for k, grp in groupby(colors): \n if k == "A": diff += max(0, len(list(grp)) - 2)\n else: diff -= max(0, len(list(grp)) - 2)\n return diff > 0 \n```
2
1
['Python3']
0
remove-colored-pieces-if-both-neighbors-are-the-same-color
[Java] - Easy, Compare(Count(AAA,BBB))
java-easy-comparecountaaabbb-by-pgthebig-fe6o
Idea\n-> Just count such pairs that have same neighbours!\n\nTime Complexity\n-> O(n)\n\n\nclass Solution {\n public boolean winnerOfGame(String str) {\n
pgthebigshot
NORMAL
2021-10-16T16:00:47.090380+00:00
2021-10-16T17:06:57.349928+00:00
180
false
**Idea**\n-> Just count such pairs that have same neighbours!\n\n**Time Complexity**\n-> O(n)\n\n```\nclass Solution {\n public boolean winnerOfGame(String str) {\n \n \tint i,n=str.length(),a=0,b=0;\n \tif(n<3)\n \t\treturn false;\n \tfor(i=1;i<n-1;i++)\n \t{\n \t\tif(str.charAt(i-1)==\'A\'...
2
1
['Java']
3
remove-colored-pieces-if-both-neighbors-are-the-same-color
java
java-by-aryaman123-r79j
IntuitionApproachComplexity Time complexity: Space complexity: Code
aryaman123
NORMAL
2025-03-31T17:10:03.628679+00:00
2025-03-31T17:10:03.628679+00:00
10
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code `...
1
0
['Java']
0
remove-colored-pieces-if-both-neighbors-are-the-same-color
eASy sOlutioN iN cPp.
easy-solution-in-cpp-by-xegl87zdze-fjmm
IntuitionApproachComplexity Time complexity:O(n) Space complexity:O(1) Code
xegl87zdzE
NORMAL
2025-03-20T15:32:29.574813+00:00
2025-03-20T15:32:29.574813+00:00
16
false
# Intuition <!-- 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, e.g. $$O(n)$$ --> ...
1
0
['Math', 'String', 'Greedy', 'Game Theory', 'C++']
0
remove-colored-pieces-if-both-neighbors-are-the-same-color
Simple & Intuitive O(n) Java Solution.
simple-intuitive-on-java-solution-by-wsh-8xo6
Intuition\nA grouping of AAA means that Alice can remove one color. So a grouping of AAAA would mean that Alice can remove 2 colors. A grouping of AAAAA would m
wsheppard9
NORMAL
2024-08-02T02:59:48.313594+00:00
2024-08-02T03:42:42.529525+00:00
8
false
# Intuition\nA grouping of AAA means that Alice can remove one color. So a grouping of AAAA would mean that Alice can remove 2 colors. A grouping of AAAAA would mean that Alice can remove 3 colors, and so on. Notice how that number keeps going up. We should keep track of it somehow! Whoever can remove the most colors, ...
1
0
['Java']
0
remove-colored-pieces-if-both-neighbors-are-the-same-color
Very Very Easy Java Solution
very-very-easy-java-solution-by-himanshu-s6te
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
Himanshu_Gahlot
NORMAL
2024-04-25T13:37:46.949428+00:00
2024-04-25T13:37:46.949464+00:00
1
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)$$ --...
1
0
['Java']
0
remove-colored-pieces-if-both-neighbors-are-the-same-color
GLBians cum here!
glbians-cum-here-by-xplicit_aman-9isd
Intuition\n1. You can remove an element if both its neighbours have the same colour as the current element, meaning all the A coloured elements between 2 A colo
xplicit_aman
NORMAL
2024-03-26T11:02:17.547837+00:00
2024-03-26T11:02:17.547871+00:00
6
false
# Intuition\n1. You can remove an element if both its neighbours have the same colour as the current element, meaning all the A coloured elements between 2 A coloured elements can be removed. (same for B)\n We use this information to calculate the total number of moves that can be made by Alice and Bob each.\n2. Ali...
1
0
['C++']
1
remove-colored-pieces-if-both-neighbors-are-the-same-color
Beats 95% | Very simple sol | Time - O(n) | Space - O(1)
beats-95-very-simple-sol-time-on-space-o-7ozk
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
Atharav_s
NORMAL
2024-02-24T06:12:37.274870+00:00
2024-02-24T06:12:37.274904+00:00
1
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)$$ --...
1
0
['C++']
0
remove-colored-pieces-if-both-neighbors-are-the-same-color
✅ C++ Easy Solution || Beats 96% of Users🔥🔥🔥
c-easy-solution-beats-96-of-users-by-gau-lmyp
\n# Code\n\nclass Solution {\npublic:\n bool winnerOfGame(string c) {\n int a=0;\n int b=0;\n for(int i=1;i<c.length()-1;i++){\n
Gaurav_Tomar
NORMAL
2024-01-05T03:56:16.726042+00:00
2024-01-05T03:56:16.726087+00:00
1
false
\n# Code\n```\nclass Solution {\npublic:\n bool winnerOfGame(string c) {\n int a=0;\n int b=0;\n for(int i=1;i<c.length()-1;i++){\n if(c[i+1]==c[i] && c[i-1]==c[i] && c[i]==\'A\'){\n a++;\n }\n else if(c[i+1]==c[i] && c[i-1]==c[i] && c[i]==\'B\'){\...
1
0
['Game Theory', 'C++']
0
remove-colored-pieces-if-both-neighbors-are-the-same-color
Python Solution using Sliding Window
python-solution-using-sliding-window-by-9cb1n
Code\n\nclass Solution:\n def winnerOfGame(self, colors: str) -> bool:\n a=0\n b=0\n s=""\n for i in range(len(colors)):\n
CEOSRICHARAN
NORMAL
2023-12-17T17:36:05.118294+00:00
2023-12-17T17:36:05.118327+00:00
13
false
# Code\n```\nclass Solution:\n def winnerOfGame(self, colors: str) -> bool:\n a=0\n b=0\n s=""\n for i in range(len(colors)):\n if(len(s)<3):\n s+=colors[i]\n else:\n s=s[1:]+colors[i]\n if(s==\'AAA\'):\n a+=1\n...
1
0
['Sliding Window', 'Python3']
0
remove-colored-pieces-if-both-neighbors-are-the-same-color
Python Solution: brief explain
python-solution-brief-explain-by-s117n-bk64
Intuition\n Describe your first thoughts on how to solve this problem. \nAccording to the rules:\n 1. Alice is only allowed to remove a piece colored \'A\' if b
s117n
NORMAL
2023-12-14T12:45:36.519398+00:00
2023-12-14T12:45:36.519427+00:00
2
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nAccording to the rules:\n `1. Alice is only allowed to remove a piece colored \'A\' if both its neighbors are also colored \'A\'. She is not allowed to remove pieces that are colored \'B\'.`\n`2. Bob is only allowed to remove a piece colo...
1
0
['Python']
0
remove-colored-pieces-if-both-neighbors-are-the-same-color
Intuitive Python Solution (Tc: O(n) Sc: O(1))
intuitive-python-solution-tc-on-sc-o1-by-vnee
Intuition\nSince the game is turn-based, whoever has the greatest number of matching sequences will win the game. Therefore, you only need to iterate through th
ccostello97
NORMAL
2023-12-05T01:47:29.454981+00:00
2023-12-05T01:47:29.455010+00:00
4
false
# Intuition\nSince the game is turn-based, whoever has the greatest number of matching sequences will win the game. Therefore, you only need to iterate through the loop once to determine who has the most matching sequences.\n\n# Approach\nWe iterate through the list once, starting from the second piece and stopping at ...
1
0
['Python']
0
remove-colored-pieces-if-both-neighbors-are-the-same-color
Fast way to solve the problem with O(n) time, O(1) space
fast-way-to-solve-the-problem-with-on-ti-mq4b
Approach\njust imagine of 2 pointer on the left i-1 and right i+1 and sum byte of character to be 195 or 198 and then count it if countA > countB alice should b
user9994g
NORMAL
2023-10-18T09:09:47.615003+00:00
2023-10-18T09:09:47.615024+00:00
3
false
# Approach\njust imagine of 2 pointer on the left i-1 and right i+1 and sum byte of character to be 195 or 198 and then count it if countA > countB alice should be won\n\n# Complexity\n- Time complexity: O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add your space complex...
1
0
['Go']
0
remove-colored-pieces-if-both-neighbors-are-the-same-color
Remove Colored Pieces if Both Neighbors are the Same Color
remove-colored-pieces-if-both-neighbors-84b1i
Intuition\nIf Alice has a higher possible turn count than Bob, Alice is the winner. A possible turn is counted if the same letter occurs consecutively 3 times o
minie2000
NORMAL
2023-10-06T05:44:36.052393+00:00
2023-10-06T05:44:36.052421+00:00
10
false
# Intuition\nIf Alice has a higher possible turn count than Bob, Alice is the winner. A possible turn is counted if the same letter occurs consecutively 3 times or more.\n\n# Approach\nI have declared some variables to check if the same letter occurs consecutively three times or more. If the consecutive count is 3 or g...
1
0
['C#']
0
detonate-the-maximum-bombs
[Python] Simple dfs, explained
python-simple-dfs-explained-by-dbabichev-9iy3
In fact, this is graph proglem, starting with bomb, we need to traverse all bombs we can detonate and so on. Problem constraints allow us to just use bruteforce
dbabichev
NORMAL
2021-12-11T16:01:58.852955+00:00
2021-12-11T16:01:58.852979+00:00
18,529
false
In fact, this is graph proglem, starting with bomb, we need to traverse all bombs we can detonate and so on. Problem constraints allow us to just use bruteforce.\n\n#### Complexity\nTime complexity is `O(n^3)`, because we start from `n` bombs and we can have upto `O(n^2)` edges.\n\n#### Code\n```python\nclass Solution:...
100
4
['Depth-First Search']
18
detonate-the-maximum-bombs
BFS (or DFS)
bfs-or-dfs-by-votrubac-2zkb
We can represent bombs using a directed graph - when a bomb i can detonate bomb j, there is an edge from i to j. Note that the opposite may not be true.\n\nWe g
votrubac
NORMAL
2021-12-11T16:02:54.141479+00:00
2021-12-11T18:50:39.108722+00:00
20,784
false
We can represent bombs using a *directed* graph - when a bomb `i` can detonate bomb `j`, there is an edge from `i` to `j`. Note that the opposite may not be true.\n\nWe generate this graph (`al`), and, starting from each node, we run BFS (or DFS) and find out how many nodes we can reach.\n\n#### DFS\nUsing a bitset boo...
70
1
[]
18
detonate-the-maximum-bombs
C++ || EASY TO UNDERSTAND || using basic DFS
c-easy-to-understand-using-basic-dfs-by-0lvlj
\n\nclass Solution {\n#define ll long long int\n public:\n void dfs(vector<vector<int>> &graph,vector<bool> &visited,int &c,int &i)\n {\n visite
aarindey
NORMAL
2021-12-12T01:43:05.717149+00:00
2021-12-12T01:43:05.717204+00:00
11,812
false
```\n\nclass Solution {\n#define ll long long int\n public:\n void dfs(vector<vector<int>> &graph,vector<bool> &visited,int &c,int &i)\n {\n visited[i]=true;\n c++;\n for(int j=0;j<graph[i].size();j++)\n {\n if(!visited[graph[i][j]])\n dfs(graph,visited,c,grap...
68
1
['Depth-First Search', 'Graph']
9
detonate-the-maximum-bombs
Neat Code Java DFS
neat-code-java-dfs-by-vegetablebirds-14a7
```\n public int maximumDetonation(int[][] bombs) {\n int n = bombs.length, ans = 0;\n for (int i = 0; i < n; i++) {\n ans = Math.max(a
Vegetablebirds
NORMAL
2021-12-11T23:01:27.171543+00:00
2023-07-18T13:01:26.831635+00:00
10,137
false
```\n public int maximumDetonation(int[][] bombs) {\n int n = bombs.length, ans = 0;\n for (int i = 0; i < n; i++) {\n ans = Math.max(ans, dfs(i, new boolean[n], bombs));\n }\n return ans;\n }\n\n private int dfs(int idx, boolean[] v, int[][] bombs) {\n int count = 1;...
51
0
['Depth-First Search', 'Java']
12
detonate-the-maximum-bombs
Wrong test cases?
wrong-test-cases-by-trickster-oawr
For the input\n\n[[54,95,4],[99,46,3],[29,21,3],[96,72,8],[49,43,3],[11,20,3],[2,57,1],[69,51,7],[97,1,10],[85,45,2],[38,47,1],[83,75,3],[65,59,3],[33,4,1],[32,
trickster_
NORMAL
2021-12-11T16:08:42.263280+00:00
2021-12-11T16:08:42.263308+00:00
3,747
false
For the input\n```\n[[54,95,4],[99,46,3],[29,21,3],[96,72,8],[49,43,3],[11,20,3],[2,57,1],[69,51,7],[97,1,10],[85,45,2],[38,47,1],[83,75,3],[65,59,3],[33,4,1],[32,10,2],[20,97,8],[35,37,3]]\n```\nConsider the points at index 7 and 12\n69, 51, 7\n65, 59, 3\n\nGraphing them,\n![image](https://assets.leetcode.com/users/im...
43
5
[]
14
detonate-the-maximum-bombs
Java | BFS & DFS | With Comments | Easy
java-bfs-dfs-with-comments-easy-by-omars-dyru
The main idea here is to take each bomb and check the number of bombs in its range. \n\nBFS: \n\n\n public int maximumDetonation(int[][] bombs) {\n in
omars_leet
NORMAL
2022-03-30T13:52:00.398685+00:00
2022-04-02T21:18:36.299163+00:00
4,978
false
The main idea here is to take each bomb and check the number of bombs in its range. \n\n**BFS**: \n\n```\n public int maximumDetonation(int[][] bombs) {\n int max = 0;\n //iterate through each bomb and keep track of max\n for(int i = 0; i<bombs.length; i++){\n max = Math.max(max, getM...
29
0
['Depth-First Search', 'Breadth-First Search', 'Java']
4
detonate-the-maximum-bombs
Intuition Explained | Can simple DFS be further optimized?
intuition-explained-can-simple-dfs-be-fu-dcl3
NOTE: One Bomb can detonate other if and only if the other bomb lies within the area covered by the Bomb.\n\n\n\n\n\n\n\n\nclass Solution {\npublic:\n double
27aryanraj
NORMAL
2021-12-13T15:20:49.734223+00:00
2023-04-14T20:24:07.933749+00:00
2,317
false
**NOTE: One Bomb can detonate other if and only if the other bomb lies within the area covered by the Bomb.**\n\n![image](https://assets.leetcode.com/users/images/f3110632-4cc7-4461-917b-489c8bc8b2e9_1639405880.1813633.png)\n\n![image](https://assets.leetcode.com/users/images/094a740b-d884-49af-be24-12b298167b9c_163940...
28
0
['Depth-First Search', 'Graph', 'C++']
6
detonate-the-maximum-bombs
Intuition Explained || Graph, DFS based approach || C++ Clean Code
intuition-explained-graph-dfs-based-appr-ld74
Intuition :\n\n Idea here is to first create a graph, such that there is a edge between two bombs i and j,\n\n\t if when we detonate ith bomb, then jth bomb lie
i_quasar
NORMAL
2021-12-31T12:36:31.680063+00:00
2021-12-31T12:38:17.130913+00:00
2,421
false
**Intuition :**\n\n* Idea here is to first create a graph, such that there is a edge between two bombs `i` and `j`,\n\n\t* if when we detonate `ith` bomb, then `jth bomb` lies within its **proximity** (as given in problem stmt),\n\t* i.e iff **`distance between centers <= radius of ith bomb`**\n* To create graph, simpl...
22
0
['Math', 'Depth-First Search', 'Graph', 'Geometry']
3
detonate-the-maximum-bombs
Python BFS/DFS and why union-find is not the solution.
python-bfsdfs-and-why-union-find-is-not-mlvrw
Intuition\n Describe your first thoughts on how to solve this problem. \nMy initial intuition was union-find because it seems to find out the maximum RANK of th
lhy332
NORMAL
2022-11-26T21:55:49.325047+00:00
2022-11-26T21:55:49.325087+00:00
2,600
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nMy initial intuition was union-find because it seems to find out the maximum RANK of the largest group. After a few trial and error, I figured out that union-find is only for undirected graph. So, I decided to solve this problem with typi...
17
0
['Python3']
5
detonate-the-maximum-bombs
A similar question asked in my google phone interview. (read for more)
a-similar-question-asked-in-my-google-ph-8xpl
Solving this one saved me in my google phone interview. I\'ve put the details of the interview here:\nhttps://freezefrancis.medium.com/google-phone-interview-ex
freeze_francis
NORMAL
2022-10-13T10:50:27.460569+00:00
2022-10-13T10:50:27.460617+00:00
2,073
false
Solving this one saved me in my google phone interview. I\'ve put the details of the interview here:\nhttps://freezefrancis.medium.com/google-phone-interview-experience-a75c2d0e0080
17
0
['Breadth-First Search']
2
detonate-the-maximum-bombs
C++ | Simple BFS [ Faster than 100% ]
c-simple-bfs-faster-than-100-by-priyansh-tukp
CODE\n\nclass Solution {\npublic:\n \n int maximumDetonation(vector<vector<int>>& bombs) {\n ios::sync_with_stdio(false); cin.tie(NULL);\n\t\t\n
Priyansh_34
NORMAL
2021-12-11T19:35:31.374371+00:00
2021-12-11T19:35:31.374403+00:00
2,951
false
**CODE**\n```\nclass Solution {\npublic:\n \n int maximumDetonation(vector<vector<int>>& bombs) {\n ios::sync_with_stdio(false); cin.tie(NULL);\n\t\t\n const int n = bombs.size();\n\t\t\n vector<vector<int>>v(n);\n \n for(int i = 0; i < n; i++) {\n long long r = (long...
17
0
['Breadth-First Search']
2
detonate-the-maximum-bombs
C++ | DFS | Intuition and Code Explained
c-dfs-intuition-and-code-explained-by-ni-wjlu
Explanation\nThe intuition is to keep checking the bombs we can detonate if we start from the i-th bomb. The conditions for detonation are:\n1. The bomb shouldn
nidhiii_
NORMAL
2022-02-25T17:15:29.665537+00:00
2022-02-25T17:16:54.893970+00:00
1,967
false
### Explanation\nThe intuition is to keep checking the bombs we can detonate if we start from the i-th bomb. The conditions for detonation are:\n1. The bomb shouldn\'t be visited before (Except if that is the starting point).\n2. The distance between two points should be less than radius of the previous bomb, i.e, (x1-...
12
1
['Depth-First Search', 'C++']
2
detonate-the-maximum-bombs
✅ Explained - Simple and Clear Python3 Code✅
explained-simple-and-clear-python3-code-44c7q
Intuition\nThe given problem involves determining the maximum number of bombs that can be detonated if you are allowed to detonate only one bomb. The bombs are
moazmar
NORMAL
2023-06-10T00:35:33.783952+00:00
2023-06-10T00:35:33.783990+00:00
1,264
false
# Intuition\nThe given problem involves determining the maximum number of bombs that can be detonated if you are allowed to detonate only one bomb. The bombs are represented as a list of 2D integer arrays, where each array contains the X-coordinate, Y-coordinate, and radius of a bomb.\n\n\n# Approach\nTo solve this pro...
11
0
['Python3']
0
detonate-the-maximum-bombs
Easy C++ Solution
easy-c-solution-by-am14-3t3t
Intuition\n Describe your first thoughts on how to solve this problem. \nIn this problem, we are given a list of bombs represented by their coordinates (x and y
am14
NORMAL
2023-06-02T05:01:59.075880+00:00
2023-06-02T10:56:54.906441+00:00
4,212
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nIn this problem, we are given a list of bombs represented by their coordinates (x and y) and the explosion radius. The task is to determine the maximum number of bombs that can be detonated by starting with any bomb and detonating all oth...
11
0
['Breadth-First Search', 'C++']
2
detonate-the-maximum-bombs
Python | BFS / DFS, start with every point | explanation
python-bfs-dfs-start-with-every-point-ex-b7vz
If the distance between bombs[i] and bombs[j] is smaller than or equal to the radius of bombs[i], then we can detonate bombs[j] with bombs[i]. This relationship
zoo30215
NORMAL
2021-12-11T16:01:27.830540+00:00
2021-12-12T01:40:26.918247+00:00
1,993
false
If the distance between `bombs[i]` and `bombs[j]` is smaller than or equal to the `radius` of `bombs[i]`, then we can detonate `bombs[j]` with `bombs[i]`. This relationship can be viewed as an edge `i -> j`.\n\nWe can enumerate all bomb pairs to construct a directed graph with these detonation relationships. And then w...
11
1
[]
2
detonate-the-maximum-bombs
Python Elegant & Short | DFS
python-elegant-short-dfs-by-kyrylo-ktl-8vqb
Complexity\n- Time complexity: O(n^{2})\n- Space complexity: O(n^{2})\n\n# Code\n\nclass Solution:\n def maximumDetonation(self, bombs: List[List[int]]) -> i
Kyrylo-Ktl
NORMAL
2023-06-02T10:42:24.838031+00:00
2023-06-02T10:45:15.799515+00:00
2,287
false
# Complexity\n- Time complexity: $$O(n^{2})$$\n- Space complexity: $$O(n^{2})$$\n\n# Code\n```\nclass Solution:\n def maximumDetonation(self, bombs: List[List[int]]) -> int:\n def dfs(node: int, visited: set = None) -> set:\n if visited is None:\n visited = {node}\n\n for ...
8
0
['Depth-First Search', 'Graph', 'Python', 'Python3']
1
detonate-the-maximum-bombs
Why is this wrong? Python Union Find Solution passes 111/160
why-is-this-wrong-python-union-find-solu-cfjg
\nclass UnionF:\n def __init__(self, n):\n self.rank = [1 for _ in range(n)]\n self.par = [i for i in range(n)]\n self.n = n\n \n
rsaxena123
NORMAL
2022-09-16T00:28:41.730641+00:00
2022-09-16T15:19:53.244866+00:00
1,276
false
```\nclass UnionF:\n def __init__(self, n):\n self.rank = [1 for _ in range(n)]\n self.par = [i for i in range(n)]\n self.n = n\n \n def find(self, n):\n # Path Compression + Finds root\n while n != self.par[n]:\n self.par[n] = self.par[self.par[n]]\n ...
8
0
['Union Find', 'Python']
7
detonate-the-maximum-bombs
C++ || DFS || Connected Component Count
c-dfs-connected-component-count-by-bsh24-qqxz
\n\t\n\t// Function to calculate dis^2 between two points\n long long dis(int x1, int y1, int x2, int y2)\n {\n return pow(x2-x1,2) + pow(y2-y1,2);
bsh2409
NORMAL
2022-08-17T19:27:21.218174+00:00
2022-08-17T19:27:51.376845+00:00
1,448
false
\n\t\n\t// Function to calculate dis^2 between two points\n long long dis(int x1, int y1, int x2, int y2)\n {\n return pow(x2-x1,2) + pow(y2-y1,2);\n }\n // DFS connected components count\n void dfs(int node, vector<vector<int>> &adj, vector<bool>& visited , int &count)\n {\n if(visited[...
8
0
['Depth-First Search', 'C', 'C++']
1
detonate-the-maximum-bombs
need help with union find approach || cpp || uninon-find
need-help-with-union-find-approach-cpp-u-1yya
\nclass Solution {\npublic:\n long dist(long a,long b,long x,long y){\n return sqrt(pow((a-x+0ll),2.0) + pow((b-y+0ll),2.0));\n }\n // static b
meayush912
NORMAL
2021-12-11T16:09:51.985115+00:00
2021-12-11T16:09:51.985158+00:00
769
false
```\nclass Solution {\npublic:\n long dist(long a,long b,long x,long y){\n return sqrt(pow((a-x+0ll),2.0) + pow((b-y+0ll),2.0));\n }\n // static bool cmp(vector<int> &a,vector<int> &b){\n // return a[2]>b[2];\n // }\n int getp_(vector<int> &p,int x){\n if(p[x]==x)return x;\n ...
8
0
[]
3
detonate-the-maximum-bombs
Java | DFS | Beats > 70% | Clean code
java-dfs-beats-70-clean-code-by-judgemen-2h48
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
judgementdey
NORMAL
2023-06-02T06:20:50.509832+00:00
2023-06-02T06:35:02.510602+00:00
1,627
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: $$O(n^2)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(n^2)$$\n<!-- Add your space complexity ...
7
0
['Math', 'Depth-First Search', 'Graph', 'Geometry', 'Java']
0
detonate-the-maximum-bombs
Java Solution for Detonate the Maximum Bombs Problem
java-solution-for-detonate-the-maximum-b-0hal
Intuition\n Describe your first thoughts on how to solve this problem. \nThe given problem involves finding the maximum number of bombs that can be detonated by
Aman_Raj_Sinha
NORMAL
2023-06-02T02:54:48.346610+00:00
2023-06-02T02:54:48.346652+00:00
2,618
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe given problem involves finding the maximum number of bombs that can be detonated by choosing a single bomb. To solve this, we can represent the bombs as a graph, where each bomb is a node and there is an edge between two bombs if one ...
7
0
['Java']
0
detonate-the-maximum-bombs
JAVA Solution | DFS Traversal
java-solution-dfs-traversal-by-piyushja1-uu1a
We just need to find out the maximum no. of connected components i.e. bombs\n\nclass Solution {\n \n public int maximumDetonation(int[][] bombs) {\n
piyushja1n
NORMAL
2021-12-12T06:52:14.657178+00:00
2021-12-12T06:52:14.657209+00:00
948
false
We just need to find out the maximum no. of connected components i.e. bombs\n```\nclass Solution {\n \n public int maximumDetonation(int[][] bombs) {\n \n List<List<Integer>> adj = new ArrayList<>();\n int n = bombs.length;\n boolean[] vis = new boolean[n];\n int max=1;\n ...
7
0
[]
1
detonate-the-maximum-bombs
C++ || Using BFS
c-using-bfs-by-rajdeep_nagar-3kqo
As its mentioned in first Solved example that for any two Bombs A-B , B will blast due to effect of A if and only if Centre of B lies inside or on the circumfer
Rajdeep_Nagar
NORMAL
2021-12-11T17:40:26.398534+00:00
2021-12-12T04:10:37.823568+00:00
747
false
As its mentioned in first Solved example that for any two Bombs A-B , B will blast due to effect of A if and only if Centre of B lies inside or on the circumference of A => radius of Bomb A (r1) >= Distance between their centers.\n\nSo We start bfs from Bomb i and including all those bombs in effect of A that satisfie...
7
0
['Breadth-First Search']
4
detonate-the-maximum-bombs
[C++] | BFS | Beginner - Friendly | O(N^3)
c-bfs-beginner-friendly-on3-by-doraemon-8ld0
\nclass Solution {\npublic:\n long long int cnt;\n long long get(vector<vector<int> > &ar, int i, int n){\n vector<int> vis(n,0);\n queue<ve
Doraemon_
NORMAL
2021-12-11T16:15:17.047325+00:00
2022-02-13T06:47:02.501975+00:00
606
false
```\nclass Solution {\npublic:\n long long int cnt;\n long long get(vector<vector<int> > &ar, int i, int n){\n vector<int> vis(n,0);\n queue<vector<int> > q;\n \n vis[i] = 1;\n cnt++;\n \n q.push(ar[i]);\n while(!q.empty()){\n auto cur = q.front()...
7
0
['Breadth-First Search']
1
detonate-the-maximum-bombs
✅ [Python] DFS || Explained || Easy to Understand || Faster 100%
python-dfs-explained-easy-to-understand-du1s6
First Construct a graph, each bomb as a vertex, if b is within the explosion radius of a, then there is a directed edge from a to b. Construct the adjacency mat
linfq
NORMAL
2021-12-11T16:11:00.505249+00:00
2021-12-11T16:53:56.740805+00:00
1,316
false
* First Construct a graph, each bomb as a vertex, if b is within the explosion radius of a, then there is a directed edge from a to b. Construct the adjacency matrix of the Directed graph.\n\t* Note that this is a directed graph, so we cannot use UnionFindSet.\n* Traverse each bomb as the starting point and count the n...
7
0
['Python']
4
detonate-the-maximum-bombs
Understandable Explanation | Graph visualized
understandable-explanation-graph-visuali-9wv0
Intuition\n Describe your first thoughts on how to solve this problem. \nHow can we visiualize the problem?\nWhich data structure should we use ?\n\nThe key to
Anuj_vanced
NORMAL
2023-06-02T14:00:35.772423+00:00
2023-06-02T14:00:35.772463+00:00
479
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nHow can we visiualize the problem?\nWhich data structure should we use ?\n\nThe key to the solution is just visualization, if you crack that this question is a piece of cake.\n\nThink of a single detonation some other bombs and those othe...
6
0
['Graph', 'C++']
0
detonate-the-maximum-bombs
🏆C++ || Easy DFS
c-easy-dfs-by-chiikuu-4g9b
Code\n\nclass Solution\n{\npublic:\n int dfs(vector<int> &v, vector<vector<int>> &b, int i)\n {\n v[i] = 1;\n int x = b[i][0], y = b[i][1];\
CHIIKUU
NORMAL
2023-06-02T07:57:24.164869+00:00
2023-06-02T07:57:24.164913+00:00
1,579
false
# Code\n```\nclass Solution\n{\npublic:\n int dfs(vector<int> &v, vector<vector<int>> &b, int i)\n {\n v[i] = 1;\n int x = b[i][0], y = b[i][1];\n int r = b[i][2];\n int j = 0;\n int ans = 1;\n for (int j = 0; j < b.size(); j++)\n {\n long long g = abs(x...
6
0
['C++']
2
detonate-the-maximum-bombs
C++ | Graphs + Math | Explained
c-graphs-math-explained-by-jk20-68n5
Approach :\n\n Since the constraints are low i.e we are given only 100 bombs at max, we can, for each bomb we can find if we detonate this bomb, how many other
jk20
NORMAL
2022-03-18T04:01:25.027530+00:00
2022-03-18T04:01:25.027573+00:00
894
false
**Approach :**\n\n* Since the constraints are low i.e we are given only 100 bombs at max, we can, for each bomb we can find if we detonate this bomb, how many other bombs it can detonate. \n\n* Now we can represent bombs as nodes in graph. \n* Also we need to revisit our High School Geometry, to check if a point lies o...
6
0
['Depth-First Search', 'Breadth-First Search', 'Graph', 'Recursion', 'C', 'C++']
0