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
✔️[Python3] UNPRECENDENT NUMBER OF COUNTERS o͡͡͡͡͡͡͡͡͡͡͡͡͡͡╮(。❛ᴗ❛。)╭o͡͡͡͡͡͡͡͡͡͡͡͡͡͡, Explained
minimum-domino-rotations-for-equal-row
0
1
**UPVOTE if you like (\uD83C\uDF38\u25E0\u203F\u25E0), If you have any question, feel free to ask.**\n\nTo be able to make all values the same on the top or bottom, the given dominos should have enough number of same values. So we need to compare the frequency of values on the top and bottom. If there are enough, say `...
23
In a row of dominoes, `tops[i]` and `bottoms[i]` represent the top and bottom halves of the `ith` domino. (A domino is a tile with two numbers from 1 to 6 - one on each half of the tile.) We may rotate the `ith` domino, so that `tops[i]` and `bottoms[i]` swap values. Return the minimum number of rotations so that all...
null
✔️[Python3] UNPRECENDENT NUMBER OF COUNTERS o͡͡͡͡͡͡͡͡͡͡͡͡͡͡╮(。❛ᴗ❛。)╭o͡͡͡͡͡͡͡͡͡͡͡͡͡͡, Explained
minimum-domino-rotations-for-equal-row
0
1
**UPVOTE if you like (\uD83C\uDF38\u25E0\u203F\u25E0), If you have any question, feel free to ask.**\n\nTo be able to make all values the same on the top or bottom, the given dominos should have enough number of same values. So we need to compare the frequency of values on the top and bottom. If there are enough, say `...
23
You are given an array of integers `stones` where `stones[i]` is the weight of the `ith` stone. We are playing a game with the stones. On each turn, we choose any two stones and smash them together. Suppose the stones have weights `x` and `y` with `x <= y`. The result of this smash is: * If `x == y`, both stones ar...
null
Simple in Python
minimum-domino-rotations-for-equal-row
0
1
# Intuition\nThe intuition is that we need to figure out the most common number in both arrays, as that will be the number at either top or bottom after the swaps. \n\nWe also need to make sure that the most common number is in either tops[i] or bottoms[i], because if it is not, then we know we can return -1.\n\nFinall...
1
In a row of dominoes, `tops[i]` and `bottoms[i]` represent the top and bottom halves of the `ith` domino. (A domino is a tile with two numbers from 1 to 6 - one on each half of the tile.) We may rotate the `ith` domino, so that `tops[i]` and `bottoms[i]` swap values. Return the minimum number of rotations so that all...
null
Simple in Python
minimum-domino-rotations-for-equal-row
0
1
# Intuition\nThe intuition is that we need to figure out the most common number in both arrays, as that will be the number at either top or bottom after the swaps. \n\nWe also need to make sure that the most common number is in either tops[i] or bottoms[i], because if it is not, then we know we can return -1.\n\nFinall...
1
You are given an array of integers `stones` where `stones[i]` is the weight of the `ith` stone. We are playing a game with the stones. On each turn, we choose any two stones and smash them together. Suppose the stones have weights `x` and `y` with `x <= y`. The result of this smash is: * If `x == y`, both stones ar...
null
[ Python ] ✔✔ Simple Python Solution Using Dictionary or Hashmap || O(n) 🔥✌
minimum-domino-rotations-for-equal-row
0
1
# If It is Useful to Understand Please Upvote Me \uD83D\uDE4F\uD83D\uDE4F\n# Runtime: 1184 ms, faster than 85.42% of Python3 online submissions for Minimum Domino Rotations For Equal Row.\n# Memory Usage: 15.3 MB, less than 22.57% of Python3 online submissions for Minimum Domino Rotations For Equal Row.\n# Time Complex...
3
In a row of dominoes, `tops[i]` and `bottoms[i]` represent the top and bottom halves of the `ith` domino. (A domino is a tile with two numbers from 1 to 6 - one on each half of the tile.) We may rotate the `ith` domino, so that `tops[i]` and `bottoms[i]` swap values. Return the minimum number of rotations so that all...
null
[ Python ] ✔✔ Simple Python Solution Using Dictionary or Hashmap || O(n) 🔥✌
minimum-domino-rotations-for-equal-row
0
1
# If It is Useful to Understand Please Upvote Me \uD83D\uDE4F\uD83D\uDE4F\n# Runtime: 1184 ms, faster than 85.42% of Python3 online submissions for Minimum Domino Rotations For Equal Row.\n# Memory Usage: 15.3 MB, less than 22.57% of Python3 online submissions for Minimum Domino Rotations For Equal Row.\n# Time Complex...
3
You are given an array of integers `stones` where `stones[i]` is the weight of the `ith` stone. We are playing a game with the stones. On each turn, we choose any two stones and smash them together. Suppose the stones have weights `x` and `y` with `x <= y`. The result of this smash is: * If `x == y`, both stones ar...
null
Python simple and easy intuitive explained solution
minimum-domino-rotations-for-equal-row
0
1
```\nclass Solution:\n def minDominoRotations(self, A: List[int], B: List[int]) -> int:\n def countDifference(A, B, num):\n countA, countB = 0, 0\n \n for i in range(len(A)):\n # if we have a domino which doesn\'t have num at all, num can\'t be the whole row:\n ...
8
In a row of dominoes, `tops[i]` and `bottoms[i]` represent the top and bottom halves of the `ith` domino. (A domino is a tile with two numbers from 1 to 6 - one on each half of the tile.) We may rotate the `ith` domino, so that `tops[i]` and `bottoms[i]` swap values. Return the minimum number of rotations so that all...
null
Python simple and easy intuitive explained solution
minimum-domino-rotations-for-equal-row
0
1
```\nclass Solution:\n def minDominoRotations(self, A: List[int], B: List[int]) -> int:\n def countDifference(A, B, num):\n countA, countB = 0, 0\n \n for i in range(len(A)):\n # if we have a domino which doesn\'t have num at all, num can\'t be the whole row:\n ...
8
You are given an array of integers `stones` where `stones[i]` is the weight of the `ith` stone. We are playing a game with the stones. On each turn, we choose any two stones and smash them together. Suppose the stones have weights `x` and `y` with `x <= y`. The result of this smash is: * If `x == y`, both stones ar...
null
Use Sets for Easily Solving It
minimum-domino-rotations-for-equal-row
0
1
**Time & Space:**\n![image](https://assets.leetcode.com/users/images/aa0f9793-2bbf-405c-bff5-5cbf308bccc7_1647836359.417393.png)\n\n**Intution:**\nThe questions essentially boils down weather their exists a common element b/w all the indices and where to keep that value that is on the top array or the bottom one. Somet...
2
In a row of dominoes, `tops[i]` and `bottoms[i]` represent the top and bottom halves of the `ith` domino. (A domino is a tile with two numbers from 1 to 6 - one on each half of the tile.) We may rotate the `ith` domino, so that `tops[i]` and `bottoms[i]` swap values. Return the minimum number of rotations so that all...
null
Use Sets for Easily Solving It
minimum-domino-rotations-for-equal-row
0
1
**Time & Space:**\n![image](https://assets.leetcode.com/users/images/aa0f9793-2bbf-405c-bff5-5cbf308bccc7_1647836359.417393.png)\n\n**Intution:**\nThe questions essentially boils down weather their exists a common element b/w all the indices and where to keep that value that is on the top array or the bottom one. Somet...
2
You are given an array of integers `stones` where `stones[i]` is the weight of the `ith` stone. We are playing a game with the stones. On each turn, we choose any two stones and smash them together. Suppose the stones have weights `x` and `y` with `x <= y`. The result of this smash is: * If `x == y`, both stones ar...
null
Superb logic
construct-binary-search-tree-from-preorder-traversal
0
1
```\nclass Solution:\n def bstFromPreorder(self, preorder: List[int]) -> Optional[TreeNode]:\n inorder=sorted(preorder)\n def build(preorder,inorder):\n if not preorder or not inorder:\n return \n root=TreeNode(preorder[0])\n mid=inorder.index(preorder[0]...
4
Given an array of integers preorder, which represents the **preorder traversal** of a BST (i.e., **binary search tree**), construct the tree and return _its root_. It is **guaranteed** that there is always possible to find a binary search tree with the given requirements for the given test cases. A **binary search tr...
null
Python Easy Solution
construct-binary-search-tree-from-preorder-traversal
0
1
# Python3 Solution\n```\nclass TreeNode:\n def __init__(self, val=0, left=None, right=None):\n self.val = val\n self.left = left\n self.right = right\n\nclass Solution:\n def bstFromPreorder(self, preorder: List[int]) -> Optional[TreeNode]:\n if len(preorder) == 0:\n return ...
1
Given an array of integers preorder, which represents the **preorder traversal** of a BST (i.e., **binary search tree**), construct the tree and return _its root_. It is **guaranteed** that there is always possible to find a binary search tree with the given requirements for the given test cases. A **binary search tr...
null
Python || Easy || Recursive Solution
construct-binary-search-tree-from-preorder-traversal
0
1
```\ndef bstFromPreorder(self, preorder: List[int]) -> Optional[TreeNode]:\n i=[0]\n def construct(preorder,i,bound):\n if i[0]==len(preorder) or preorder[i[0]]>bound:\n return None\n root=TreeNode(preorder[i[0]])\n i[0]+=1\n root.left=construct(p...
2
Given an array of integers preorder, which represents the **preorder traversal** of a BST (i.e., **binary search tree**), construct the tree and return _its root_. It is **guaranteed** that there is always possible to find a binary search tree with the given requirements for the given test cases. A **binary search tr...
null
Beginner-friendly || Construct a TreeNode with using list comprehension in Python3
construct-binary-search-tree-from-preorder-traversal
0
1
# Intuition\nThe problem description is the following:\n- there\'s a list of nodes, that\'re placed by **preorder traversal**\n- we need to construct a **Binary Search Tree** from this list\n\n```py\n# Example\nnodes = [2, 1, 3]\n# 1. The list of nodes will represent the following BST:\n# (2)\n# / \\\n# (1) (3)\...
1
Given an array of integers preorder, which represents the **preorder traversal** of a BST (i.e., **binary search tree**), construct the tree and return _its root_. It is **guaranteed** that there is always possible to find a binary search tree with the given requirements for the given test cases. A **binary search tr...
null
Python 3, Recursive, Easy to understand
construct-binary-search-tree-from-preorder-traversal
0
1
```\nclass Solution:\n def bstFromPreorder(self, preorder: List[int]) -> TreeNode:\n if not preorder:\n return None\n root = TreeNode(preorder[0])\n i = 1\n while i<len(preorder) and preorder[i] < root.val:\n i+=1\n root.left = self.bstFromPreorder(preorder[1...
77
Given an array of integers preorder, which represents the **preorder traversal** of a BST (i.e., **binary search tree**), construct the tree and return _its root_. It is **guaranteed** that there is always possible to find a binary search tree with the given requirements for the given test cases. A **binary search tr...
null
Solution
construct-binary-search-tree-from-preorder-traversal
1
1
```C++ []\nclass Solution {\npublic:\n void BST(TreeNode* root,int x){\n while(1){\n if(root->val<x){\n if(root->right==NULL){\n TreeNode* new_node=new TreeNode(x);\n root->right=new_node;\n return;\n }\n ...
2
Given an array of integers preorder, which represents the **preorder traversal** of a BST (i.e., **binary search tree**), construct the tree and return _its root_. It is **guaranteed** that there is always possible to find a binary search tree with the given requirements for the given test cases. A **binary search tr...
null
Solution
complement-of-base-10-integer
1
1
```C++ []\nclass Solution {\n public:\n int bitwiseComplement(int N) {\n int mask = 1;\n\n while (mask < N)\n mask = (mask << 1) + 1;\n\n return mask ^ N;\n }\n};\n```\n\n```Python3 []\nclass Solution:\n def bitwiseComplement(self, n: int) -> int:\n cnt=0\n ans=0\n if n==0:\n ...
456
The **complement** of an integer is the integer you get when you flip all the `0`'s to `1`'s and all the `1`'s to `0`'s in its binary representation. * For example, The integer `5` is `"101 "` in binary and its **complement** is `"010 "` which is the integer `2`. Given an integer `n`, return _its complement_. **Ex...
null
Solution
complement-of-base-10-integer
1
1
```C++ []\nclass Solution {\n public:\n int bitwiseComplement(int N) {\n int mask = 1;\n\n while (mask < N)\n mask = (mask << 1) + 1;\n\n return mask ^ N;\n }\n};\n```\n\n```Python3 []\nclass Solution:\n def bitwiseComplement(self, n: int) -> int:\n cnt=0\n ans=0\n if n==0:\n ...
456
In a warehouse, there is a row of barcodes, where the `ith` barcode is `barcodes[i]`. Rearrange the barcodes so that no two adjacent barcodes are equal. You may return any answer, and it is guaranteed an answer exists. **Example 1:** **Input:** barcodes = \[1,1,1,2,2,2\] **Output:** \[2,1,2,1,2,1\] **Example 2:** ...
A binary number plus its complement will equal 111....111 in binary. Also, N = 0 is a corner case.
2 Solutions one-liner beat 90.93% 26ms Python3
complement-of-base-10-integer
0
1
\n\n# Code\n```\nclass Solution:\n def bitwiseComplement(self, n: int) -> int:\n return (int((bin(n)[2:]).replace(\'1\', \'2\').replace(\'0\',\'1\').replace(\'2\',\'0\'),2))\n\n return (int((bin(n)[2:]).translate(str.maketrans("01", "10")),2))\n```
1
The **complement** of an integer is the integer you get when you flip all the `0`'s to `1`'s and all the `1`'s to `0`'s in its binary representation. * For example, The integer `5` is `"101 "` in binary and its **complement** is `"010 "` which is the integer `2`. Given an integer `n`, return _its complement_. **Ex...
null
2 Solutions one-liner beat 90.93% 26ms Python3
complement-of-base-10-integer
0
1
\n\n# Code\n```\nclass Solution:\n def bitwiseComplement(self, n: int) -> int:\n return (int((bin(n)[2:]).replace(\'1\', \'2\').replace(\'0\',\'1\').replace(\'2\',\'0\'),2))\n\n return (int((bin(n)[2:]).translate(str.maketrans("01", "10")),2))\n```
1
In a warehouse, there is a row of barcodes, where the `ith` barcode is `barcodes[i]`. Rearrange the barcodes so that no two adjacent barcodes are equal. You may return any answer, and it is guaranteed an answer exists. **Example 1:** **Input:** barcodes = \[1,1,1,2,2,2\] **Output:** \[2,1,2,1,2,1\] **Example 2:** ...
A binary number plus its complement will equal 111....111 in binary. Also, N = 0 is a corner case.
Python 2 Approach 97.96% beats
complement-of-base-10-integer
0
1
**If you got help from this,... Plz Upvote .. it encourage me**\n# EXAMPLE , \n # N = 101 (5)\n # MASK WILL BE 111 (7)\n # COMPLEMENT MASK - N = 7-5 = 2 (010)\n# Code\n```\n<!-- 1ST APPROACH -->\nclass Solution:\n def bitwiseComplement(self, n: int) -> int:\n \n if n == 0:\n ...
2
The **complement** of an integer is the integer you get when you flip all the `0`'s to `1`'s and all the `1`'s to `0`'s in its binary representation. * For example, The integer `5` is `"101 "` in binary and its **complement** is `"010 "` which is the integer `2`. Given an integer `n`, return _its complement_. **Ex...
null
Python 2 Approach 97.96% beats
complement-of-base-10-integer
0
1
**If you got help from this,... Plz Upvote .. it encourage me**\n# EXAMPLE , \n # N = 101 (5)\n # MASK WILL BE 111 (7)\n # COMPLEMENT MASK - N = 7-5 = 2 (010)\n# Code\n```\n<!-- 1ST APPROACH -->\nclass Solution:\n def bitwiseComplement(self, n: int) -> int:\n \n if n == 0:\n ...
2
In a warehouse, there is a row of barcodes, where the `ith` barcode is `barcodes[i]`. Rearrange the barcodes so that no two adjacent barcodes are equal. You may return any answer, and it is guaranteed an answer exists. **Example 1:** **Input:** barcodes = \[1,1,1,2,2,2\] **Output:** \[2,1,2,1,2,1\] **Example 2:** ...
A binary number plus its complement will equal 111....111 in binary. Also, N = 0 is a corner case.
Beginner Friendly Python || Beats 91%
complement-of-base-10-integer
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. -->\nLet\'s assume a number, say 10. \n\n```\nBinary version = 1010\nComplement = 0101\nInteger compelement = 5\n```\n\n```\nmask is initially 0,\nTill m = 10 (1010) is not...
2
The **complement** of an integer is the integer you get when you flip all the `0`'s to `1`'s and all the `1`'s to `0`'s in its binary representation. * For example, The integer `5` is `"101 "` in binary and its **complement** is `"010 "` which is the integer `2`. Given an integer `n`, return _its complement_. **Ex...
null
Beginner Friendly Python || Beats 91%
complement-of-base-10-integer
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. -->\nLet\'s assume a number, say 10. \n\n```\nBinary version = 1010\nComplement = 0101\nInteger compelement = 5\n```\n\n```\nmask is initially 0,\nTill m = 10 (1010) is not...
2
In a warehouse, there is a row of barcodes, where the `ith` barcode is `barcodes[i]`. Rearrange the barcodes so that no two adjacent barcodes are equal. You may return any answer, and it is guaranteed an answer exists. **Example 1:** **Input:** barcodes = \[1,1,1,2,2,2\] **Output:** \[2,1,2,1,2,1\] **Example 2:** ...
A binary number plus its complement will equal 111....111 in binary. Also, N = 0 is a corner case.
Solution
pairs-of-songs-with-total-durations-divisible-by-60
1
1
```C++ []\nclass Solution {\npublic:\n int numPairsDivisibleBy60(vector<int>& time) {\n vector<int> remainders(60);\n int count = 0;\n for(int t : time) {\n if(t % 60 == 0) count += remainders[0];\n\n else count += remainders[60 - t % 60]; \n\n remainders[t % 60]++...
1
You are given a list of songs where the `ith` song has a duration of `time[i]` seconds. Return _the number of pairs of songs for which their total duration in seconds is divisible by_ `60`. Formally, we want the number of indices `i`, `j` such that `i < j` with `(time[i] + time[j]) % 60 == 0`. **Example 1:** **Input...
null
Solution
pairs-of-songs-with-total-durations-divisible-by-60
1
1
```C++ []\nclass Solution {\npublic:\n int numPairsDivisibleBy60(vector<int>& time) {\n vector<int> remainders(60);\n int count = 0;\n for(int t : time) {\n if(t % 60 == 0) count += remainders[0];\n\n else count += remainders[60 - t % 60]; \n\n remainders[t % 60]++...
1
A **subsequence** of a string is a new string that is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (i.e., `"ace "` is a subsequence of `"abcde "` while `"aec "` is not). Given two strings `source` and `target`, r...
We only need to consider each song length modulo 60. We can count the number of songs with (length % 60) equal to r, and store that in an array of size 60.
[LC-1010-M | Python3] A Plain Solution
pairs-of-songs-with-total-durations-divisible-by-60
0
1
Note that `i > j` is symmetric with `i < j` for calculation.\nTC: $\\Omicron(n)$ | SC: $\\Omicron(n)$, where `n = len(time)`.\n \n```Python3 []\nclass Solution:\n def numPairsDivisibleBy60(self, time: List[int]) -> int:\n cnter = defaultdict(int)\n res = 0\n for t in time:\n t %= 60\n...
1
You are given a list of songs where the `ith` song has a duration of `time[i]` seconds. Return _the number of pairs of songs for which their total duration in seconds is divisible by_ `60`. Formally, we want the number of indices `i`, `j` such that `i < j` with `(time[i] + time[j]) % 60 == 0`. **Example 1:** **Input...
null
[LC-1010-M | Python3] A Plain Solution
pairs-of-songs-with-total-durations-divisible-by-60
0
1
Note that `i > j` is symmetric with `i < j` for calculation.\nTC: $\\Omicron(n)$ | SC: $\\Omicron(n)$, where `n = len(time)`.\n \n```Python3 []\nclass Solution:\n def numPairsDivisibleBy60(self, time: List[int]) -> int:\n cnter = defaultdict(int)\n res = 0\n for t in time:\n t %= 60\n...
1
A **subsequence** of a string is a new string that is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (i.e., `"ace "` is a subsequence of `"abcde "` while `"aec "` is not). Given two strings `source` and `target`, r...
We only need to consider each song length modulo 60. We can count the number of songs with (length % 60) equal to r, and store that in an array of size 60.
99% Faster || Python3 ||
pairs-of-songs-with-total-durations-divisible-by-60
0
1
class Solution:\n def numPairsDivisibleBy60(self, time: List[int]) -> int: \n\t \n\t\trem={}\n count=0\n for x in time:\n r=x%60\n if r in rem:\n rem[r]=rem[r]+1\n else:\n rem[r]=1 \n if 0 in rem:\n n=rem[0]\n ...
1
You are given a list of songs where the `ith` song has a duration of `time[i]` seconds. Return _the number of pairs of songs for which their total duration in seconds is divisible by_ `60`. Formally, we want the number of indices `i`, `j` such that `i < j` with `(time[i] + time[j]) % 60 == 0`. **Example 1:** **Input...
null
99% Faster || Python3 ||
pairs-of-songs-with-total-durations-divisible-by-60
0
1
class Solution:\n def numPairsDivisibleBy60(self, time: List[int]) -> int: \n\t \n\t\trem={}\n count=0\n for x in time:\n r=x%60\n if r in rem:\n rem[r]=rem[r]+1\n else:\n rem[r]=1 \n if 0 in rem:\n n=rem[0]\n ...
1
A **subsequence** of a string is a new string that is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (i.e., `"ace "` is a subsequence of `"abcde "` while `"aec "` is not). Given two strings `source` and `target`, r...
We only need to consider each song length modulo 60. We can count the number of songs with (length % 60) equal to r, and store that in an array of size 60.
Python : HashMap/Dictionary | Complexity O(n)
pairs-of-songs-with-total-durations-divisible-by-60
0
1
```\nclass Solution:\n def numPairsDivisibleBy60(self, time: List[int]) -> int:\n HashMap = {}\n pairs = 0\n \n for t in time:\n numMod = t % 60\n \n if numMod == 0:\n if 0 in HashMap:\n pairs += HashMap[0]\n el...
23
You are given a list of songs where the `ith` song has a duration of `time[i]` seconds. Return _the number of pairs of songs for which their total duration in seconds is divisible by_ `60`. Formally, we want the number of indices `i`, `j` such that `i < j` with `(time[i] + time[j]) % 60 == 0`. **Example 1:** **Input...
null
Python : HashMap/Dictionary | Complexity O(n)
pairs-of-songs-with-total-durations-divisible-by-60
0
1
```\nclass Solution:\n def numPairsDivisibleBy60(self, time: List[int]) -> int:\n HashMap = {}\n pairs = 0\n \n for t in time:\n numMod = t % 60\n \n if numMod == 0:\n if 0 in HashMap:\n pairs += HashMap[0]\n el...
23
A **subsequence** of a string is a new string that is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (i.e., `"ace "` is a subsequence of `"abcde "` while `"aec "` is not). Given two strings `source` and `target`, r...
We only need to consider each song length modulo 60. We can count the number of songs with (length % 60) equal to r, and store that in an array of size 60.
Python | HashMap | O(n) Time and Space | 80% T 75% S
pairs-of-songs-with-total-durations-divisible-by-60
0
1
We only need to consider song length modulo 60. \n\nFor every pair(a, b) we know a + b should = 60 to count as valid. \nSolving for a, we get 60 - b which we can hash and use to check against the rest of the array to generate the number of valid pairs.\n\nTo handle the case where pair(a % 60 = 0, b % 60 = 0) ex. (60,12...
3
You are given a list of songs where the `ith` song has a duration of `time[i]` seconds. Return _the number of pairs of songs for which their total duration in seconds is divisible by_ `60`. Formally, we want the number of indices `i`, `j` such that `i < j` with `(time[i] + time[j]) % 60 == 0`. **Example 1:** **Input...
null
Python | HashMap | O(n) Time and Space | 80% T 75% S
pairs-of-songs-with-total-durations-divisible-by-60
0
1
We only need to consider song length modulo 60. \n\nFor every pair(a, b) we know a + b should = 60 to count as valid. \nSolving for a, we get 60 - b which we can hash and use to check against the rest of the array to generate the number of valid pairs.\n\nTo handle the case where pair(a % 60 = 0, b % 60 = 0) ex. (60,12...
3
A **subsequence** of a string is a new string that is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (i.e., `"ace "` is a subsequence of `"abcde "` while `"aec "` is not). Given two strings `source` and `target`, r...
We only need to consider each song length modulo 60. We can count the number of songs with (length % 60) equal to r, and store that in an array of size 60.
Python Solution
pairs-of-songs-with-total-durations-divisible-by-60
0
1
```\nclass Solution:\n def numPairsDivisibleBy60(self, time: List[int]) -> int:\n arr=[0]*60\n count=0\n for i in range(len(time)):\n temp=time[i]%60\n count+=arr[-temp%60]\n arr[temp]+=1\n return count\n```
1
You are given a list of songs where the `ith` song has a duration of `time[i]` seconds. Return _the number of pairs of songs for which their total duration in seconds is divisible by_ `60`. Formally, we want the number of indices `i`, `j` such that `i < j` with `(time[i] + time[j]) % 60 == 0`. **Example 1:** **Input...
null
Python Solution
pairs-of-songs-with-total-durations-divisible-by-60
0
1
```\nclass Solution:\n def numPairsDivisibleBy60(self, time: List[int]) -> int:\n arr=[0]*60\n count=0\n for i in range(len(time)):\n temp=time[i]%60\n count+=arr[-temp%60]\n arr[temp]+=1\n return count\n```
1
A **subsequence** of a string is a new string that is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (i.e., `"ace "` is a subsequence of `"abcde "` while `"aec "` is not). Given two strings `source` and `target`, r...
We only need to consider each song length modulo 60. We can count the number of songs with (length % 60) equal to r, and store that in an array of size 60.
Python O(n) 6 Lines beats 86% time
pairs-of-songs-with-total-durations-divisible-by-60
0
1
```python\nclass Solution:\n def numPairsDivisibleBy60(self, time: List[int]) -> int:\n res , count = 0, [0] * 60\n for one in range(len(time)):\n index = time[one] % 60\n res += count[(60 - index)%60] # %60 is for index==0\n count[index] += 1\n return res\n``...
30
You are given a list of songs where the `ith` song has a duration of `time[i]` seconds. Return _the number of pairs of songs for which their total duration in seconds is divisible by_ `60`. Formally, we want the number of indices `i`, `j` such that `i < j` with `(time[i] + time[j]) % 60 == 0`. **Example 1:** **Input...
null
Python O(n) 6 Lines beats 86% time
pairs-of-songs-with-total-durations-divisible-by-60
0
1
```python\nclass Solution:\n def numPairsDivisibleBy60(self, time: List[int]) -> int:\n res , count = 0, [0] * 60\n for one in range(len(time)):\n index = time[one] % 60\n res += count[(60 - index)%60] # %60 is for index==0\n count[index] += 1\n return res\n``...
30
A **subsequence** of a string is a new string that is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (i.e., `"ace "` is a subsequence of `"abcde "` while `"aec "` is not). Given two strings `source` and `target`, r...
We only need to consider each song length modulo 60. We can count the number of songs with (length % 60) equal to r, and store that in an array of size 60.
✔️[Python3] HASHMAP, °‿‿° Explained
pairs-of-songs-with-total-durations-divisible-by-60
0
1
We can notice that to find a pair that is divisible by 60 we need to find two songs that have the sum of their modulo equal to 60 or 0. For example for 20 and 100 we have `20%60=20` and `100%60=40`, i.e. their modulo add up to 60, thus thees pair satisfy the condition. So we can create a hashmap where a key is `time[i]...
8
You are given a list of songs where the `ith` song has a duration of `time[i]` seconds. Return _the number of pairs of songs for which their total duration in seconds is divisible by_ `60`. Formally, we want the number of indices `i`, `j` such that `i < j` with `(time[i] + time[j]) % 60 == 0`. **Example 1:** **Input...
null
✔️[Python3] HASHMAP, °‿‿° Explained
pairs-of-songs-with-total-durations-divisible-by-60
0
1
We can notice that to find a pair that is divisible by 60 we need to find two songs that have the sum of their modulo equal to 60 or 0. For example for 20 and 100 we have `20%60=20` and `100%60=40`, i.e. their modulo add up to 60, thus thees pair satisfy the condition. So we can create a hashmap where a key is `time[i]...
8
A **subsequence** of a string is a new string that is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (i.e., `"ace "` is a subsequence of `"abcde "` while `"aec "` is not). Given two strings `source` and `target`, r...
We only need to consider each song length modulo 60. We can count the number of songs with (length % 60) equal to r, and store that in an array of size 60.
🔥Easy Binary Search Explanation🔥
capacity-to-ship-packages-within-d-days
0
1
# Intuition\r\nSuppose we know capacity `x` doesn\'t work, then we know that we should try a capacity greater than `x`. We can stop checking capacities less than `x`.\r\n\r\nIf we know capacity `y` works, we need to check capacities less than `y` to see if there\'s a smaller capacity that also works. We no longer need ...
4
A conveyor belt has packages that must be shipped from one port to another within `days` days. The `ith` package on the conveyor belt has a weight of `weights[i]`. Each day, we load the ship with packages on the conveyor belt (in the order given by `weights`). We may not load more weight than the maximum weight capaci...
null
🔥Easy Binary Search Explanation🔥
capacity-to-ship-packages-within-d-days
0
1
# Intuition\r\nSuppose we know capacity `x` doesn\'t work, then we know that we should try a capacity greater than `x`. We can stop checking capacities less than `x`.\r\n\r\nIf we know capacity `y` works, we need to check capacities less than `y` to see if there\'s a smaller capacity that also works. We no longer need ...
4
A **confusing number** is a number that when rotated `180` degrees becomes a different number with **each digit valid**. We can rotate digits of a number by `180` degrees to form new digits. * When `0`, `1`, `6`, `8`, and `9` are rotated `180` degrees, they become `0`, `1`, `9`, `8`, and `6` respectively. * When ...
Binary search on the answer. We need a function possible(capacity) which returns true if and only if we can do the task in D days.
Solution
capacity-to-ship-packages-within-d-days
1
1
```C++ []\r\nclass Solution {\r\npublic:\r\n int shipWithinDays(vector<int>& weights, int days) {\r\n if (weights.size() == 0)\r\n\t\t\treturn 0;\r\n\r\n\t\tif (weights.size() < days)\r\n\t\t\treturn 0;\r\n\r\n\t\tint minVal = weights[0], maxVal = 0;\r\n\t\tfor (auto& elem : weights)\r\n\t\t{\r\n\t\t\tif (ele...
1
A conveyor belt has packages that must be shipped from one port to another within `days` days. The `ith` package on the conveyor belt has a weight of `weights[i]`. Each day, we load the ship with packages on the conveyor belt (in the order given by `weights`). We may not load more weight than the maximum weight capaci...
null
Solution
capacity-to-ship-packages-within-d-days
1
1
```C++ []\r\nclass Solution {\r\npublic:\r\n int shipWithinDays(vector<int>& weights, int days) {\r\n if (weights.size() == 0)\r\n\t\t\treturn 0;\r\n\r\n\t\tif (weights.size() < days)\r\n\t\t\treturn 0;\r\n\r\n\t\tint minVal = weights[0], maxVal = 0;\r\n\t\tfor (auto& elem : weights)\r\n\t\t{\r\n\t\t\tif (ele...
1
A **confusing number** is a number that when rotated `180` degrees becomes a different number with **each digit valid**. We can rotate digits of a number by `180` degrees to form new digits. * When `0`, `1`, `6`, `8`, and `9` are rotated `180` degrees, they become `0`, `1`, `9`, `8`, and `6` respectively. * When ...
Binary search on the answer. We need a function possible(capacity) which returns true if and only if we can do the task in D days.
Easy solution on python3
capacity-to-ship-packages-within-d-days
0
1
# Intuition\r\n<!-- Describe your first thoughts on how to solve this problem. -->\r\n\r\n# Approach\r\n<!-- Describe your approach to solving the problem. -->\r\n\r\n# Complexity\r\n- Time complexity:\r\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\r\n\r\n- Space complexity:\r\n<!-- Add your space complexity ...
1
A conveyor belt has packages that must be shipped from one port to another within `days` days. The `ith` package on the conveyor belt has a weight of `weights[i]`. Each day, we load the ship with packages on the conveyor belt (in the order given by `weights`). We may not load more weight than the maximum weight capaci...
null
Easy solution on python3
capacity-to-ship-packages-within-d-days
0
1
# Intuition\r\n<!-- Describe your first thoughts on how to solve this problem. -->\r\n\r\n# Approach\r\n<!-- Describe your approach to solving the problem. -->\r\n\r\n# Complexity\r\n- Time complexity:\r\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\r\n\r\n- Space complexity:\r\n<!-- Add your space complexity ...
1
A **confusing number** is a number that when rotated `180` degrees becomes a different number with **each digit valid**. We can rotate digits of a number by `180` degrees to form new digits. * When `0`, `1`, `6`, `8`, and `9` are rotated `180` degrees, they become `0`, `1`, `9`, `8`, and `6` respectively. * When ...
Binary search on the answer. We need a function possible(capacity) which returns true if and only if we can do the task in D days.
Solution
numbers-with-repeated-digits
1
1
```C++ []\nclass Solution {\npublic:\n int numDupDigitsAtMostN(int n) {\n vector<int> digits{};\n int temp = n + 1;\n while (temp > 0) {\n digits.emplace_back(temp % 10);\n temp /= 10;\n }\n int result = 0;\n int len = digits.size();\n int curr =...
442
Given an integer `n`, return _the number of positive integers in the range_ `[1, n]` _that have **at least one** repeated digit_. **Example 1:** **Input:** n = 20 **Output:** 1 **Explanation:** The only positive number (<= 20) with at least 1 repeated digit is 11. **Example 2:** **Input:** n = 100 **Output:** 10 **...
null
Solution
numbers-with-repeated-digits
1
1
```C++ []\nclass Solution {\npublic:\n int numDupDigitsAtMostN(int n) {\n vector<int> digits{};\n int temp = n + 1;\n while (temp > 0) {\n digits.emplace_back(temp % 10);\n temp /= 10;\n }\n int result = 0;\n int len = digits.size();\n int curr =...
442
On a campus represented on the X-Y plane, there are `n` workers and `m` bikes, with `n <= m`. You are given an array `workers` of length `n` where `workers[i] = [xi, yi]` is the position of the `ith` worker. You are also given an array `bikes` of length `m` where `bikes[j] = [xj, yj]` is the position of the `jth` bike...
How many numbers with no duplicate digits? How many numbers with K digits and no duplicates? How many numbers with same length as N? How many numbers with same prefix as N?
I spent 4 hours on this shit I hate my life
numbers-with-repeated-digits
0
1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nIts basically just math, Im gonna die \n# Approach\n<!-- Describe your approach to solving the problem. -->\nlet n be a K digit integer\nWe will count the total number of non-duplicated integers\nWe split them up in 2 cases by counting <K...
2
Given an integer `n`, return _the number of positive integers in the range_ `[1, n]` _that have **at least one** repeated digit_. **Example 1:** **Input:** n = 20 **Output:** 1 **Explanation:** The only positive number (<= 20) with at least 1 repeated digit is 11. **Example 2:** **Input:** n = 100 **Output:** 10 **...
null
I spent 4 hours on this shit I hate my life
numbers-with-repeated-digits
0
1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nIts basically just math, Im gonna die \n# Approach\n<!-- Describe your approach to solving the problem. -->\nlet n be a K digit integer\nWe will count the total number of non-duplicated integers\nWe split them up in 2 cases by counting <K...
2
On a campus represented on the X-Y plane, there are `n` workers and `m` bikes, with `n <= m`. You are given an array `workers` of length `n` where `workers[i] = [xi, yi]` is the position of the `ith` worker. You are also given an array `bikes` of length `m` where `bikes[j] = [xj, yj]` is the position of the `jth` bike...
How many numbers with no duplicate digits? How many numbers with K digits and no duplicates? How many numbers with same length as N? How many numbers with same prefix as N?
Math solution
numbers-with-repeated-digits
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: O(logn)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O...
0
Given an integer `n`, return _the number of positive integers in the range_ `[1, n]` _that have **at least one** repeated digit_. **Example 1:** **Input:** n = 20 **Output:** 1 **Explanation:** The only positive number (<= 20) with at least 1 repeated digit is 11. **Example 2:** **Input:** n = 100 **Output:** 10 **...
null
Math solution
numbers-with-repeated-digits
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: O(logn)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O...
0
On a campus represented on the X-Y plane, there are `n` workers and `m` bikes, with `n <= m`. You are given an array `workers` of length `n` where `workers[i] = [xi, yi]` is the position of the `ith` worker. You are also given an array `bikes` of length `m` where `bikes[j] = [xj, yj]` is the position of the `jth` bike...
How many numbers with no duplicate digits? How many numbers with K digits and no duplicates? How many numbers with same length as N? How many numbers with same prefix as N?
easy dp python digit dp
numbers-with-repeated-digits
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 an integer `n`, return _the number of positive integers in the range_ `[1, n]` _that have **at least one** repeated digit_. **Example 1:** **Input:** n = 20 **Output:** 1 **Explanation:** The only positive number (<= 20) with at least 1 repeated digit is 11. **Example 2:** **Input:** n = 100 **Output:** 10 **...
null
easy dp python digit dp
numbers-with-repeated-digits
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
On a campus represented on the X-Y plane, there are `n` workers and `m` bikes, with `n <= m`. You are given an array `workers` of length `n` where `workers[i] = [xi, yi]` is the position of the `ith` worker. You are also given an array `bikes` of length `m` where `bikes[j] = [xj, yj]` is the position of the `jth` bike...
How many numbers with no duplicate digits? How many numbers with K digits and no duplicates? How many numbers with same length as N? How many numbers with same prefix as N?
80%faster Easy and optimal solution
partition-array-into-three-parts-with-equal-sum
0
1
```\n def canThreePartsEqualSum(self, arr: List[int]) -> bool:\n \n res=sum(arr)\n if(res%3!=0):\n return False\n res=res//3\n li=0\n sm=0\n for i in arr:\n sm+=i\n if(sm==res):\n li+=1\n sm=0\n if...
1
Given an array of integers `arr`, return `true` if we can partition the array into three **non-empty** parts with equal sums. Formally, we can partition the array if we can find indexes `i + 1 < j` with `(arr[0] + arr[1] + ... + arr[i] == arr[i + 1] + arr[i + 2] + ... + arr[j - 1] == arr[j] + arr[j + 1] + ... + arr[ar...
null
80%faster Easy and optimal solution
partition-array-into-three-parts-with-equal-sum
0
1
```\n def canThreePartsEqualSum(self, arr: List[int]) -> bool:\n \n res=sum(arr)\n if(res%3!=0):\n return False\n res=res//3\n li=0\n sm=0\n for i in arr:\n sm+=i\n if(sm==res):\n li+=1\n sm=0\n if...
1
Given a string `s`, return _the length of the longest repeating substrings_. If no repeating substring exists, return `0`. **Example 1:** **Input:** s = "abcd " **Output:** 0 **Explanation:** There is no repeating substring. **Example 2:** **Input:** s = "abbaba " **Output:** 2 **Explanation:** The longest repeat...
If we have three parts with the same sum, what is the sum of each? If you can find the first part, can you find the second part?
Solution in Python 3 (beats ~99%) (With Detailed Explanation) ( O(n) time ) ( O(1) space )
partition-array-into-three-parts-with-equal-sum
0
1
_Explanation:_\n\nWe are asked to determine if the array can be partioned into three _adjacent_ regions each of which have the same sum. Since we must use all of the elements in the array the sum of each of the three regions must be sum(A)//3. If sum(A) is not divisible by 3, one can immediately return False because a ...
23
Given an array of integers `arr`, return `true` if we can partition the array into three **non-empty** parts with equal sums. Formally, we can partition the array if we can find indexes `i + 1 < j` with `(arr[0] + arr[1] + ... + arr[i] == arr[i + 1] + arr[i + 2] + ... + arr[j - 1] == arr[j] + arr[j + 1] + ... + arr[ar...
null
Solution in Python 3 (beats ~99%) (With Detailed Explanation) ( O(n) time ) ( O(1) space )
partition-array-into-three-parts-with-equal-sum
0
1
_Explanation:_\n\nWe are asked to determine if the array can be partioned into three _adjacent_ regions each of which have the same sum. Since we must use all of the elements in the array the sum of each of the three regions must be sum(A)//3. If sum(A) is not divisible by 3, one can immediately return False because a ...
23
Given a string `s`, return _the length of the longest repeating substrings_. If no repeating substring exists, return `0`. **Example 1:** **Input:** s = "abcd " **Output:** 0 **Explanation:** There is no repeating substring. **Example 2:** **Input:** s = "abbaba " **Output:** 2 **Explanation:** The longest repeat...
If we have three parts with the same sum, what is the sum of each? If you can find the first part, can you find the second part?
Solution
partition-array-into-three-parts-with-equal-sum
1
1
```C++ []\nclass Solution {\npublic:\n bool canThreePartsEqualSum(vector<int>&v) {\n ios::sync_with_stdio(0);\n int ts=accumulate(v.begin(),v.end(),0),c=0,s=0,n=v.size()-1,sum;\n if(ts%3 == 0) sum=ts/3;\n else return 0;\n for(int i=0;i<=n;i++)\n {\n s+=v[i];\n ...
2
Given an array of integers `arr`, return `true` if we can partition the array into three **non-empty** parts with equal sums. Formally, we can partition the array if we can find indexes `i + 1 < j` with `(arr[0] + arr[1] + ... + arr[i] == arr[i + 1] + arr[i + 2] + ... + arr[j - 1] == arr[j] + arr[j + 1] + ... + arr[ar...
null
Solution
partition-array-into-three-parts-with-equal-sum
1
1
```C++ []\nclass Solution {\npublic:\n bool canThreePartsEqualSum(vector<int>&v) {\n ios::sync_with_stdio(0);\n int ts=accumulate(v.begin(),v.end(),0),c=0,s=0,n=v.size()-1,sum;\n if(ts%3 == 0) sum=ts/3;\n else return 0;\n for(int i=0;i<=n;i++)\n {\n s+=v[i];\n ...
2
Given a string `s`, return _the length of the longest repeating substrings_. If no repeating substring exists, return `0`. **Example 1:** **Input:** s = "abcd " **Output:** 0 **Explanation:** There is no repeating substring. **Example 2:** **Input:** s = "abbaba " **Output:** 2 **Explanation:** The longest repeat...
If we have three parts with the same sum, what is the sum of each? If you can find the first part, can you find the second part?
Python 3 faster than 90%
partition-array-into-three-parts-with-equal-sum
0
1
```\nclass Solution:\n def canThreePartsEqualSum(self, arr: List[int]) -> bool:\n s = sum(arr)\n if s % 3:\n return False\n \n part_sum = s / 3\n \n cur_sum = parts = 0\n for num in arr:\n cur_sum += num\n if cur_sum == part_sum:\n ...
3
Given an array of integers `arr`, return `true` if we can partition the array into three **non-empty** parts with equal sums. Formally, we can partition the array if we can find indexes `i + 1 < j` with `(arr[0] + arr[1] + ... + arr[i] == arr[i + 1] + arr[i + 2] + ... + arr[j - 1] == arr[j] + arr[j + 1] + ... + arr[ar...
null
Python 3 faster than 90%
partition-array-into-three-parts-with-equal-sum
0
1
```\nclass Solution:\n def canThreePartsEqualSum(self, arr: List[int]) -> bool:\n s = sum(arr)\n if s % 3:\n return False\n \n part_sum = s / 3\n \n cur_sum = parts = 0\n for num in arr:\n cur_sum += num\n if cur_sum == part_sum:\n ...
3
Given a string `s`, return _the length of the longest repeating substrings_. If no repeating substring exists, return `0`. **Example 1:** **Input:** s = "abcd " **Output:** 0 **Explanation:** There is no repeating substring. **Example 2:** **Input:** s = "abbaba " **Output:** 2 **Explanation:** The longest repeat...
If we have three parts with the same sum, what is the sum of each? If you can find the first part, can you find the second part?
Solution
best-sightseeing-pair
1
1
```C++ []\nclass Solution {\npublic:\n int maxScoreSightseeingPair(vector<int>& values) {\n int maxval = values[0];\n int minval = INT_MAX;\n int res = 0;\n for (int i = 1; i < values.size(); i++)\n {\n minval = values[i] - i;\n res = max(res, maxval + minval)...
1
You are given an integer array `values` where values\[i\] represents the value of the `ith` sightseeing spot. Two sightseeing spots `i` and `j` have a **distance** `j - i` between them. The score of a pair (`i < j`) of sightseeing spots is `values[i] + values[j] + i - j`: the sum of the values of the sightseeing spots...
null
Solution
best-sightseeing-pair
1
1
```C++ []\nclass Solution {\npublic:\n int maxScoreSightseeingPair(vector<int>& values) {\n int maxval = values[0];\n int minval = INT_MAX;\n int res = 0;\n for (int i = 1; i < values.size(); i++)\n {\n minval = values[i] - i;\n res = max(res, maxval + minval)...
1
Given an integer array `nums`, return _the number of non-empty **subarrays** with the leftmost element of the subarray not larger than other elements in the subarray_. A **subarray** is a **contiguous** part of an array. **Example 1:** **Input:** nums = \[1,4,2,5,3\] **Output:** 11 **Explanation:** There are 11 vali...
Can you tell the best sightseeing spot in one pass (ie. as you iterate over the input?) What should we store or keep track of as we iterate to do this?
✅ || Very easy explanation || DP || Complexity Analysis || Python
best-sightseeing-pair
0
1
## **Solution**\n\n\n#### **LOGIC**\n\nSuppose we have a = ```[8,1,5,2,6]```\ncreate a dp = ```[0, 0, 0, 0]``` where dp[i] represents the best possible answer if we consider all pairs forming with a[i] (like i = 3 then it will be (0, 3),(1, 3), (2, 3))\n\n* For d[0] it will be 0\n* For d[1] it will be a[0] + a[1] + 0 -...
50
You are given an integer array `values` where values\[i\] represents the value of the `ith` sightseeing spot. Two sightseeing spots `i` and `j` have a **distance** `j - i` between them. The score of a pair (`i < j`) of sightseeing spots is `values[i] + values[j] + i - j`: the sum of the values of the sightseeing spots...
null
✅ || Very easy explanation || DP || Complexity Analysis || Python
best-sightseeing-pair
0
1
## **Solution**\n\n\n#### **LOGIC**\n\nSuppose we have a = ```[8,1,5,2,6]```\ncreate a dp = ```[0, 0, 0, 0]``` where dp[i] represents the best possible answer if we consider all pairs forming with a[i] (like i = 3 then it will be (0, 3),(1, 3), (2, 3))\n\n* For d[0] it will be 0\n* For d[1] it will be a[0] + a[1] + 0 -...
50
Given an integer array `nums`, return _the number of non-empty **subarrays** with the leftmost element of the subarray not larger than other elements in the subarray_. A **subarray** is a **contiguous** part of an array. **Example 1:** **Input:** nums = \[1,4,2,5,3\] **Output:** 11 **Explanation:** There are 11 vali...
Can you tell the best sightseeing spot in one pass (ie. as you iterate over the input?) What should we store or keep track of as we iterate to do this?
✅Python 3 | O(n) | Very clearly explained!
best-sightseeing-pair
0
1
***Solution 1: Brute Force [Time Limit Exceeded]***\nThe most naive solution is that we can have a brute force solution by simply getting all possible combinations of index `i` and `j`, and then finding the maximum of `values[i] + values[j] + i - j` when `i < j` for all combinations and that will be our answer. We can ...
4
You are given an integer array `values` where values\[i\] represents the value of the `ith` sightseeing spot. Two sightseeing spots `i` and `j` have a **distance** `j - i` between them. The score of a pair (`i < j`) of sightseeing spots is `values[i] + values[j] + i - j`: the sum of the values of the sightseeing spots...
null
✅Python 3 | O(n) | Very clearly explained!
best-sightseeing-pair
0
1
***Solution 1: Brute Force [Time Limit Exceeded]***\nThe most naive solution is that we can have a brute force solution by simply getting all possible combinations of index `i` and `j`, and then finding the maximum of `values[i] + values[j] + i - j` when `i < j` for all combinations and that will be our answer. We can ...
4
Given an integer array `nums`, return _the number of non-empty **subarrays** with the leftmost element of the subarray not larger than other elements in the subarray_. A **subarray** is a **contiguous** part of an array. **Example 1:** **Input:** nums = \[1,4,2,5,3\] **Output:** 11 **Explanation:** There are 11 vali...
Can you tell the best sightseeing spot in one pass (ie. as you iterate over the input?) What should we store or keep track of as we iterate to do this?
Solution
smallest-integer-divisible-by-k
1
1
```C++ []\nclass Solution {\npublic:\n int smallestRepunitDivByK(int k) {\n for (int r=0,N=1;N<=k;N++) {\n if ((r=(r*10+1)%k)==0) {\n return N;\n }\n }\n return -1;\n }\n};\n```\n\n```Python3 []\nclass Solution:\n def smallestRepunitDivByK(self, k: int)...
1
Given a positive integer `k`, you need to find the **length** of the **smallest** positive integer `n` such that `n` is divisible by `k`, and `n` only contains the digit `1`. Return _the **length** of_ `n`. If there is no such `n`, return -1. **Note:** `n` may not fit in a 64-bit signed integer. **Example 1:** **In...
null
Solution
smallest-integer-divisible-by-k
1
1
```C++ []\nclass Solution {\npublic:\n int smallestRepunitDivByK(int k) {\n for (int r=0,N=1;N<=k;N++) {\n if ((r=(r*10+1)%k)==0) {\n return N;\n }\n }\n return -1;\n }\n};\n```\n\n```Python3 []\nclass Solution:\n def smallestRepunitDivByK(self, k: int)...
1
Given an array of distinct integers `arr`, where `arr` is sorted in **ascending order**, return the smallest index `i` that satisfies `arr[i] == i`. If there is no such index, return `-1`. **Example 1:** **Input:** arr = \[-10,-5,0,3,7\] **Output:** 3 **Explanation:** For the given array, `arr[0] = -10, arr[1] = -5, ...
11111 = 1111 * 10 + 1 We only need to store remainders modulo K. If we never get a remainder of 0, why would that happen, and how would we know that?
[Python3] ✔️ Less Math, More Intuition ✔️ | 2 Accepted Solutions | Intuitive
smallest-integer-divisible-by-k
0
1
**Important**: A number containing only `1`s cannot be divisible by `2` or `5`. You can easily convince yourself that this is true since:\n* A number divisble by 2 can only end with `0`, `2`, `4`, `6`, or `8`.\n* A number divisble by 5 can only end with `0`, or `5`.\n\n\u2714\uFE0F **[Accepted] First Approach:** *Makin...
27
Given a positive integer `k`, you need to find the **length** of the **smallest** positive integer `n` such that `n` is divisible by `k`, and `n` only contains the digit `1`. Return _the **length** of_ `n`. If there is no such `n`, return -1. **Note:** `n` may not fit in a 64-bit signed integer. **Example 1:** **In...
null
[Python3] ✔️ Less Math, More Intuition ✔️ | 2 Accepted Solutions | Intuitive
smallest-integer-divisible-by-k
0
1
**Important**: A number containing only `1`s cannot be divisible by `2` or `5`. You can easily convince yourself that this is true since:\n* A number divisble by 2 can only end with `0`, `2`, `4`, `6`, or `8`.\n* A number divisble by 5 can only end with `0`, or `5`.\n\n\u2714\uFE0F **[Accepted] First Approach:** *Makin...
27
Given an array of distinct integers `arr`, where `arr` is sorted in **ascending order**, return the smallest index `i` that satisfies `arr[i] == i`. If there is no such index, return `-1`. **Example 1:** **Input:** arr = \[-10,-5,0,3,7\] **Output:** 3 **Explanation:** For the given array, `arr[0] = -10, arr[1] = -5, ...
11111 = 1111 * 10 + 1 We only need to store remainders modulo K. If we never get a remainder of 0, why would that happen, and how would we know that?
Smallest Integer Divisible by K
smallest-integer-divisible-by-k
0
1
Given a positive integer `K`, we must find the *length* of the smallest positive integer `N` such that `N` is divisible by `K`, and `N` only contains the digit `1`. If there is no such `N`, return `-1`. Therefore the following constraints must be met.\n\n* `N % K == 0`\n* length of `N` is minimized\n* `N` only contains...
20
Given a positive integer `k`, you need to find the **length** of the **smallest** positive integer `n` such that `n` is divisible by `k`, and `n` only contains the digit `1`. Return _the **length** of_ `n`. If there is no such `n`, return -1. **Note:** `n` may not fit in a 64-bit signed integer. **Example 1:** **In...
null
Smallest Integer Divisible by K
smallest-integer-divisible-by-k
0
1
Given a positive integer `K`, we must find the *length* of the smallest positive integer `N` such that `N` is divisible by `K`, and `N` only contains the digit `1`. If there is no such `N`, return `-1`. Therefore the following constraints must be met.\n\n* `N % K == 0`\n* length of `N` is minimized\n* `N` only contains...
20
Given an array of distinct integers `arr`, where `arr` is sorted in **ascending order**, return the smallest index `i` that satisfies `arr[i] == i`. If there is no such index, return `-1`. **Example 1:** **Input:** arr = \[-10,-5,0,3,7\] **Output:** 3 **Explanation:** For the given array, `arr[0] = -10, arr[1] = -5, ...
11111 = 1111 * 10 + 1 We only need to store remainders modulo K. If we never get a remainder of 0, why would that happen, and how would we know that?
Farhad Zada -> Beats 100% Python3
smallest-integer-divisible-by-k
0
1
# Intuition\nThe point is that you need to find the remnants of something. Let me explain what is it. \nExample when you `100 % 7` you get `2`, let\'s see why. \n`1 % 7 = 1` this is obvious. \n`10 % 7 = 3` \n`30 % 7 = 2` because if you get 3 when you divide 10 by 7, 100 is just 10 times 10, you will get 10 3s as remnan...
0
Given a positive integer `k`, you need to find the **length** of the **smallest** positive integer `n` such that `n` is divisible by `k`, and `n` only contains the digit `1`. Return _the **length** of_ `n`. If there is no such `n`, return -1. **Note:** `n` may not fit in a 64-bit signed integer. **Example 1:** **In...
null
Farhad Zada -> Beats 100% Python3
smallest-integer-divisible-by-k
0
1
# Intuition\nThe point is that you need to find the remnants of something. Let me explain what is it. \nExample when you `100 % 7` you get `2`, let\'s see why. \n`1 % 7 = 1` this is obvious. \n`10 % 7 = 3` \n`30 % 7 = 2` because if you get 3 when you divide 10 by 7, 100 is just 10 times 10, you will get 10 3s as remnan...
0
Given an array of distinct integers `arr`, where `arr` is sorted in **ascending order**, return the smallest index `i` that satisfies `arr[i] == i`. If there is no such index, return `-1`. **Example 1:** **Input:** arr = \[-10,-5,0,3,7\] **Output:** 3 **Explanation:** For the given array, `arr[0] = -10, arr[1] = -5, ...
11111 = 1111 * 10 + 1 We only need to store remainders modulo K. If we never get a remainder of 0, why would that happen, and how would we know that?
python3 solution
smallest-integer-divisible-by-k
0
1
\n# Approach\ninitialize the remainder with zero and make a set to store all the remainders.\nBy looping k times we have to update the remainder by (remainder*10+1)%k.\nif the remainder will be zero return i+1 as i is zero base and for returning the length will be 1 base so i+1 instead of i.\nif remainder is in the set...
0
Given a positive integer `k`, you need to find the **length** of the **smallest** positive integer `n` such that `n` is divisible by `k`, and `n` only contains the digit `1`. Return _the **length** of_ `n`. If there is no such `n`, return -1. **Note:** `n` may not fit in a 64-bit signed integer. **Example 1:** **In...
null
python3 solution
smallest-integer-divisible-by-k
0
1
\n# Approach\ninitialize the remainder with zero and make a set to store all the remainders.\nBy looping k times we have to update the remainder by (remainder*10+1)%k.\nif the remainder will be zero return i+1 as i is zero base and for returning the length will be 1 base so i+1 instead of i.\nif remainder is in the set...
0
Given an array of distinct integers `arr`, where `arr` is sorted in **ascending order**, return the smallest index `i` that satisfies `arr[i] == i`. If there is no such index, return `-1`. **Example 1:** **Input:** arr = \[-10,-5,0,3,7\] **Output:** 3 **Explanation:** For the given array, `arr[0] = -10, arr[1] = -5, ...
11111 = 1111 * 10 + 1 We only need to store remainders modulo K. If we never get a remainder of 0, why would that happen, and how would we know that?
Solution
binary-string-with-substrings-representing-1-to-n
1
1
```C++ []\nclass Solution {\n public:\n bool queryString(string S, int N) {\n if (N > 1511)\n return false;\n\n for (int i = N; i > N / 2; --i) {\n string binary = bitset<32>(i).to_string();\n binary = binary.substr(binary.find("1"));\n if (S.find(binary) == string::npos)\n return fals...
1
Given a binary string `s` and a positive integer `n`, return `true` _if the binary representation of all the integers in the range_ `[1, n]` _are **substrings** of_ `s`_, or_ `false` _otherwise_. A **substring** is a contiguous sequence of characters within a string. **Example 1:** **Input:** s = "0110", n = 3 **Out...
null
Solution
binary-string-with-substrings-representing-1-to-n
1
1
```C++ []\nclass Solution {\n public:\n bool queryString(string S, int N) {\n if (N > 1511)\n return false;\n\n for (int i = N; i > N / 2; --i) {\n string binary = bitset<32>(i).to_string();\n binary = binary.substr(binary.find("1"));\n if (S.find(binary) == string::npos)\n return fals...
1
Given a string `text` and an array of strings `words`, return _an array of all index pairs_ `[i, j]` _so that the substring_ `text[i...j]` _is in `words`_. Return the pairs `[i, j]` in sorted order (i.e., sort them by their first coordinate, and in case of ties sort them by their second coordinate). **Example 1:** *...
We only need to check substrings of length at most 30, because 10^9 has 30 bits.
2 LINES ||| PYTHON EASY SOLUTION|| USING STRING
binary-string-with-substrings-representing-1-to-n
0
1
```\nclass Solution:\n def queryString(self, s: str, n: int) -> bool:\n for i in range(1,n+1):\n if bin(i)[2:] not in s:return 0\n return 1
1
Given a binary string `s` and a positive integer `n`, return `true` _if the binary representation of all the integers in the range_ `[1, n]` _are **substrings** of_ `s`_, or_ `false` _otherwise_. A **substring** is a contiguous sequence of characters within a string. **Example 1:** **Input:** s = "0110", n = 3 **Out...
null
2 LINES ||| PYTHON EASY SOLUTION|| USING STRING
binary-string-with-substrings-representing-1-to-n
0
1
```\nclass Solution:\n def queryString(self, s: str, n: int) -> bool:\n for i in range(1,n+1):\n if bin(i)[2:] not in s:return 0\n return 1
1
Given a string `text` and an array of strings `words`, return _an array of all index pairs_ `[i, j]` _so that the substring_ `text[i...j]` _is in `words`_. Return the pairs `[i, j]` in sorted order (i.e., sort them by their first coordinate, and in case of ties sort them by their second coordinate). **Example 1:** *...
We only need to check substrings of length at most 30, because 10^9 has 30 bits.
Python solution beats 100%
binary-string-with-substrings-representing-1-to-n
0
1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nMy thought is to loop through numbers from `n` to `n//2` and check if their binary representation is in the string `s`.\n# Approach\n<!-- Describe your approach to solving the problem. -->\nWe can loop through numbers from `n` to `n//2` a...
1
Given a binary string `s` and a positive integer `n`, return `true` _if the binary representation of all the integers in the range_ `[1, n]` _are **substrings** of_ `s`_, or_ `false` _otherwise_. A **substring** is a contiguous sequence of characters within a string. **Example 1:** **Input:** s = "0110", n = 3 **Out...
null
Python solution beats 100%
binary-string-with-substrings-representing-1-to-n
0
1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nMy thought is to loop through numbers from `n` to `n//2` and check if their binary representation is in the string `s`.\n# Approach\n<!-- Describe your approach to solving the problem. -->\nWe can loop through numbers from `n` to `n//2` a...
1
Given a string `text` and an array of strings `words`, return _an array of all index pairs_ `[i, j]` _so that the substring_ `text[i...j]` _is in `words`_. Return the pairs `[i, j]` in sorted order (i.e., sort them by their first coordinate, and in case of ties sort them by their second coordinate). **Example 1:** *...
We only need to check substrings of length at most 30, because 10^9 has 30 bits.
Easy Python solution || 80%runtime
binary-string-with-substrings-representing-1-to-n
0
1
\n# Code\n```\nclass Solution:\n def queryString(self, s: str, n: int) -> bool:\n for i in range(1,n+1):\n if bin(i)[2:] not in s:return False\n return True\n```
2
Given a binary string `s` and a positive integer `n`, return `true` _if the binary representation of all the integers in the range_ `[1, n]` _are **substrings** of_ `s`_, or_ `false` _otherwise_. A **substring** is a contiguous sequence of characters within a string. **Example 1:** **Input:** s = "0110", n = 3 **Out...
null
Easy Python solution || 80%runtime
binary-string-with-substrings-representing-1-to-n
0
1
\n# Code\n```\nclass Solution:\n def queryString(self, s: str, n: int) -> bool:\n for i in range(1,n+1):\n if bin(i)[2:] not in s:return False\n return True\n```
2
Given a string `text` and an array of strings `words`, return _an array of all index pairs_ `[i, j]` _so that the substring_ `text[i...j]` _is in `words`_. Return the pairs `[i, j]` in sorted order (i.e., sort them by their first coordinate, and in case of ties sort them by their second coordinate). **Example 1:** *...
We only need to check substrings of length at most 30, because 10^9 has 30 bits.
✅ Explained - Simple and Clear Python3 Code✅
binary-string-with-substrings-representing-1-to-n
0
1
# Intuition\nTo determine if the binary representation of all integers in the range [1, n] are substrings of a given binary string s, we can iterate through the range and check if each binary representation exists as a substring in s. If we find any missing substring, we return False; otherwise, we return True.\n\n# Ap...
5
Given a binary string `s` and a positive integer `n`, return `true` _if the binary representation of all the integers in the range_ `[1, n]` _are **substrings** of_ `s`_, or_ `false` _otherwise_. A **substring** is a contiguous sequence of characters within a string. **Example 1:** **Input:** s = "0110", n = 3 **Out...
null
✅ Explained - Simple and Clear Python3 Code✅
binary-string-with-substrings-representing-1-to-n
0
1
# Intuition\nTo determine if the binary representation of all integers in the range [1, n] are substrings of a given binary string s, we can iterate through the range and check if each binary representation exists as a substring in s. If we find any missing substring, we return False; otherwise, we return True.\n\n# Ap...
5
Given a string `text` and an array of strings `words`, return _an array of all index pairs_ `[i, j]` _so that the substring_ `text[i...j]` _is in `words`_. Return the pairs `[i, j]` in sorted order (i.e., sort them by their first coordinate, and in case of ties sort them by their second coordinate). **Example 1:** *...
We only need to check substrings of length at most 30, because 10^9 has 30 bits.
Python + C# solutions: another bluffing question...
binary-string-with-substrings-representing-1-to-n
0
1
List of bluffing Leetcode questions:\n1. [1016. Binary String With Substrings Representing 1 To N](https://leetcode.com/problems/binary-string-with-substrings-representing-1-to-n/)\n2. [2311. Longest Binary Subsequence Less Than or Equal to K](https://leetcode.com/problems/longest-binary-subsequence-less-than-or-equal-...
2
Given a binary string `s` and a positive integer `n`, return `true` _if the binary representation of all the integers in the range_ `[1, n]` _are **substrings** of_ `s`_, or_ `false` _otherwise_. A **substring** is a contiguous sequence of characters within a string. **Example 1:** **Input:** s = "0110", n = 3 **Out...
null
Python + C# solutions: another bluffing question...
binary-string-with-substrings-representing-1-to-n
0
1
List of bluffing Leetcode questions:\n1. [1016. Binary String With Substrings Representing 1 To N](https://leetcode.com/problems/binary-string-with-substrings-representing-1-to-n/)\n2. [2311. Longest Binary Subsequence Less Than or Equal to K](https://leetcode.com/problems/longest-binary-subsequence-less-than-or-equal-...
2
Given a string `text` and an array of strings `words`, return _an array of all index pairs_ `[i, j]` _so that the substring_ `text[i...j]` _is in `words`_. Return the pairs `[i, j]` in sorted order (i.e., sort them by their first coordinate, and in case of ties sort them by their second coordinate). **Example 1:** *...
We only need to check substrings of length at most 30, because 10^9 has 30 bits.
python3 solution beats 100% in runtime(24ms) & 100% in memory(16.1MB)
binary-string-with-substrings-representing-1-to-n
0
1
\nI deserve Upvotes\n\n\n\n![image.png](https://assets.leetcode.com/users/images/05b650cd-f299-4536-8f24-0d668ddf6319_1691581632.2105668.png)\n\n# Code\n```\nclass Solution:\n def queryString(self, s: str, n: int) -> bool:\n flag=True\n for i in range(1,n+1):\n if flag==False:return False\n ...
3
Given a binary string `s` and a positive integer `n`, return `true` _if the binary representation of all the integers in the range_ `[1, n]` _are **substrings** of_ `s`_, or_ `false` _otherwise_. A **substring** is a contiguous sequence of characters within a string. **Example 1:** **Input:** s = "0110", n = 3 **Out...
null
python3 solution beats 100% in runtime(24ms) & 100% in memory(16.1MB)
binary-string-with-substrings-representing-1-to-n
0
1
\nI deserve Upvotes\n\n\n\n![image.png](https://assets.leetcode.com/users/images/05b650cd-f299-4536-8f24-0d668ddf6319_1691581632.2105668.png)\n\n# Code\n```\nclass Solution:\n def queryString(self, s: str, n: int) -> bool:\n flag=True\n for i in range(1,n+1):\n if flag==False:return False\n ...
3
Given a string `text` and an array of strings `words`, return _an array of all index pairs_ `[i, j]` _so that the substring_ `text[i...j]` _is in `words`_. Return the pairs `[i, j]` in sorted order (i.e., sort them by their first coordinate, and in case of ties sort them by their second coordinate). **Example 1:** *...
We only need to check substrings of length at most 30, because 10^9 has 30 bits.
Python 3 || 3 lines, w/ comment || T/M: 93% / 98%
binary-string-with-substrings-representing-1-to-n
0
1
Pretty much the same as the other brute force solutions, with one enhancement: *If`num`is in s then so is`num`//2.* For example, 13 = "1101" and 13//2= 6 = "110." \n\nIt follows then we only need to verify`num`over `range(n//2+1, n+1)`.\n```\nclass Solution:\n def queryString(self, s: str, n: int) -> bool:\n\n ...
4
Given a binary string `s` and a positive integer `n`, return `true` _if the binary representation of all the integers in the range_ `[1, n]` _are **substrings** of_ `s`_, or_ `false` _otherwise_. A **substring** is a contiguous sequence of characters within a string. **Example 1:** **Input:** s = "0110", n = 3 **Out...
null
Python 3 || 3 lines, w/ comment || T/M: 93% / 98%
binary-string-with-substrings-representing-1-to-n
0
1
Pretty much the same as the other brute force solutions, with one enhancement: *If`num`is in s then so is`num`//2.* For example, 13 = "1101" and 13//2= 6 = "110." \n\nIt follows then we only need to verify`num`over `range(n//2+1, n+1)`.\n```\nclass Solution:\n def queryString(self, s: str, n: int) -> bool:\n\n ...
4
Given a string `text` and an array of strings `words`, return _an array of all index pairs_ `[i, j]` _so that the substring_ `text[i...j]` _is in `words`_. Return the pairs `[i, j]` in sorted order (i.e., sort them by their first coordinate, and in case of ties sort them by their second coordinate). **Example 1:** *...
We only need to check substrings of length at most 30, because 10^9 has 30 bits.
[Python3] 2 approaches
binary-string-with-substrings-representing-1-to-n
0
1
Approach 1 - check if binary of number is in `S`\n```\nclass Solution:\n def queryString(self, S: str, N: int) -> bool:\n for x in range(N, 0, -1):\n if bin(x)[2:] not in S: return False \n return True \n```\n\nApproach 2 - collect all numbers in `S` and check if they fill `1` to `N`\n```\nc...
7
Given a binary string `s` and a positive integer `n`, return `true` _if the binary representation of all the integers in the range_ `[1, n]` _are **substrings** of_ `s`_, or_ `false` _otherwise_. A **substring** is a contiguous sequence of characters within a string. **Example 1:** **Input:** s = "0110", n = 3 **Out...
null
[Python3] 2 approaches
binary-string-with-substrings-representing-1-to-n
0
1
Approach 1 - check if binary of number is in `S`\n```\nclass Solution:\n def queryString(self, S: str, N: int) -> bool:\n for x in range(N, 0, -1):\n if bin(x)[2:] not in S: return False \n return True \n```\n\nApproach 2 - collect all numbers in `S` and check if they fill `1` to `N`\n```\nc...
7
Given a string `text` and an array of strings `words`, return _an array of all index pairs_ `[i, j]` _so that the substring_ `text[i...j]` _is in `words`_. Return the pairs `[i, j]` in sorted order (i.e., sort them by their first coordinate, and in case of ties sort them by their second coordinate). **Example 1:** *...
We only need to check substrings of length at most 30, because 10^9 has 30 bits.
simple easy to understand beats 80%
binary-string-with-substrings-representing-1-to-n
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 binary string `s` and a positive integer `n`, return `true` _if the binary representation of all the integers in the range_ `[1, n]` _are **substrings** of_ `s`_, or_ `false` _otherwise_. A **substring** is a contiguous sequence of characters within a string. **Example 1:** **Input:** s = "0110", n = 3 **Out...
null
simple easy to understand beats 80%
binary-string-with-substrings-representing-1-to-n
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 `text` and an array of strings `words`, return _an array of all index pairs_ `[i, j]` _so that the substring_ `text[i...j]` _is in `words`_. Return the pairs `[i, j]` in sorted order (i.e., sort them by their first coordinate, and in case of ties sort them by their second coordinate). **Example 1:** *...
We only need to check substrings of length at most 30, because 10^9 has 30 bits.
Python Solution
binary-string-with-substrings-representing-1-to-n
0
1
# Code\n```\nclass Solution:\n def queryString(self, s: str, n: int) -> bool:\n for i in range(1,n+1):\n st=""\n no=i\n while(no>0):\n st=str(no&1)+st\n no=no>>1\n if(st not in s):\n return False\n return True\n```
0
Given a binary string `s` and a positive integer `n`, return `true` _if the binary representation of all the integers in the range_ `[1, n]` _are **substrings** of_ `s`_, or_ `false` _otherwise_. A **substring** is a contiguous sequence of characters within a string. **Example 1:** **Input:** s = "0110", n = 3 **Out...
null
Python Solution
binary-string-with-substrings-representing-1-to-n
0
1
# Code\n```\nclass Solution:\n def queryString(self, s: str, n: int) -> bool:\n for i in range(1,n+1):\n st=""\n no=i\n while(no>0):\n st=str(no&1)+st\n no=no>>1\n if(st not in s):\n return False\n return True\n```
0
Given a string `text` and an array of strings `words`, return _an array of all index pairs_ `[i, j]` _so that the substring_ `text[i...j]` _is in `words`_. Return the pairs `[i, j]` in sorted order (i.e., sort them by their first coordinate, and in case of ties sort them by their second coordinate). **Example 1:** *...
We only need to check substrings of length at most 30, because 10^9 has 30 bits.