title stringlengths 1 100 | titleSlug stringlengths 3 77 | Java int64 0 1 | Python3 int64 1 1 | content stringlengths 28 44.4k | voteCount int64 0 3.67k | question_content stringlengths 65 5k | question_hints stringclasses 970
values |
|---|---|---|---|---|---|---|---|
793: Beats 96.08%, Solution with step by step explanation | preimage-size-of-factorial-zeroes-function | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nStep 1: Calculate trailing zeros for a given number\nTo understand how many trailing zeros a number\'s factorial has, we need to count the number of times 5 appears as a factor in all numbers leading up to it.\n\nIf n is 0, ... | 0 | Let `f(x)` be the number of zeroes at the end of `x!`. Recall that `x! = 1 * 2 * 3 * ... * x` and by convention, `0! = 1`.
* For example, `f(3) = 0` because `3! = 6` has no zeroes at the end, while `f(11) = 2` because `11! = 39916800` has two zeroes at the end.
Given an integer `k`, return the number of non-negativ... | Think of the L and R's as people on a horizontal line, where X is a space. The people can't cross each other, and also you can't go from XRX to RXX. |
793: Beats 96.08%, Solution with step by step explanation | preimage-size-of-factorial-zeroes-function | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nStep 1: Calculate trailing zeros for a given number\nTo understand how many trailing zeros a number\'s factorial has, we need to count the number of times 5 appears as a factor in all numbers leading up to it.\n\nIf n is 0, ... | 0 | Sometimes people repeat letters to represent extra feeling. For example:
* `"hello " -> "heeellooo "`
* `"hi " -> "hiiii "`
In these strings like `"heeellooo "`, we have groups of adjacent letters that are all the same: `"h "`, `"eee "`, `"ll "`, `"ooo "`.
You are given a string `s` and an array of query strings... | null |
math + binary search | preimage-size-of-factorial-zeroes-function | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe key here is simply knowing a mathematical formula for the numer of trailing zeroes of a factorial. It\'s well known from math contests that this is just k = floor(n/5) + floor(n/25) + floor(n/125) + ....\n\nImportantly, this is monoto... | 0 | Let `f(x)` be the number of zeroes at the end of `x!`. Recall that `x! = 1 * 2 * 3 * ... * x` and by convention, `0! = 1`.
* For example, `f(3) = 0` because `3! = 6` has no zeroes at the end, while `f(11) = 2` because `11! = 39916800` has two zeroes at the end.
Given an integer `k`, return the number of non-negativ... | Think of the L and R's as people on a horizontal line, where X is a space. The people can't cross each other, and also you can't go from XRX to RXX. |
math + binary search | preimage-size-of-factorial-zeroes-function | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe key here is simply knowing a mathematical formula for the numer of trailing zeroes of a factorial. It\'s well known from math contests that this is just k = floor(n/5) + floor(n/25) + floor(n/125) + ....\n\nImportantly, this is monoto... | 0 | Sometimes people repeat letters to represent extra feeling. For example:
* `"hello " -> "heeellooo "`
* `"hi " -> "hiiii "`
In these strings like `"heeellooo "`, we have groups of adjacent letters that are all the same: `"h "`, `"eee "`, `"ll "`, `"ooo "`.
You are given a string `s` and an array of query strings... | null |
Python Easy to Understand solution. Binary Search step by step explanation | preimage-size-of-factorial-zeroes-function | 0 | 1 | - Number of zeroes for a given number n = min(n//5, n//2)+n//10\n- n//2 gives the number of 2 factors and n//5 gives the number of 5 factors. \n- n//5 isn\'t accurance. Taking 1.2.3......125, we get 5,10,15,...125 and 25, 50, 75, 100, 125 and 125\n- The total isn\'t n//5. It is n//5 + n//25 + n//125\n- We also don\'t n... | 0 | Let `f(x)` be the number of zeroes at the end of `x!`. Recall that `x! = 1 * 2 * 3 * ... * x` and by convention, `0! = 1`.
* For example, `f(3) = 0` because `3! = 6` has no zeroes at the end, while `f(11) = 2` because `11! = 39916800` has two zeroes at the end.
Given an integer `k`, return the number of non-negativ... | Think of the L and R's as people on a horizontal line, where X is a space. The people can't cross each other, and also you can't go from XRX to RXX. |
Python Easy to Understand solution. Binary Search step by step explanation | preimage-size-of-factorial-zeroes-function | 0 | 1 | - Number of zeroes for a given number n = min(n//5, n//2)+n//10\n- n//2 gives the number of 2 factors and n//5 gives the number of 5 factors. \n- n//5 isn\'t accurance. Taking 1.2.3......125, we get 5,10,15,...125 and 25, 50, 75, 100, 125 and 125\n- The total isn\'t n//5. It is n//5 + n//25 + n//125\n- We also don\'t n... | 0 | Sometimes people repeat letters to represent extra feeling. For example:
* `"hello " -> "heeellooo "`
* `"hi " -> "hiiii "`
In these strings like `"heeellooo "`, we have groups of adjacent letters that are all the same: `"h "`, `"eee "`, `"ll "`, `"ooo "`.
You are given a string `s` and an array of query strings... | null |
Python O(log(n)^2) - Binary Search using problem 172 | preimage-size-of-factorial-zeroes-function | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n- Note: it might be helpful to complete https://leetcode.com/problems/factorial-trailing-zeroes/description/ beforehand to get a nice helper function\n- To recap\n - The number of 0\'s following a factorial come from the number of 2\'s... | 0 | Let `f(x)` be the number of zeroes at the end of `x!`. Recall that `x! = 1 * 2 * 3 * ... * x` and by convention, `0! = 1`.
* For example, `f(3) = 0` because `3! = 6` has no zeroes at the end, while `f(11) = 2` because `11! = 39916800` has two zeroes at the end.
Given an integer `k`, return the number of non-negativ... | Think of the L and R's as people on a horizontal line, where X is a space. The people can't cross each other, and also you can't go from XRX to RXX. |
Python O(log(n)^2) - Binary Search using problem 172 | preimage-size-of-factorial-zeroes-function | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n- Note: it might be helpful to complete https://leetcode.com/problems/factorial-trailing-zeroes/description/ beforehand to get a nice helper function\n- To recap\n - The number of 0\'s following a factorial come from the number of 2\'s... | 0 | Sometimes people repeat letters to represent extra feeling. For example:
* `"hello " -> "heeellooo "`
* `"hi " -> "hiiii "`
In these strings like `"heeellooo "`, we have groups of adjacent letters that are all the same: `"h "`, `"eee "`, `"ll "`, `"ooo "`.
You are given a string `s` and an array of query strings... | null |
Solution using Binary search | preimage-size-of-factorial-zeroes-function | 0 | 1 | # Intuition\nIt is easy to calcuate f(x) given an integer x. The problem changes to find the left bound and the right bound of $f(x) = k$ which could be solved by binary search. \n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n$$O(n)$$ $$n = $$ range of unsigned long\n\n- Spa... | 0 | Let `f(x)` be the number of zeroes at the end of `x!`. Recall that `x! = 1 * 2 * 3 * ... * x` and by convention, `0! = 1`.
* For example, `f(3) = 0` because `3! = 6` has no zeroes at the end, while `f(11) = 2` because `11! = 39916800` has two zeroes at the end.
Given an integer `k`, return the number of non-negativ... | Think of the L and R's as people on a horizontal line, where X is a space. The people can't cross each other, and also you can't go from XRX to RXX. |
Solution using Binary search | preimage-size-of-factorial-zeroes-function | 0 | 1 | # Intuition\nIt is easy to calcuate f(x) given an integer x. The problem changes to find the left bound and the right bound of $f(x) = k$ which could be solved by binary search. \n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n$$O(n)$$ $$n = $$ range of unsigned long\n\n- Spa... | 0 | Sometimes people repeat letters to represent extra feeling. For example:
* `"hello " -> "heeellooo "`
* `"hi " -> "hiiii "`
In these strings like `"heeellooo "`, we have groups of adjacent letters that are all the same: `"h "`, `"eee "`, `"ll "`, `"ooo "`.
You are given a string `s` and an array of query strings... | null |
Modular and Extensible Python Solution - Beats 90% | valid-tic-tac-toe-state | 0 | 1 | O(1) time complexity, O(1) space complesity\n\n```\nclass Solution:\n def validTicTacToe(self, board: List[str]) -> bool:\n n = 3\n rows = [0] * n\n cols = [0] * n\n diag = antidiag = balance = 0\n \n def win(v):\n if v in rows or v in cols or v in [diag, antidiag... | 4 | Given a Tic-Tac-Toe board as a string array `board`, return `true` if and only if it is possible to reach this board position during the course of a valid tic-tac-toe game.
The board is a `3 x 3` array that consists of characters `' '`, `'X'`, and `'O'`. The `' '` character represents an empty square.
Here are the ru... | Use either Dijkstra's, or binary search for the best time T for which you can reach the end if you only step on squares at most T. |
Modular and Extensible Python Solution - Beats 90% | valid-tic-tac-toe-state | 0 | 1 | O(1) time complexity, O(1) space complesity\n\n```\nclass Solution:\n def validTicTacToe(self, board: List[str]) -> bool:\n n = 3\n rows = [0] * n\n cols = [0] * n\n diag = antidiag = balance = 0\n \n def win(v):\n if v in rows or v in cols or v in [diag, antidiag... | 4 | You are given an array of integers `nums` represents the numbers written on a chalkboard.
Alice and Bob take turns erasing exactly one number from the chalkboard, with Alice starting first. If erasing a number causes the bitwise XOR of all the elements of the chalkboard to become `0`, then that player loses. The bitwi... | null |
Solution | valid-tic-tac-toe-state | 1 | 1 | ```C++ []\nclass Solution {\npublic:\n bool validTicTacToe(vector<string>& board) \n {\n int turn = 0, diag = 0, adg = 0, i, j;\n bool xwin = false, owin = false;\n vector<int> row(3), col(3);\n for(i = 0; i < 3; i ++)\n {\n for(j = 0; j < 3; j ++)\n {\n ... | 2 | Given a Tic-Tac-Toe board as a string array `board`, return `true` if and only if it is possible to reach this board position during the course of a valid tic-tac-toe game.
The board is a `3 x 3` array that consists of characters `' '`, `'X'`, and `'O'`. The `' '` character represents an empty square.
Here are the ru... | Use either Dijkstra's, or binary search for the best time T for which you can reach the end if you only step on squares at most T. |
Solution | valid-tic-tac-toe-state | 1 | 1 | ```C++ []\nclass Solution {\npublic:\n bool validTicTacToe(vector<string>& board) \n {\n int turn = 0, diag = 0, adg = 0, i, j;\n bool xwin = false, owin = false;\n vector<int> row(3), col(3);\n for(i = 0; i < 3; i ++)\n {\n for(j = 0; j < 3; j ++)\n {\n ... | 2 | You are given an array of integers `nums` represents the numbers written on a chalkboard.
Alice and Bob take turns erasing exactly one number from the chalkboard, with Alice starting first. If erasing a number causes the bitwise XOR of all the elements of the chalkboard to become `0`, then that player loses. The bitwi... | null |
Python3 || int array, 7 lines, w/ explanation || T/M: 98%/ 49% | valid-tic-tac-toe-state | 0 | 1 | ```\nclass Solution:\n def validTicTacToe(self, board: List[str]) -> bool:\n # The two criteria for a valid board are:\n # 1) num of Xs - num of Os is 0 or 1\n # 2) X is not a winner i... | 7 | Given a Tic-Tac-Toe board as a string array `board`, return `true` if and only if it is possible to reach this board position during the course of a valid tic-tac-toe game.
The board is a `3 x 3` array that consists of characters `' '`, `'X'`, and `'O'`. The `' '` character represents an empty square.
Here are the ru... | Use either Dijkstra's, or binary search for the best time T for which you can reach the end if you only step on squares at most T. |
Python3 || int array, 7 lines, w/ explanation || T/M: 98%/ 49% | valid-tic-tac-toe-state | 0 | 1 | ```\nclass Solution:\n def validTicTacToe(self, board: List[str]) -> bool:\n # The two criteria for a valid board are:\n # 1) num of Xs - num of Os is 0 or 1\n # 2) X is not a winner i... | 7 | You are given an array of integers `nums` represents the numbers written on a chalkboard.
Alice and Bob take turns erasing exactly one number from the chalkboard, with Alice starting first. If erasing a number causes the bitwise XOR of all the elements of the chalkboard to become `0`, then that player loses. The bitwi... | null |
concise code beat 100% python solution with explanation | valid-tic-tac-toe-state | 0 | 1 | There is only four situation that Tic-Tac-Toe is invalid:\n1. two players are not taking turns making move\n2. "O" player makes move before "X" player\n3. "X" player wins but "O" player continues to make move\n4. "O" player wins but "X" player continues to make move\n\n```\nclass Solution(object):\n def validTicTacT... | 12 | Given a Tic-Tac-Toe board as a string array `board`, return `true` if and only if it is possible to reach this board position during the course of a valid tic-tac-toe game.
The board is a `3 x 3` array that consists of characters `' '`, `'X'`, and `'O'`. The `' '` character represents an empty square.
Here are the ru... | Use either Dijkstra's, or binary search for the best time T for which you can reach the end if you only step on squares at most T. |
concise code beat 100% python solution with explanation | valid-tic-tac-toe-state | 0 | 1 | There is only four situation that Tic-Tac-Toe is invalid:\n1. two players are not taking turns making move\n2. "O" player makes move before "X" player\n3. "X" player wins but "O" player continues to make move\n4. "O" player wins but "X" player continues to make move\n\n```\nclass Solution(object):\n def validTicTacT... | 12 | You are given an array of integers `nums` represents the numbers written on a chalkboard.
Alice and Bob take turns erasing exactly one number from the chalkboard, with Alice starting first. If erasing a number causes the bitwise XOR of all the elements of the chalkboard to become `0`, then that player loses. The bitwi... | null |
Python | Straightforward Solution | valid-tic-tac-toe-state | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\njust validate against the rules\n\n# Code\n```\nclass Solution:\n def validTicTacToe(self, board: List[str]) -> bool:\n n = len(board)\n cntx = cnto = 0\n rows = [0] * n\n cols = [0] * n\n diagonals... | 0 | Given a Tic-Tac-Toe board as a string array `board`, return `true` if and only if it is possible to reach this board position during the course of a valid tic-tac-toe game.
The board is a `3 x 3` array that consists of characters `' '`, `'X'`, and `'O'`. The `' '` character represents an empty square.
Here are the ru... | Use either Dijkstra's, or binary search for the best time T for which you can reach the end if you only step on squares at most T. |
Python | Straightforward Solution | valid-tic-tac-toe-state | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\njust validate against the rules\n\n# Code\n```\nclass Solution:\n def validTicTacToe(self, board: List[str]) -> bool:\n n = len(board)\n cntx = cnto = 0\n rows = [0] * n\n cols = [0] * n\n diagonals... | 0 | You are given an array of integers `nums` represents the numbers written on a chalkboard.
Alice and Bob take turns erasing exactly one number from the chalkboard, with Alice starting first. If erasing a number causes the bitwise XOR of all the elements of the chalkboard to become `0`, then that player loses. The bitwi... | null |
Python3 | Easy To Understand | valid-tic-tac-toe-state | 0 | 1 | # Code\n```\nclass Solution:\n\n def win_check(self, arr, char):\n matches = [[0, 1, 2], [3, 4, 5],\n [6, 7, 8], [0, 3, 6],\n [1, 4, 7], [2, 5, 8],\n [0, 4, 8], [2, 4, 6]]\n \n for i in range(8):\n if(arr[int((matches[i][0])/3)][(matches[i][0])... | 0 | Given a Tic-Tac-Toe board as a string array `board`, return `true` if and only if it is possible to reach this board position during the course of a valid tic-tac-toe game.
The board is a `3 x 3` array that consists of characters `' '`, `'X'`, and `'O'`. The `' '` character represents an empty square.
Here are the ru... | Use either Dijkstra's, or binary search for the best time T for which you can reach the end if you only step on squares at most T. |
Python3 | Easy To Understand | valid-tic-tac-toe-state | 0 | 1 | # Code\n```\nclass Solution:\n\n def win_check(self, arr, char):\n matches = [[0, 1, 2], [3, 4, 5],\n [6, 7, 8], [0, 3, 6],\n [1, 4, 7], [2, 5, 8],\n [0, 4, 8], [2, 4, 6]]\n \n for i in range(8):\n if(arr[int((matches[i][0])/3)][(matches[i][0])... | 0 | You are given an array of integers `nums` represents the numbers written on a chalkboard.
Alice and Bob take turns erasing exactly one number from the chalkboard, with Alice starting first. If erasing a number causes the bitwise XOR of all the elements of the chalkboard to become `0`, then that player loses. The bitwi... | null |
Beats 99% | valid-tic-tac-toe-state | 0 | 1 | # Approach\nFirst check who the winner(s) on the board are, then check if its possible to reach that state by counting the number of "X"s and "O"s on the board\n\n# Code\n```\nclass Solution:\n def validTicTacToe(self, board: List[str]) -> bool:\n def checkwinner(board):\n winners = \'\'\n\n ... | 0 | Given a Tic-Tac-Toe board as a string array `board`, return `true` if and only if it is possible to reach this board position during the course of a valid tic-tac-toe game.
The board is a `3 x 3` array that consists of characters `' '`, `'X'`, and `'O'`. The `' '` character represents an empty square.
Here are the ru... | Use either Dijkstra's, or binary search for the best time T for which you can reach the end if you only step on squares at most T. |
Beats 99% | valid-tic-tac-toe-state | 0 | 1 | # Approach\nFirst check who the winner(s) on the board are, then check if its possible to reach that state by counting the number of "X"s and "O"s on the board\n\n# Code\n```\nclass Solution:\n def validTicTacToe(self, board: List[str]) -> bool:\n def checkwinner(board):\n winners = \'\'\n\n ... | 0 | You are given an array of integers `nums` represents the numbers written on a chalkboard.
Alice and Bob take turns erasing exactly one number from the chalkboard, with Alice starting first. If erasing a number causes the bitwise XOR of all the elements of the chalkboard to become `0`, then that player loses. The bitwi... | null |
794: Beats 97.22%, Solution with step by step explanation | valid-tic-tac-toe-state | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n```\nx_count = sum(row.count(\'X\') for row in board)\no_count = sum(row.count(\'O\') for row in board)\n```\n\nBefore proceeding with other checks, it\'s vital to understand that since \'X\' always starts the game, there sh... | 0 | Given a Tic-Tac-Toe board as a string array `board`, return `true` if and only if it is possible to reach this board position during the course of a valid tic-tac-toe game.
The board is a `3 x 3` array that consists of characters `' '`, `'X'`, and `'O'`. The `' '` character represents an empty square.
Here are the ru... | Use either Dijkstra's, or binary search for the best time T for which you can reach the end if you only step on squares at most T. |
794: Beats 97.22%, Solution with step by step explanation | valid-tic-tac-toe-state | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n```\nx_count = sum(row.count(\'X\') for row in board)\no_count = sum(row.count(\'O\') for row in board)\n```\n\nBefore proceeding with other checks, it\'s vital to understand that since \'X\' always starts the game, there sh... | 0 | You are given an array of integers `nums` represents the numbers written on a chalkboard.
Alice and Bob take turns erasing exactly one number from the chalkboard, with Alice starting first. If erasing a number causes the bitwise XOR of all the elements of the chalkboard to become `0`, then that player loses. The bitwi... | null |
Python simplely list all case beats 94.33% | valid-tic-tac-toe-state | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nList all condition then we\'ll check it from item to item\n1.In any case, the count of O will be either count of X or count of X-1\n2.If X win, the count of O must equal the count of X -1\n3.If O win, the count of O must equ... | 0 | Given a Tic-Tac-Toe board as a string array `board`, return `true` if and only if it is possible to reach this board position during the course of a valid tic-tac-toe game.
The board is a `3 x 3` array that consists of characters `' '`, `'X'`, and `'O'`. The `' '` character represents an empty square.
Here are the ru... | Use either Dijkstra's, or binary search for the best time T for which you can reach the end if you only step on squares at most T. |
Python simplely list all case beats 94.33% | valid-tic-tac-toe-state | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nList all condition then we\'ll check it from item to item\n1.In any case, the count of O will be either count of X or count of X-1\n2.If X win, the count of O must equal the count of X -1\n3.If O win, the count of O must equ... | 0 | You are given an array of integers `nums` represents the numbers written on a chalkboard.
Alice and Bob take turns erasing exactly one number from the chalkboard, with Alice starting first. If erasing a number causes the bitwise XOR of all the elements of the chalkboard to become `0`, then that player loses. The bitwi... | null |
[Python3] Good enough | valid-tic-tac-toe-state | 0 | 1 | ``` Python3 []\nclass Solution:\n def validTicTacToe(self, board: List[str]) -> bool:\n xs = \'\'.join(board).count(\'X\')\n os = \'\'.join(board).count(\'O\')\n if xs-os not in (0,1):\n return False\n \n seen = {}\n\n if \'\'.join(board[0]) in (\'XXX\',\'OOO\'): ... | 0 | Given a Tic-Tac-Toe board as a string array `board`, return `true` if and only if it is possible to reach this board position during the course of a valid tic-tac-toe game.
The board is a `3 x 3` array that consists of characters `' '`, `'X'`, and `'O'`. The `' '` character represents an empty square.
Here are the ru... | Use either Dijkstra's, or binary search for the best time T for which you can reach the end if you only step on squares at most T. |
[Python3] Good enough | valid-tic-tac-toe-state | 0 | 1 | ``` Python3 []\nclass Solution:\n def validTicTacToe(self, board: List[str]) -> bool:\n xs = \'\'.join(board).count(\'X\')\n os = \'\'.join(board).count(\'O\')\n if xs-os not in (0,1):\n return False\n \n seen = {}\n\n if \'\'.join(board[0]) in (\'XXX\',\'OOO\'): ... | 0 | You are given an array of integers `nums` represents the numbers written on a chalkboard.
Alice and Bob take turns erasing exactly one number from the chalkboard, with Alice starting first. If erasing a number causes the bitwise XOR of all the elements of the chalkboard to become `0`, then that player loses. The bitwi... | null |
TicTacToe Lab Intro | Commented and Explained | valid-tic-tac-toe-state | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThis is serving as a lab walkthrough for my intro to python class. If just reviewing for your own purposes, you can skip to the approach. \n\nIn computer science we are concerned most often with presenting something of value to a user, wh... | 0 | Given a Tic-Tac-Toe board as a string array `board`, return `true` if and only if it is possible to reach this board position during the course of a valid tic-tac-toe game.
The board is a `3 x 3` array that consists of characters `' '`, `'X'`, and `'O'`. The `' '` character represents an empty square.
Here are the ru... | Use either Dijkstra's, or binary search for the best time T for which you can reach the end if you only step on squares at most T. |
TicTacToe Lab Intro | Commented and Explained | valid-tic-tac-toe-state | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThis is serving as a lab walkthrough for my intro to python class. If just reviewing for your own purposes, you can skip to the approach. \n\nIn computer science we are concerned most often with presenting something of value to a user, wh... | 0 | You are given an array of integers `nums` represents the numbers written on a chalkboard.
Alice and Bob take turns erasing exactly one number from the chalkboard, with Alice starting first. If erasing a number causes the bitwise XOR of all the elements of the chalkboard to become `0`, then that player loses. The bitwi... | null |
Number of Subarrays with Bounded Maximum || Simple Python Sliding Window | number-of-subarrays-with-bounded-maximum | 0 | 1 | ```\nclass Solution:\n def numSubarrayBoundedMax(self, nums: List[int], left: int, right: int) -> int:\n windowStart=0\n count=0\n curr=0\n \n for windowEnd, num in enumerate(nums):\n if left <= num <= right:\n curr = windowEnd - windowStart + 1\n ... | 4 | Given an integer array `nums` and two integers `left` and `right`, return _the number of contiguous non-empty **subarrays** such that the value of the maximum array element in that subarray is in the range_ `[left, right]`.
The test cases are generated so that the answer will fit in a **32-bit** integer.
**Example 1:... | Try to represent the current (N, K) in terms of some (N-1, prevK). What is prevK ? |
Number of Subarrays with Bounded Maximum || Simple Python Sliding Window | number-of-subarrays-with-bounded-maximum | 0 | 1 | ```\nclass Solution:\n def numSubarrayBoundedMax(self, nums: List[int], left: int, right: int) -> int:\n windowStart=0\n count=0\n curr=0\n \n for windowEnd, num in enumerate(nums):\n if left <= num <= right:\n curr = windowEnd - windowStart + 1\n ... | 4 | A website domain `"discuss.leetcode.com "` consists of various subdomains. At the top level, we have `"com "`, at the next level, we have `"leetcode.com "` and at the lowest level, `"discuss.leetcode.com "`. When we visit a domain like `"discuss.leetcode.com "`, we will also visit the parent domains `"leetcode.com "` a... | null |
Python | Two pointer technique | Easy solution | number-of-subarrays-with-bounded-maximum | 0 | 1 | ***Do hit like button if helpful!!!!***\n```\nclass Solution:\n def numSubarrayBoundedMax(self, nums: List[int], left: int, right: int) -> int:\n start,end = -1, -1\n res = 0\n for i in range(len(nums)):\n if nums[i] > right:\n start = end = i\n continue\... | 4 | Given an integer array `nums` and two integers `left` and `right`, return _the number of contiguous non-empty **subarrays** such that the value of the maximum array element in that subarray is in the range_ `[left, right]`.
The test cases are generated so that the answer will fit in a **32-bit** integer.
**Example 1:... | Try to represent the current (N, K) in terms of some (N-1, prevK). What is prevK ? |
Python | Two pointer technique | Easy solution | number-of-subarrays-with-bounded-maximum | 0 | 1 | ***Do hit like button if helpful!!!!***\n```\nclass Solution:\n def numSubarrayBoundedMax(self, nums: List[int], left: int, right: int) -> int:\n start,end = -1, -1\n res = 0\n for i in range(len(nums)):\n if nums[i] > right:\n start = end = i\n continue\... | 4 | A website domain `"discuss.leetcode.com "` consists of various subdomains. At the top level, we have `"com "`, at the next level, we have `"leetcode.com "` and at the lowest level, `"discuss.leetcode.com "`. When we visit a domain like `"discuss.leetcode.com "`, we will also visit the parent domains `"leetcode.com "` a... | null |
📌 MAANG One Liner 💥😯 | rotate-string | 1 | 1 | \n\n# Complexity\n- Time complexity: O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(n)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n bool rotateString(string s, string goal) {\n return (s.size()==goal.size()) && (s+s).... | 5 | Given two strings `s` and `goal`, return `true` _if and only if_ `s` _can become_ `goal` _after some number of **shifts** on_ `s`.
A **shift** on `s` consists of moving the leftmost character of `s` to the rightmost position.
* For example, if `s = "abcde "`, then it will be `"bcdea "` after one shift.
**Example 1... | null |
📌 MAANG One Liner 💥😯 | rotate-string | 1 | 1 | \n\n# Complexity\n- Time complexity: O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(n)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n bool rotateString(string s, string goal) {\n return (s.size()==goal.size()) && (s+s).... | 5 | Given an array of points on the **X-Y** plane `points` where `points[i] = [xi, yi]`, return _the area of the largest triangle that can be formed by any three different points_. Answers within `10-5` of the actual answer will be accepted.
**Example 1:**
**Input:** points = \[\[0,0\],\[0,1\],\[1,0\],\[0,2\],\[2,0\]\]
*... | null |
✅ | python3 | ONE LINE | FASTER THAN 99% | 🔥💪 | rotate-string | 0 | 1 | ```\nclass Solution:\n def rotateString(self, s: str, goal: str) -> bool:\n return len(s) == len(goal) and s in goal+goal \n```\n\nEnjoy :) | 47 | Given two strings `s` and `goal`, return `true` _if and only if_ `s` _can become_ `goal` _after some number of **shifts** on_ `s`.
A **shift** on `s` consists of moving the leftmost character of `s` to the rightmost position.
* For example, if `s = "abcde "`, then it will be `"bcdea "` after one shift.
**Example 1... | null |
✅ | python3 | ONE LINE | FASTER THAN 99% | 🔥💪 | rotate-string | 0 | 1 | ```\nclass Solution:\n def rotateString(self, s: str, goal: str) -> bool:\n return len(s) == len(goal) and s in goal+goal \n```\n\nEnjoy :) | 47 | Given an array of points on the **X-Y** plane `points` where `points[i] = [xi, yi]`, return _the area of the largest triangle that can be formed by any three different points_. Answers within `10-5` of the actual answer will be accepted.
**Example 1:**
**Input:** points = \[\[0,0\],\[0,1\],\[1,0\],\[0,2\],\[2,0\]\]
*... | null |
python3, simple DFS | all-paths-from-source-to-target | 0 | 1 | ERROR: type should be string, got "https://leetcode.com/accounts/login/?next=/submissions/detail/868289908/ \\n```\\nRuntime: 93 ms, faster than 98.56% of Python3 online submissions for All Paths From Source to Target.\\nMemory Usage: 15.6 MB, less than 78.47% of Python3 online submissions for All Paths From Source to Target.\\n```\\n```\\nclass Solution:\\n def allPathsSourceTarget(self, graph: List[List[int]]) -> List[List[int]]:\\n target = len(graph) - 1\\n paths, targets = [[0]], []\\n while paths:\\n path = paths.pop(0)\\n edges = graph[path[-1]]\\n if not edges: \\n continue\\n for edge in edges:\\n if edge==target:\\n targets.append(path+[edge])\\n else:\\n paths = [path+[edge]] + paths\\n return targets \\n```" | 2 | Given a directed acyclic graph (**DAG**) of `n` nodes labeled from `0` to `n - 1`, find all possible paths from node `0` to node `n - 1` and return them in **any order**.
The graph is given as follows: `graph[i]` is a list of all nodes you can visit from node `i` (i.e., there is a directed edge from node `i` to node `... | null |
python3, simple DFS | all-paths-from-source-to-target | 0 | 1 | ERROR: type should be string, got "https://leetcode.com/accounts/login/?next=/submissions/detail/868289908/ \\n```\\nRuntime: 93 ms, faster than 98.56% of Python3 online submissions for All Paths From Source to Target.\\nMemory Usage: 15.6 MB, less than 78.47% of Python3 online submissions for All Paths From Source to Target.\\n```\\n```\\nclass Solution:\\n def allPathsSourceTarget(self, graph: List[List[int]]) -> List[List[int]]:\\n target = len(graph) - 1\\n paths, targets = [[0]], []\\n while paths:\\n path = paths.pop(0)\\n edges = graph[path[-1]]\\n if not edges: \\n continue\\n for edge in edges:\\n if edge==target:\\n targets.append(path+[edge])\\n else:\\n paths = [path+[edge]] + paths\\n return targets \\n```" | 2 | You are given an integer array `nums` and an integer `k`. You can partition the array into **at most** `k` non-empty adjacent subarrays. The **score** of a partition is the sum of the averages of each subarray.
Note that the partition must use every integer in `nums`, and that the score is not necessarily an integer.
... | null |
Solution | smallest-rotation-with-highest-score | 1 | 1 | ```C++ []\nint cnt[100000];\nint speedup = []{ios::sync_with_stdio(0); cin.tie(0); return 0;}();\n\nclass Solution {\npublic:\n int bestRotation(vector<int>& nums) {\n int n = size(nums);\n memset(cnt, 0, sizeof(int) * n);\n for (int i = 0; i < n; ++i) {\n int v = nums[i], i2 = i-v;\n... | 1 | You are given an array `nums`. You can rotate it by a non-negative integer `k` so that the array becomes `[nums[k], nums[k + 1], ... nums[nums.length - 1], nums[0], nums[1], ..., nums[k-1]]`. Afterward, any entries that are less than or equal to their index are worth one point.
* For example, if we have `nums = [2,4... | null |
Solution | smallest-rotation-with-highest-score | 1 | 1 | ```C++ []\nint cnt[100000];\nint speedup = []{ios::sync_with_stdio(0); cin.tie(0); return 0;}();\n\nclass Solution {\npublic:\n int bestRotation(vector<int>& nums) {\n int n = size(nums);\n memset(cnt, 0, sizeof(int) * n);\n for (int i = 0; i < n; ++i) {\n int v = nums[i], i2 = i-v;\n... | 1 | Given the `root` of a binary tree, return _the same tree where every subtree (of the given tree) not containing a_ `1` _has been removed_.
A subtree of a node `node` is `node` plus every node that is a descendant of `node`.
**Example 1:**
**Input:** root = \[1,null,0,0,1\]
**Output:** \[1,null,0,null,1\]
**Explanati... | null |
✔ Python3 Solution | Prefix Sum | smallest-rotation-with-highest-score | 0 | 1 | # Complexity\n- Time complexity: $$O(n)$$\n- Space complexity: $$O(n)$$\n\n# Code\n```Python\nclass Solution:\n def bestRotation(self, A):\n n = len(A)\n P = [1] * n\n for i in range(n):\n P[(i - A[i] + 1) % n] -= 1\n P = list(accumulate(P))\n return P.index(max(P))\n``` | 2 | You are given an array `nums`. You can rotate it by a non-negative integer `k` so that the array becomes `[nums[k], nums[k + 1], ... nums[nums.length - 1], nums[0], nums[1], ..., nums[k-1]]`. Afterward, any entries that are less than or equal to their index are worth one point.
* For example, if we have `nums = [2,4... | null |
✔ Python3 Solution | Prefix Sum | smallest-rotation-with-highest-score | 0 | 1 | # Complexity\n- Time complexity: $$O(n)$$\n- Space complexity: $$O(n)$$\n\n# Code\n```Python\nclass Solution:\n def bestRotation(self, A):\n n = len(A)\n P = [1] * n\n for i in range(n):\n P[(i - A[i] + 1) % n] -= 1\n P = list(accumulate(P))\n return P.index(max(P))\n``` | 2 | Given the `root` of a binary tree, return _the same tree where every subtree (of the given tree) not containing a_ `1` _has been removed_.
A subtree of a node `node` is `node` plus every node that is a descendant of `node`.
**Example 1:**
**Input:** root = \[1,null,0,0,1\]
**Output:** \[1,null,0,null,1\]
**Explanati... | null |
798: Solution with step by step explanation | smallest-rotation-with-highest-score | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n```\nn = len(nums)\nchange = [1] * n\n```\n\nHere, we find the length n of the nums array.\nWe initialize a change list of the same length filled with ones. This list represents the difference in scores for each rotation k.\... | 0 | You are given an array `nums`. You can rotate it by a non-negative integer `k` so that the array becomes `[nums[k], nums[k + 1], ... nums[nums.length - 1], nums[0], nums[1], ..., nums[k-1]]`. Afterward, any entries that are less than or equal to their index are worth one point.
* For example, if we have `nums = [2,4... | null |
798: Solution with step by step explanation | smallest-rotation-with-highest-score | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n```\nn = len(nums)\nchange = [1] * n\n```\n\nHere, we find the length n of the nums array.\nWe initialize a change list of the same length filled with ones. This list represents the difference in scores for each rotation k.\... | 0 | Given the `root` of a binary tree, return _the same tree where every subtree (of the given tree) not containing a_ `1` _has been removed_.
A subtree of a node `node` is `node` plus every node that is a descendant of `node`.
**Example 1:**
**Input:** root = \[1,null,0,0,1\]
**Output:** \[1,null,0,null,1\]
**Explanati... | null |
Python 32% | score range parsing, but not prefix-sum | smallest-rotation-with-highest-score | 0 | 1 | # Intuition\r\nRather than using prefix-sum, I began with the awareness that this problem can be broken into two subproblems:\r\n1. for each number in array, what\'s the range of k? so that in the end this number can score?\r\n2. given certain intervals, find out the very first index that has the most intervals coverin... | 0 | You are given an array `nums`. You can rotate it by a non-negative integer `k` so that the array becomes `[nums[k], nums[k + 1], ... nums[nums.length - 1], nums[0], nums[1], ..., nums[k-1]]`. Afterward, any entries that are less than or equal to their index are worth one point.
* For example, if we have `nums = [2,4... | null |
Python 32% | score range parsing, but not prefix-sum | smallest-rotation-with-highest-score | 0 | 1 | # Intuition\r\nRather than using prefix-sum, I began with the awareness that this problem can be broken into two subproblems:\r\n1. for each number in array, what\'s the range of k? so that in the end this number can score?\r\n2. given certain intervals, find out the very first index that has the most intervals coverin... | 0 | Given the `root` of a binary tree, return _the same tree where every subtree (of the given tree) not containing a_ `1` _has been removed_.
A subtree of a node `node` is `node` plus every node that is a descendant of `node`.
**Example 1:**
**Input:** root = \[1,null,0,0,1\]
**Output:** \[1,null,0,null,1\]
**Explanati... | null |
[Python3] difference array | smallest-rotation-with-highest-score | 0 | 1 | \n```\nclass Solution:\n def bestRotation(self, nums: List[int]) -> int:\n diff = [0]*(len(nums) + 1)\n for i, x in enumerate(nums): \n diff[i+1] += 1\n if x <= i: diff[0] += 1\n diff[(i-x)%len(nums) + 1] -= 1\n \n ans = prefix = 0 \n mx = -inf \n ... | 1 | You are given an array `nums`. You can rotate it by a non-negative integer `k` so that the array becomes `[nums[k], nums[k + 1], ... nums[nums.length - 1], nums[0], nums[1], ..., nums[k-1]]`. Afterward, any entries that are less than or equal to their index are worth one point.
* For example, if we have `nums = [2,4... | null |
[Python3] difference array | smallest-rotation-with-highest-score | 0 | 1 | \n```\nclass Solution:\n def bestRotation(self, nums: List[int]) -> int:\n diff = [0]*(len(nums) + 1)\n for i, x in enumerate(nums): \n diff[i+1] += 1\n if x <= i: diff[0] += 1\n diff[(i-x)%len(nums) + 1] -= 1\n \n ans = prefix = 0 \n mx = -inf \n ... | 1 | Given the `root` of a binary tree, return _the same tree where every subtree (of the given tree) not containing a_ `1` _has been removed_.
A subtree of a node `node` is `node` plus every node that is a descendant of `node`.
**Example 1:**
**Input:** root = \[1,null,0,0,1\]
**Output:** \[1,null,0,null,1\]
**Explanati... | null |
🚀98.73% || Dynamic Programming || Commented Code🚀 | champagne-tower | 1 | 1 | # Problem Description\nStack drink glasses in a **pyramid** structure, starting with one glass in the first row and **incrementing** by one glass in each subsequent row, up to the `100th` row. Pour drink into the top glass, any excess spills equally to the **adjacent** `left` and `right` glasses. \nDetermine the levels... | 22 | We stack glasses in a pyramid, where the **first** row has `1` glass, the **second** row has `2` glasses, and so on until the 100th row. Each glass holds one cup of champagne.
Then, some champagne is poured into the first glass at the top. When the topmost glass is full, any excess liquid poured will fall equally to t... | null |
🚀98.73% || Dynamic Programming || Commented Code🚀 | champagne-tower | 1 | 1 | # Problem Description\nStack drink glasses in a **pyramid** structure, starting with one glass in the first row and **incrementing** by one glass in each subsequent row, up to the `100th` row. Pour drink into the top glass, any excess spills equally to the **adjacent** `left` and `right` glasses. \nDetermine the levels... | 22 | You are given an array `routes` representing bus routes where `routes[i]` is a bus route that the `ith` bus repeats forever.
* For example, if `routes[0] = [1, 5, 7]`, this means that the `0th` bus travels in the sequence `1 -> 5 -> 7 -> 1 -> 5 -> 7 -> 1 -> ...` forever.
You will start at the bus stop `source` (You... | null |
[Python3] 1-liner Top-down Dynamic Programming Solution | champagne-tower | 0 | 1 | # Approach\nTop-down DP in one line\n\n# Code\n```\nclass Solution:\n def champagneTower(self, poured: int, query_row: int, query_glass: int) -> float:\n return min((lambda func: lambda a, b, c: func(func, a, b, c))((functools.lru_cache(maxsize=None))(lambda champagneTower_, poured_, query_row_, query_glass_:... | 1 | We stack glasses in a pyramid, where the **first** row has `1` glass, the **second** row has `2` glasses, and so on until the 100th row. Each glass holds one cup of champagne.
Then, some champagne is poured into the first glass at the top. When the topmost glass is full, any excess liquid poured will fall equally to t... | null |
[Python3] 1-liner Top-down Dynamic Programming Solution | champagne-tower | 0 | 1 | # Approach\nTop-down DP in one line\n\n# Code\n```\nclass Solution:\n def champagneTower(self, poured: int, query_row: int, query_glass: int) -> float:\n return min((lambda func: lambda a, b, c: func(func, a, b, c))((functools.lru_cache(maxsize=None))(lambda champagneTower_, poured_, query_row_, query_glass_:... | 1 | You are given an array `routes` representing bus routes where `routes[i]` is a bus route that the `ith` bus repeats forever.
* For example, if `routes[0] = [1, 5, 7]`, this means that the `0th` bus travels in the sequence `1 -> 5 -> 7 -> 1 -> 5 -> 7 -> 1 -> ...` forever.
You will start at the bus stop `source` (You... | null |
Python greedy | champagne-tower | 0 | 1 | # Intuition\n`poured` in a `glass[i][j]` fall into `glass[i+1][j]` and `glass[i+1][j+1]`\n\n# Code\n```\nclass Solution:\n def champagneTower(self, poured: int, query_row: int, query_glass: int) -> float:\n A = [poured]\n row_index = 0\n while any(A):\n if row_index == query_row:\n ... | 1 | We stack glasses in a pyramid, where the **first** row has `1` glass, the **second** row has `2` glasses, and so on until the 100th row. Each glass holds one cup of champagne.
Then, some champagne is poured into the first glass at the top. When the topmost glass is full, any excess liquid poured will fall equally to t... | null |
Python greedy | champagne-tower | 0 | 1 | # Intuition\n`poured` in a `glass[i][j]` fall into `glass[i+1][j]` and `glass[i+1][j+1]`\n\n# Code\n```\nclass Solution:\n def champagneTower(self, poured: int, query_row: int, query_glass: int) -> float:\n A = [poured]\n row_index = 0\n while any(A):\n if row_index == query_row:\n ... | 1 | You are given an array `routes` representing bus routes where `routes[i]` is a bus route that the `ith` bus repeats forever.
* For example, if `routes[0] = [1, 5, 7]`, this means that the `0th` bus travels in the sequence `1 -> 5 -> 7 -> 1 -> 5 -> 7 -> 1 -> ...` forever.
You will start at the bus stop `source` (You... | null |
easy solution | champagne-tower | 0 | 1 | # 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 | We stack glasses in a pyramid, where the **first** row has `1` glass, the **second** row has `2` glasses, and so on until the 100th row. Each glass holds one cup of champagne.
Then, some champagne is poured into the first glass at the top. When the topmost glass is full, any excess liquid poured will fall equally to t... | null |
easy solution | champagne-tower | 0 | 1 | # 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 | You are given an array `routes` representing bus routes where `routes[i]` is a bus route that the `ith` bus repeats forever.
* For example, if `routes[0] = [1, 5, 7]`, this means that the `0th` bus travels in the sequence `1 -> 5 -> 7 -> 1 -> 5 -> 7 -> 1 -> ...` forever.
You will start at the bus stop `source` (You... | null |
Solved it after 1 hour , i am improving . | champagne-tower | 0 | 1 | # 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 | We stack glasses in a pyramid, where the **first** row has `1` glass, the **second** row has `2` glasses, and so on until the 100th row. Each glass holds one cup of champagne.
Then, some champagne is poured into the first glass at the top. When the topmost glass is full, any excess liquid poured will fall equally to t... | null |
Solved it after 1 hour , i am improving . | champagne-tower | 0 | 1 | # 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 | You are given an array `routes` representing bus routes where `routes[i]` is a bus route that the `ith` bus repeats forever.
* For example, if `routes[0] = [1, 5, 7]`, this means that the `0th` bus travels in the sequence `1 -> 5 -> 7 -> 1 -> 5 -> 7 -> 1 -> ...` forever.
You will start at the bus stop `source` (You... | null |
[Python]Easy One, But Also Easy to Get It Wrong! | champagne-tower | 0 | 1 | # Code\n```\nclass Solution:\n def champagneTower(self, poured: int, query_row: int, query_glass: int) -> float:\n if poured == 0:\n return 0\n states = {(0,0):(1,poured-1)}\n\n def getRe(query_row:int, query_glass:int):\n if states.__contains__((query_row,query_glass)):\n ... | 1 | We stack glasses in a pyramid, where the **first** row has `1` glass, the **second** row has `2` glasses, and so on until the 100th row. Each glass holds one cup of champagne.
Then, some champagne is poured into the first glass at the top. When the topmost glass is full, any excess liquid poured will fall equally to t... | null |
[Python]Easy One, But Also Easy to Get It Wrong! | champagne-tower | 0 | 1 | # Code\n```\nclass Solution:\n def champagneTower(self, poured: int, query_row: int, query_glass: int) -> float:\n if poured == 0:\n return 0\n states = {(0,0):(1,poured-1)}\n\n def getRe(query_row:int, query_glass:int):\n if states.__contains__((query_row,query_glass)):\n ... | 1 | You are given an array `routes` representing bus routes where `routes[i]` is a bus route that the `ith` bus repeats forever.
* For example, if `routes[0] = [1, 5, 7]`, this means that the `0th` bus travels in the sequence `1 -> 5 -> 7 -> 1 -> 5 -> 7 -> 1 -> ...` forever.
You will start at the bus stop `source` (You... | null |
Python3 Solution | champagne-tower | 0 | 1 | \n```\nclass Solution:\n def champagneTower(self, poured: int, query_row: int, query_glass: int) -> float:\n glasses=[poured]\n for i in range(query_row):\n temp=[0]*(len(glasses)+1)\n for i in range(len(glasses)):\n pour=max(0,glasses[i]-1)/2\n temp[... | 1 | We stack glasses in a pyramid, where the **first** row has `1` glass, the **second** row has `2` glasses, and so on until the 100th row. Each glass holds one cup of champagne.
Then, some champagne is poured into the first glass at the top. When the topmost glass is full, any excess liquid poured will fall equally to t... | null |
Python3 Solution | champagne-tower | 0 | 1 | \n```\nclass Solution:\n def champagneTower(self, poured: int, query_row: int, query_glass: int) -> float:\n glasses=[poured]\n for i in range(query_row):\n temp=[0]*(len(glasses)+1)\n for i in range(len(glasses)):\n pour=max(0,glasses[i]-1)/2\n temp[... | 1 | You are given an array `routes` representing bus routes where `routes[i]` is a bus route that the `ith` bus repeats forever.
* For example, if `routes[0] = [1, 5, 7]`, this means that the `0th` bus travels in the sequence `1 -> 5 -> 7 -> 1 -> 5 -> 7 -> 1 -> ...` forever.
You will start at the bus stop `source` (You... | null |
Solution | champagne-tower | 1 | 1 | ```C++ []\nclass Solution {\npublic:\n double champagneTower(int poured, int query_row, int query_glass) {\n double dp[101][101] = {0.00000};\n dp[0][0] = (double)poured;\n for(int i = 0; i <= query_row; i++){\n for(int j = 0; j <= i; j++){\n if(dp[i][j] > 1){\n ... | 1 | We stack glasses in a pyramid, where the **first** row has `1` glass, the **second** row has `2` glasses, and so on until the 100th row. Each glass holds one cup of champagne.
Then, some champagne is poured into the first glass at the top. When the topmost glass is full, any excess liquid poured will fall equally to t... | null |
Solution | champagne-tower | 1 | 1 | ```C++ []\nclass Solution {\npublic:\n double champagneTower(int poured, int query_row, int query_glass) {\n double dp[101][101] = {0.00000};\n dp[0][0] = (double)poured;\n for(int i = 0; i <= query_row; i++){\n for(int j = 0; j <= i; j++){\n if(dp[i][j] > 1){\n ... | 1 | You are given an array `routes` representing bus routes where `routes[i]` is a bus route that the `ith` bus repeats forever.
* For example, if `routes[0] = [1, 5, 7]`, this means that the `0th` bus travels in the sequence `1 -> 5 -> 7 -> 1 -> 5 -> 7 -> 1 -> ...` forever.
You will start at the bus stop `source` (You... | null |
🚀Beats 100% Acceptance📈 of runtime and memory with optimisation | Detailed and easy explanation | champagne-tower | 1 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe problem models the pouring of champagne into a pyramid of glasses. The goal is to find the champagne level in a specific glass at a given row. The key insight is that champagne flows from higher rows to lower rows, and any excess cham... | 3 | We stack glasses in a pyramid, where the **first** row has `1` glass, the **second** row has `2` glasses, and so on until the 100th row. Each glass holds one cup of champagne.
Then, some champagne is poured into the first glass at the top. When the topmost glass is full, any excess liquid poured will fall equally to t... | null |
🚀Beats 100% Acceptance📈 of runtime and memory with optimisation | Detailed and easy explanation | champagne-tower | 1 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe problem models the pouring of champagne into a pyramid of glasses. The goal is to find the champagne level in a specific glass at a given row. The key insight is that champagne flows from higher rows to lower rows, and any excess cham... | 3 | You are given an array `routes` representing bus routes where `routes[i]` is a bus route that the `ith` bus repeats forever.
* For example, if `routes[0] = [1, 5, 7]`, this means that the `0th` bus travels in the sequence `1 -> 5 -> 7 -> 1 -> 5 -> 7 -> 1 -> ...` forever.
You will start at the bus stop `source` (You... | null |
✅98.44%🔥Dynamic Programming & Iterative Approach🔥 | champagne-tower | 1 | 1 | # Problem\n#### This problem can be viewed as a dynamic programming problem where you are pouring champagne into glasses arranged in a pyramid shape and need to find out how much champagne each glass contains after a certain amount of pouring. The key idea is to track the amount of champagne in each glass by simulating... | 55 | We stack glasses in a pyramid, where the **first** row has `1` glass, the **second** row has `2` glasses, and so on until the 100th row. Each glass holds one cup of champagne.
Then, some champagne is poured into the first glass at the top. When the topmost glass is full, any excess liquid poured will fall equally to t... | null |
✅98.44%🔥Dynamic Programming & Iterative Approach🔥 | champagne-tower | 1 | 1 | # Problem\n#### This problem can be viewed as a dynamic programming problem where you are pouring champagne into glasses arranged in a pyramid shape and need to find out how much champagne each glass contains after a certain amount of pouring. The key idea is to track the amount of champagne in each glass by simulating... | 55 | You are given an array `routes` representing bus routes where `routes[i]` is a bus route that the `ith` bus repeats forever.
* For example, if `routes[0] = [1, 5, 7]`, this means that the `0th` bus travels in the sequence `1 -> 5 -> 7 -> 1 -> 5 -> 7 -> 1 -> ...` forever.
You will start at the bus stop `source` (You... | null |
【Video】How we think about a solution - DP Solution with 1D and 2D - Python, JavaScript, Java and C++ | champagne-tower | 1 | 1 | Welcome to my article! This artcle starts with "How we think about a solution". In other words, that is my thought process to solve the question. This article explains how I get to my solution instead of just posting solution codes or out of blue algorithms. I hope this aricle is helpful for someone.\n\n# Intuition\n\n... | 30 | We stack glasses in a pyramid, where the **first** row has `1` glass, the **second** row has `2` glasses, and so on until the 100th row. Each glass holds one cup of champagne.
Then, some champagne is poured into the first glass at the top. When the topmost glass is full, any excess liquid poured will fall equally to t... | null |
【Video】How we think about a solution - DP Solution with 1D and 2D - Python, JavaScript, Java and C++ | champagne-tower | 1 | 1 | Welcome to my article! This artcle starts with "How we think about a solution". In other words, that is my thought process to solve the question. This article explains how I get to my solution instead of just posting solution codes or out of blue algorithms. I hope this aricle is helpful for someone.\n\n# Intuition\n\n... | 30 | You are given an array `routes` representing bus routes where `routes[i]` is a bus route that the `ith` bus repeats forever.
* For example, if `routes[0] = [1, 5, 7]`, this means that the `0th` bus travels in the sequence `1 -> 5 -> 7 -> 1 -> 5 -> 7 -> 1 -> ...` forever.
You will start at the bus stop `source` (You... | null |
Python 1-liner. Functional programming. | champagne-tower | 0 | 1 | # Approach\nTL;DR, Similar to [Editorial solution](https://leetcode.com/problems/champagne-tower/editorial/?envType=daily-question&envId=2023-09-24) but shorter and functional.\n\n# Complexity\n- Time complexity: $$O(n^2)$$\n\n- Space complexity: $$O(n)$$\n\nwhere,\n`n is query_row`.\n\n# Code\nImperative multi-liner:\... | 1 | We stack glasses in a pyramid, where the **first** row has `1` glass, the **second** row has `2` glasses, and so on until the 100th row. Each glass holds one cup of champagne.
Then, some champagne is poured into the first glass at the top. When the topmost glass is full, any excess liquid poured will fall equally to t... | null |
Python 1-liner. Functional programming. | champagne-tower | 0 | 1 | # Approach\nTL;DR, Similar to [Editorial solution](https://leetcode.com/problems/champagne-tower/editorial/?envType=daily-question&envId=2023-09-24) but shorter and functional.\n\n# Complexity\n- Time complexity: $$O(n^2)$$\n\n- Space complexity: $$O(n)$$\n\nwhere,\n`n is query_row`.\n\n# Code\nImperative multi-liner:\... | 1 | You are given an array `routes` representing bus routes where `routes[i]` is a bus route that the `ith` bus repeats forever.
* For example, if `routes[0] = [1, 5, 7]`, this means that the `0th` bus travels in the sequence `1 -> 5 -> 7 -> 1 -> 5 -> 7 -> 1 -> ...` forever.
You will start at the bus stop `source` (You... | null |
Solution | minimum-swaps-to-make-sequences-increasing | 1 | 1 | ```C++ []\nconst int ZERO = []() {\n ios_base::sync_with_stdio(false);\n cin.tie(nullptr);\n return 0;\n}();\nclass Solution {\npublic:\n int minSwap(vector<int>& a, vector<int>& b) {\n int n = static_cast<int>(a.size());\n vector<int> swaps(n, n);\n vector<int> noswaps(n, n);\n ... | 1 | You are given two integer arrays of the same length `nums1` and `nums2`. In one operation, you are allowed to swap `nums1[i]` with `nums2[i]`.
* For example, if `nums1 = [1,2,3,8]`, and `nums2 = [5,6,7,4]`, you can swap the element at `i = 3` to obtain `nums1 = [1,2,3,4]` and `nums2 = [5,6,7,8]`.
Return _the minimu... | null |
Solution | minimum-swaps-to-make-sequences-increasing | 1 | 1 | ```C++ []\nconst int ZERO = []() {\n ios_base::sync_with_stdio(false);\n cin.tie(nullptr);\n return 0;\n}();\nclass Solution {\npublic:\n int minSwap(vector<int>& a, vector<int>& b) {\n int n = static_cast<int>(a.size());\n vector<int> swaps(n, n);\n vector<int> noswaps(n, n);\n ... | 1 | Given a string `paragraph` and a string array of the banned words `banned`, return _the most frequent word that is not banned_. It is **guaranteed** there is **at least one word** that is not banned, and that the answer is **unique**.
The words in `paragraph` are **case-insensitive** and the answer should be returned ... | null |
✅ [Python3] DP Solution O(n) Time | minimum-swaps-to-make-sequences-increasing | 0 | 1 | ```\nclass Solution:\n def minSwap(self, nums1: List[int], nums2: List[int]) -> int:\n dp = [[-1]*2 for i in range(len(nums1))]\n \n def solve(prev1, prev2, i, swaped):\n if i >= len(nums1): return 0\n if dp[i][swaped] != -1: return dp[i][swaped]\n \n... | 4 | You are given two integer arrays of the same length `nums1` and `nums2`. In one operation, you are allowed to swap `nums1[i]` with `nums2[i]`.
* For example, if `nums1 = [1,2,3,8]`, and `nums2 = [5,6,7,4]`, you can swap the element at `i = 3` to obtain `nums1 = [1,2,3,4]` and `nums2 = [5,6,7,8]`.
Return _the minimu... | null |
✅ [Python3] DP Solution O(n) Time | minimum-swaps-to-make-sequences-increasing | 0 | 1 | ```\nclass Solution:\n def minSwap(self, nums1: List[int], nums2: List[int]) -> int:\n dp = [[-1]*2 for i in range(len(nums1))]\n \n def solve(prev1, prev2, i, swaped):\n if i >= len(nums1): return 0\n if dp[i][swaped] != -1: return dp[i][swaped]\n \n... | 4 | Given a string `paragraph` and a string array of the banned words `banned`, return _the most frequent word that is not banned_. It is **guaranteed** there is **at least one word** that is not banned, and that the answer is **unique**.
The words in `paragraph` are **case-insensitive** and the answer should be returned ... | null |
[Python 3] O(n) Time, O(1) Space, Detailed Explanation | minimum-swaps-to-make-sequences-increasing | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThere are 3 different cases to consider when looking at the border between two pairs of numbers (a pair being numbers in nums1 and nums2 with the same index):\n1. The numbers are increasing, and if either pair was flipped they would still... | 1 | You are given two integer arrays of the same length `nums1` and `nums2`. In one operation, you are allowed to swap `nums1[i]` with `nums2[i]`.
* For example, if `nums1 = [1,2,3,8]`, and `nums2 = [5,6,7,4]`, you can swap the element at `i = 3` to obtain `nums1 = [1,2,3,4]` and `nums2 = [5,6,7,8]`.
Return _the minimu... | null |
[Python 3] O(n) Time, O(1) Space, Detailed Explanation | minimum-swaps-to-make-sequences-increasing | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThere are 3 different cases to consider when looking at the border between two pairs of numbers (a pair being numbers in nums1 and nums2 with the same index):\n1. The numbers are increasing, and if either pair was flipped they would still... | 1 | Given a string `paragraph` and a string array of the banned words `banned`, return _the most frequent word that is not banned_. It is **guaranteed** there is **at least one word** that is not banned, and that the answer is **unique**.
The words in `paragraph` are **case-insensitive** and the answer should be returned ... | null |
[Python3] two counters | minimum-swaps-to-make-sequences-increasing | 0 | 1 | Algo \nThis solution is different from the mainstream solutions. Given that we know a solution exists, if we put larger of `A[i]` and `B[i]` to `A` and smaller of `A[i]` and `B[i]` to `B`. The resulting sequence satisfies the requirement of increasing `A` and increasing `B`. In the spirit of this idea, we can count the... | 9 | You are given two integer arrays of the same length `nums1` and `nums2`. In one operation, you are allowed to swap `nums1[i]` with `nums2[i]`.
* For example, if `nums1 = [1,2,3,8]`, and `nums2 = [5,6,7,4]`, you can swap the element at `i = 3` to obtain `nums1 = [1,2,3,4]` and `nums2 = [5,6,7,8]`.
Return _the minimu... | null |
[Python3] two counters | minimum-swaps-to-make-sequences-increasing | 0 | 1 | Algo \nThis solution is different from the mainstream solutions. Given that we know a solution exists, if we put larger of `A[i]` and `B[i]` to `A` and smaller of `A[i]` and `B[i]` to `B`. The resulting sequence satisfies the requirement of increasing `A` and increasing `B`. In the spirit of this idea, we can count the... | 9 | Given a string `paragraph` and a string array of the banned words `banned`, return _the most frequent word that is not banned_. It is **guaranteed** there is **at least one word** that is not banned, and that the answer is **unique**.
The words in `paragraph` are **case-insensitive** and the answer should be returned ... | null |
Clear Python o(n) Time, o(n) Space solution with comments | minimum-swaps-to-make-sequences-increasing | 0 | 1 | bottom up dp python solution with comments\n\nTime: o(n)\nSpace: o(n)\n\n\n```\nclass Solution:\n def minSwap(self, A: List[int], B: List[int]) -> int:\n \n n = len(A)\n \n # In this problem, we have two states that we need to keep track at element i; \n # what happens if we swap o... | 11 | You are given two integer arrays of the same length `nums1` and `nums2`. In one operation, you are allowed to swap `nums1[i]` with `nums2[i]`.
* For example, if `nums1 = [1,2,3,8]`, and `nums2 = [5,6,7,4]`, you can swap the element at `i = 3` to obtain `nums1 = [1,2,3,4]` and `nums2 = [5,6,7,8]`.
Return _the minimu... | null |
Clear Python o(n) Time, o(n) Space solution with comments | minimum-swaps-to-make-sequences-increasing | 0 | 1 | bottom up dp python solution with comments\n\nTime: o(n)\nSpace: o(n)\n\n\n```\nclass Solution:\n def minSwap(self, A: List[int], B: List[int]) -> int:\n \n n = len(A)\n \n # In this problem, we have two states that we need to keep track at element i; \n # what happens if we swap o... | 11 | Given a string `paragraph` and a string array of the banned words `banned`, return _the most frequent word that is not banned_. It is **guaranteed** there is **at least one word** that is not banned, and that the answer is **unique**.
The words in `paragraph` are **case-insensitive** and the answer should be returned ... | null |
Mark my solution | minimum-swaps-to-make-sequences-increasing | 0 | 1 | # 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 | You are given two integer arrays of the same length `nums1` and `nums2`. In one operation, you are allowed to swap `nums1[i]` with `nums2[i]`.
* For example, if `nums1 = [1,2,3,8]`, and `nums2 = [5,6,7,4]`, you can swap the element at `i = 3` to obtain `nums1 = [1,2,3,4]` and `nums2 = [5,6,7,8]`.
Return _the minimu... | null |
Mark my solution | minimum-swaps-to-make-sequences-increasing | 0 | 1 | # 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 | Given a string `paragraph` and a string array of the banned words `banned`, return _the most frequent word that is not banned_. It is **guaranteed** there is **at least one word** that is not banned, and that the answer is **unique**.
The words in `paragraph` are **case-insensitive** and the answer should be returned ... | null |
801: Solution with step by step explanation | minimum-swaps-to-make-sequences-increasing | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nBefore we start processing the arrays, we need to initialize our DP arrays:\n\n```\nkeep = [float(\'inf\')] * n \nswap = [float(\'inf\')] * n \nkeep[0] = 0 \nswap[0] = 1 \n```\nWe will loop over each index starting from ... | 0 | You are given two integer arrays of the same length `nums1` and `nums2`. In one operation, you are allowed to swap `nums1[i]` with `nums2[i]`.
* For example, if `nums1 = [1,2,3,8]`, and `nums2 = [5,6,7,4]`, you can swap the element at `i = 3` to obtain `nums1 = [1,2,3,4]` and `nums2 = [5,6,7,8]`.
Return _the minimu... | null |
801: Solution with step by step explanation | minimum-swaps-to-make-sequences-increasing | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nBefore we start processing the arrays, we need to initialize our DP arrays:\n\n```\nkeep = [float(\'inf\')] * n \nswap = [float(\'inf\')] * n \nkeep[0] = 0 \nswap[0] = 1 \n```\nWe will loop over each index starting from ... | 0 | Given a string `paragraph` and a string array of the banned words `banned`, return _the most frequent word that is not banned_. It is **guaranteed** there is **at least one word** that is not banned, and that the answer is **unique**.
The words in `paragraph` are **case-insensitive** and the answer should be returned ... | null |
topological sort | find-eventual-safe-states | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nstart with nodes that have no outgoing edges.These are terminal nodes.\n\n\n# Approach\n```\n1.mark all nodes with no outgoing edges. --->term\n2.store the count of outgoing edges from each node.-->d1\n3.create an adjacency list with reve... | 3 | There is a directed graph of `n` nodes with each node labeled from `0` to `n - 1`. The graph is represented by a **0-indexed** 2D integer array `graph` where `graph[i]` is an integer array of nodes adjacent to node `i`, meaning there is an edge from node `i` to each node in `graph[i]`.
A node is a **terminal node** if... | null |
topological sort | find-eventual-safe-states | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nstart with nodes that have no outgoing edges.These are terminal nodes.\n\n\n# Approach\n```\n1.mark all nodes with no outgoing edges. --->term\n2.store the count of outgoing edges from each node.-->d1\n3.create an adjacency list with reve... | 3 | A **valid encoding** of an array of `words` is any reference string `s` and array of indices `indices` such that:
* `words.length == indices.length`
* The reference string `s` ends with the `'#'` character.
* For each index `indices[i]`, the **substring** of `s` starting from `indices[i]` and up to (but not incl... | null |
Python3 Solution | find-eventual-safe-states | 0 | 1 | \n```\nclass Solution:\n def eventualSafeNodes(self, graph: List[List[int]]) -> List[int]:\n n=len(graph)\n safe={}\n ans=[]\n def dfs(i):\n if i in safe:\n return safe[i]\n\n safe[i]=False\n for nei in graph[i]:\n if not dfs(... | 16 | There is a directed graph of `n` nodes with each node labeled from `0` to `n - 1`. The graph is represented by a **0-indexed** 2D integer array `graph` where `graph[i]` is an integer array of nodes adjacent to node `i`, meaning there is an edge from node `i` to each node in `graph[i]`.
A node is a **terminal node** if... | null |
Python3 Solution | find-eventual-safe-states | 0 | 1 | \n```\nclass Solution:\n def eventualSafeNodes(self, graph: List[List[int]]) -> List[int]:\n n=len(graph)\n safe={}\n ans=[]\n def dfs(i):\n if i in safe:\n return safe[i]\n\n safe[i]=False\n for nei in graph[i]:\n if not dfs(... | 16 | A **valid encoding** of an array of `words` is any reference string `s` and array of indices `indices` such that:
* `words.length == indices.length`
* The reference string `s` ends with the `'#'` character.
* For each index `indices[i]`, the **substring** of `s` starting from `indices[i]` and up to (but not incl... | null |
Python short and clean. Topological sort. Functional programming. | find-eventual-safe-states | 0 | 1 | # Complexity\n- Time complexity: $$O(n + e)$$\n\n- Space complexity: $$O(n + e)$$\n\nwhere,\n`n is number of nodes in graph`,\n`e is number of edges in graph`.\n\n# Code\n```python\nclass Solution:\n def eventualSafeNodes(self, graph: list[list[int]]) -> list[int]:\n DiGraph = list[list[int]]\n\n def f... | 1 | There is a directed graph of `n` nodes with each node labeled from `0` to `n - 1`. The graph is represented by a **0-indexed** 2D integer array `graph` where `graph[i]` is an integer array of nodes adjacent to node `i`, meaning there is an edge from node `i` to each node in `graph[i]`.
A node is a **terminal node** if... | null |
Python short and clean. Topological sort. Functional programming. | find-eventual-safe-states | 0 | 1 | # Complexity\n- Time complexity: $$O(n + e)$$\n\n- Space complexity: $$O(n + e)$$\n\nwhere,\n`n is number of nodes in graph`,\n`e is number of edges in graph`.\n\n# Code\n```python\nclass Solution:\n def eventualSafeNodes(self, graph: list[list[int]]) -> list[int]:\n DiGraph = list[list[int]]\n\n def f... | 1 | A **valid encoding** of an array of `words` is any reference string `s` and array of indices `indices` such that:
* `words.length == indices.length`
* The reference string `s` ends with the `'#'` character.
* For each index `indices[i]`, the **substring** of `s` starting from `indices[i]` and up to (but not incl... | null |
BEATS 99.12% IN SPACE OPTIMIZATION || EASY PYTHON SOLUTION | find-eventual-safe-states | 0 | 1 | # Code\n```\nclass Solution:\n def soln(self,node,graph,lst,visited):\n visited[node]=0\n ans=1\n for i in graph[node]:\n if visited[i]==-1:\n ans&=self.soln(i,graph,lst,visited)\n else:\n ans&=visited[i]\n # print(node,ans)\n vis... | 1 | There is a directed graph of `n` nodes with each node labeled from `0` to `n - 1`. The graph is represented by a **0-indexed** 2D integer array `graph` where `graph[i]` is an integer array of nodes adjacent to node `i`, meaning there is an edge from node `i` to each node in `graph[i]`.
A node is a **terminal node** if... | null |
BEATS 99.12% IN SPACE OPTIMIZATION || EASY PYTHON SOLUTION | find-eventual-safe-states | 0 | 1 | # Code\n```\nclass Solution:\n def soln(self,node,graph,lst,visited):\n visited[node]=0\n ans=1\n for i in graph[node]:\n if visited[i]==-1:\n ans&=self.soln(i,graph,lst,visited)\n else:\n ans&=visited[i]\n # print(node,ans)\n vis... | 1 | A **valid encoding** of an array of `words` is any reference string `s` and array of indices `indices` such that:
* `words.length == indices.length`
* The reference string `s` ends with the `'#'` character.
* For each index `indices[i]`, the **substring** of `s` starting from `indices[i]` and up to (but not incl... | null |
🔥Best [C++,JAVA,🐍] Code🌟 || 🔥Commented || DFS💯 | find-eventual-safe-states | 1 | 1 | ### Connect with me on LinkedIn : https://www.linkedin.com/in/aditya-jhunjhunwala-51b586195/\n# Intuition\n#### The code is based on the concept of finding eventual safe nodes in a directed graph. Here\'s the intuition behind the approach:\n\n1. The function `DFS` performs a depth-first search starting from a node `s` ... | 24 | There is a directed graph of `n` nodes with each node labeled from `0` to `n - 1`. The graph is represented by a **0-indexed** 2D integer array `graph` where `graph[i]` is an integer array of nodes adjacent to node `i`, meaning there is an edge from node `i` to each node in `graph[i]`.
A node is a **terminal node** if... | null |
🔥Best [C++,JAVA,🐍] Code🌟 || 🔥Commented || DFS💯 | find-eventual-safe-states | 1 | 1 | ### Connect with me on LinkedIn : https://www.linkedin.com/in/aditya-jhunjhunwala-51b586195/\n# Intuition\n#### The code is based on the concept of finding eventual safe nodes in a directed graph. Here\'s the intuition behind the approach:\n\n1. The function `DFS` performs a depth-first search starting from a node `s` ... | 24 | A **valid encoding** of an array of `words` is any reference string `s` and array of indices `indices` such that:
* `words.length == indices.length`
* The reference string `s` ends with the `'#'` character.
* For each index `indices[i]`, the **substring** of `s` starting from `indices[i]` and up to (but not incl... | null |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.