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
NOOB CODE : EASY TO UNDERSTAND
goat-latin
0
1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n1. If a word begins with a vowel (a, e, i, o, u, A, E, I, O, U), append "ma" to the end of the word.\n2. If a word begins with a consonant, remove the first letter and append it to the end of the word, followed by "ma."\n3. ...
3
You are given a string `sentence` that consist of words separated by spaces. Each word consists of lowercase and uppercase letters only. We would like to convert the sentence to "Goat Latin " (a made-up language similar to Pig Latin.) The rules of Goat Latin are as follows: * If a word begins with a vowel (`'a'`, `...
null
NOOB CODE : EASY TO UNDERSTAND
goat-latin
0
1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n1. If a word begins with a vowel (a, e, i, o, u, A, E, I, O, U), append "ma" to the end of the word.\n2. If a word begins with a consonant, remove the first letter and append it to the end of the word, followed by "ma."\n3. ...
3
There is a group of `n` people labeled from `0` to `n - 1` where each person has a different amount of money and a different level of quietness. You are given an array `richer` where `richer[i] = [ai, bi]` indicates that `ai` has more money than `bi` and an integer array `quiet` where `quiet[i]` is the quietness of th...
null
easy
goat-latin
0
1
\n```\nclass Solution:\n def toGoatLatin(self, sentence: str) -> str:\n k = 0\n p = ""\n for x in sentence.split(" "):\n if x[0] not in ("aeiouAEIOU"): \n x = x[1:]+x[0]\n p+=x+"maa"+"a" * k\n k += 1\n if k == len(sentence.split(" ")):\n...
1
You are given a string `sentence` that consist of words separated by spaces. Each word consists of lowercase and uppercase letters only. We would like to convert the sentence to "Goat Latin " (a made-up language similar to Pig Latin.) The rules of Goat Latin are as follows: * If a word begins with a vowel (`'a'`, `...
null
easy
goat-latin
0
1
\n```\nclass Solution:\n def toGoatLatin(self, sentence: str) -> str:\n k = 0\n p = ""\n for x in sentence.split(" "):\n if x[0] not in ("aeiouAEIOU"): \n x = x[1:]+x[0]\n p+=x+"maa"+"a" * k\n k += 1\n if k == len(sentence.split(" ")):\n...
1
There is a group of `n` people labeled from `0` to `n - 1` where each person has a different amount of money and a different level of quietness. You are given an array `richer` where `richer[i] = [ai, bi]` indicates that `ai` has more money than `bi` and an integer array `quiet` where `quiet[i]` is the quietness of th...
null
[Python 3] - Simple Solution w Explanation
goat-latin
0
1
Still fairly new to Python so open to any suggestions or improvements! \n```\nclass Solution:\n def toGoatLatin(self, sentence: str) -> str:\n new = sentence.split() # Breaks up the input into individual sentences\n count = 1 # Starting at 1 since we only have one "a" to begin with.\n \n ...
4
You are given a string `sentence` that consist of words separated by spaces. Each word consists of lowercase and uppercase letters only. We would like to convert the sentence to "Goat Latin " (a made-up language similar to Pig Latin.) The rules of Goat Latin are as follows: * If a word begins with a vowel (`'a'`, `...
null
[Python 3] - Simple Solution w Explanation
goat-latin
0
1
Still fairly new to Python so open to any suggestions or improvements! \n```\nclass Solution:\n def toGoatLatin(self, sentence: str) -> str:\n new = sentence.split() # Breaks up the input into individual sentences\n count = 1 # Starting at 1 since we only have one "a" to begin with.\n \n ...
4
There is a group of `n` people labeled from `0` to `n - 1` where each person has a different amount of money and a different level of quietness. You are given an array `richer` where `richer[i] = [ai, bi]` indicates that `ai` has more money than `bi` and an integer array `quiet` where `quiet[i]` is the quietness of th...
null
Python Easy
goat-latin
0
1
\tclass Solution:\n\t\tdef toGoatLatin(self, sentence: str) -> str:\n\t\t\tlst = sentence.split(" ")\n\n\t\t\tlst2 = []\n\n\t\t\tvowels = ["a", "e", "i", "o", "u"]\n\n\t\t\tfor i, word in enumerate(lst):\n\t\t\t\ttmp = word\n\n\t\t\t\tif (word[0].lower() in vowels):\n\t\t\t\t\ttmp = tmp + "ma"\n\n\t\t\t\telse: \n\t\t\t...
2
You are given a string `sentence` that consist of words separated by spaces. Each word consists of lowercase and uppercase letters only. We would like to convert the sentence to "Goat Latin " (a made-up language similar to Pig Latin.) The rules of Goat Latin are as follows: * If a word begins with a vowel (`'a'`, `...
null
Python Easy
goat-latin
0
1
\tclass Solution:\n\t\tdef toGoatLatin(self, sentence: str) -> str:\n\t\t\tlst = sentence.split(" ")\n\n\t\t\tlst2 = []\n\n\t\t\tvowels = ["a", "e", "i", "o", "u"]\n\n\t\t\tfor i, word in enumerate(lst):\n\t\t\t\ttmp = word\n\n\t\t\t\tif (word[0].lower() in vowels):\n\t\t\t\t\ttmp = tmp + "ma"\n\n\t\t\t\telse: \n\t\t\t...
2
There is a group of `n` people labeled from `0` to `n - 1` where each person has a different amount of money and a different level of quietness. You are given an array `richer` where `richer[i] = [ai, bi]` indicates that `ai` has more money than `bi` and an integer array `quiet` where `quiet[i]` is the quietness of th...
null
[Python] (Very Easy to understand solution)
goat-latin
0
1
```\nclass Solution:\n def toGoatLatin(self, S: str) -> str:\n temp = []\n ans = " " # Here space must be present. (So, after joining the words, they wil be separated by space)\n i = 1\n vowel = [\'a\', \'e\', \'i\', \'o\', \'u\', \'A\', \'E\', \'I\', \'O\', \'U\']\n for word in S...
15
You are given a string `sentence` that consist of words separated by spaces. Each word consists of lowercase and uppercase letters only. We would like to convert the sentence to "Goat Latin " (a made-up language similar to Pig Latin.) The rules of Goat Latin are as follows: * If a word begins with a vowel (`'a'`, `...
null
[Python] (Very Easy to understand solution)
goat-latin
0
1
```\nclass Solution:\n def toGoatLatin(self, S: str) -> str:\n temp = []\n ans = " " # Here space must be present. (So, after joining the words, they wil be separated by space)\n i = 1\n vowel = [\'a\', \'e\', \'i\', \'o\', \'u\', \'A\', \'E\', \'I\', \'O\', \'U\']\n for word in S...
15
There is a group of `n` people labeled from `0` to `n - 1` where each person has a different amount of money and a different level of quietness. You are given an array `richer` where `richer[i] = [ai, bi]` indicates that `ai` has more money than `bi` and an integer array `quiet` where `quiet[i]` is the quietness of th...
null
Python3 O(m+n)? or O(m*n) # Runtime: 42ms 61.69% Memory: 13.9mb 63.09%
goat-latin
0
1
```\nvowels = {\'a\', \'e\',\'i\',\'o\',\'u\', \'A\',\'E\',\'I\',\'O\',\'U\'}\n\nclass Solution:\n# O(m+n)?\n# Runtime: 33ms 89.10% Memory: 13.9mb 63.09%\n def toGoatLatin(self, string: str) -> str:\n sub = "maa"\n newString = string.split()\n\n for idx, val in enumerate(newString):\n ...
1
You are given a string `sentence` that consist of words separated by spaces. Each word consists of lowercase and uppercase letters only. We would like to convert the sentence to "Goat Latin " (a made-up language similar to Pig Latin.) The rules of Goat Latin are as follows: * If a word begins with a vowel (`'a'`, `...
null
Python3 O(m+n)? or O(m*n) # Runtime: 42ms 61.69% Memory: 13.9mb 63.09%
goat-latin
0
1
```\nvowels = {\'a\', \'e\',\'i\',\'o\',\'u\', \'A\',\'E\',\'I\',\'O\',\'U\'}\n\nclass Solution:\n# O(m+n)?\n# Runtime: 33ms 89.10% Memory: 13.9mb 63.09%\n def toGoatLatin(self, string: str) -> str:\n sub = "maa"\n newString = string.split()\n\n for idx, val in enumerate(newString):\n ...
1
There is a group of `n` people labeled from `0` to `n - 1` where each person has a different amount of money and a different level of quietness. You are given an array `richer` where `richer[i] = [ai, bi]` indicates that `ai` has more money than `bi` and an integer array `quiet` where `quiet[i]` is the quietness of th...
null
Simple python solution
goat-latin
0
1
Runtime: 28 ms\nMemory Usage: 14 MB\n\nCreate a list to store vowels and split the sentence into list. Then iterate through the list of sentence and check if first letter is vowel or consonant. If it is consonant then store the first letter in a variable and and remove that letter using slicing after that add that lett...
1
You are given a string `sentence` that consist of words separated by spaces. Each word consists of lowercase and uppercase letters only. We would like to convert the sentence to "Goat Latin " (a made-up language similar to Pig Latin.) The rules of Goat Latin are as follows: * If a word begins with a vowel (`'a'`, `...
null
Simple python solution
goat-latin
0
1
Runtime: 28 ms\nMemory Usage: 14 MB\n\nCreate a list to store vowels and split the sentence into list. Then iterate through the list of sentence and check if first letter is vowel or consonant. If it is consonant then store the first letter in a variable and and remove that letter using slicing after that add that lett...
1
There is a group of `n` people labeled from `0` to `n - 1` where each person has a different amount of money and a different level of quietness. You are given an array `richer` where `richer[i] = [ai, bi]` indicates that `ai` has more money than `bi` and an integer array `quiet` where `quiet[i]` is the quietness of th...
null
Simple solution
goat-latin
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 a string `sentence` that consist of words separated by spaces. Each word consists of lowercase and uppercase letters only. We would like to convert the sentence to "Goat Latin " (a made-up language similar to Pig Latin.) The rules of Goat Latin are as follows: * If a word begins with a vowel (`'a'`, `...
null
Simple solution
goat-latin
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
There is a group of `n` people labeled from `0` to `n - 1` where each person has a different amount of money and a different level of quietness. You are given an array `richer` where `richer[i] = [ai, bi]` indicates that `ai` has more money than `bi` and an integer array `quiet` where `quiet[i]` is the quietness of th...
null
Super Easy solution in O(N) time
goat-latin
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. -->\n1. split the string and convert it into array of strings\n2. Create a list of vowels which includes both uppercase and lowercase vowels\n3. check if the strings first ...
0
You are given a string `sentence` that consist of words separated by spaces. Each word consists of lowercase and uppercase letters only. We would like to convert the sentence to "Goat Latin " (a made-up language similar to Pig Latin.) The rules of Goat Latin are as follows: * If a word begins with a vowel (`'a'`, `...
null
Super Easy solution in O(N) time
goat-latin
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. -->\n1. split the string and convert it into array of strings\n2. Create a list of vowels which includes both uppercase and lowercase vowels\n3. check if the strings first ...
0
There is a group of `n` people labeled from `0` to `n - 1` where each person has a different amount of money and a different level of quietness. You are given an array `richer` where `richer[i] = [ai, bi]` indicates that `ai` has more money than `bi` and an integer array `quiet` where `quiet[i]` is the quietness of th...
null
Solution
friends-of-appropriate-ages
1
1
```C++ []\nclass Solution {\npublic:\n int numFriendRequests(vector<int>& ages) {\n vector<int> v(121, 0);\n for(auto it: ages)\n v[it]++;\n int ans=0;\n for(int i=1; i<121; i++)\n {\n if(v[i]==0) continue;\n int tmp =0;\n for(int j=1; j<...
1
There are `n` persons on a social media website. You are given an integer array `ages` where `ages[i]` is the age of the `ith` person. A Person `x` will not send a friend request to a person `y` (`x != y`) if any of the following conditions is true: * `age[y] <= 0.5 * age[x] + 7` * `age[y] > age[x]` * `age[y] >...
null
Solution
friends-of-appropriate-ages
1
1
```C++ []\nclass Solution {\npublic:\n int numFriendRequests(vector<int>& ages) {\n vector<int> v(121, 0);\n for(auto it: ages)\n v[it]++;\n int ans=0;\n for(int i=1; i<121; i++)\n {\n if(v[i]==0) continue;\n int tmp =0;\n for(int j=1; j<...
1
An array `arr` a **mountain** if the following properties hold: * `arr.length >= 3` * There exists some `i` with `0 < i < arr.length - 1` such that: * `arr[0] < arr[1] < ... < arr[i - 1] < arr[i]` * `arr[i] > arr[i + 1] > ... > arr[arr.length - 1]` Given a mountain array `arr`, return the index `i` su...
null
Python 3 | Three Methods (Binary Search, Counter/Hashmap, Math) | Explanation
friends-of-appropriate-ages
0
1
### Approach 1. Binary Search + Math\n- Time Complexity: `O(NlogN), N = len(ages)`\n```\nclass Solution:\n def numFriendRequests(self, ages: List[int]) -> int:\n ages.sort() # sort the `ages`\n ans = 0\n n = len(ages)\n for idx, age in enumerate(ages): ...
9
There are `n` persons on a social media website. You are given an integer array `ages` where `ages[i]` is the age of the `ith` person. A Person `x` will not send a friend request to a person `y` (`x != y`) if any of the following conditions is true: * `age[y] <= 0.5 * age[x] + 7` * `age[y] > age[x]` * `age[y] >...
null
Python 3 | Three Methods (Binary Search, Counter/Hashmap, Math) | Explanation
friends-of-appropriate-ages
0
1
### Approach 1. Binary Search + Math\n- Time Complexity: `O(NlogN), N = len(ages)`\n```\nclass Solution:\n def numFriendRequests(self, ages: List[int]) -> int:\n ages.sort() # sort the `ages`\n ans = 0\n n = len(ages)\n for idx, age in enumerate(ages): ...
9
An array `arr` a **mountain** if the following properties hold: * `arr.length >= 3` * There exists some `i` with `0 < i < arr.length - 1` such that: * `arr[0] < arr[1] < ... < arr[i - 1] < arr[i]` * `arr[i] > arr[i + 1] > ... > arr[arr.length - 1]` Given a mountain array `arr`, return the index `i` su...
null
Simple Python solution beats 88%
friends-of-appropriate-ages
0
1
\n def numFriendRequests(self, ages: List[int]) -> int:\n\t # send request or not\n def request(x,y):\n if y <= 0.5 * x + 7 or y > x or (y > 100 and x < 100):\n return False\n return True\n \n\t\t# Construct a dictionary that the keys are ages and the values are ...
2
There are `n` persons on a social media website. You are given an integer array `ages` where `ages[i]` is the age of the `ith` person. A Person `x` will not send a friend request to a person `y` (`x != y`) if any of the following conditions is true: * `age[y] <= 0.5 * age[x] + 7` * `age[y] > age[x]` * `age[y] >...
null
Simple Python solution beats 88%
friends-of-appropriate-ages
0
1
\n def numFriendRequests(self, ages: List[int]) -> int:\n\t # send request or not\n def request(x,y):\n if y <= 0.5 * x + 7 or y > x or (y > 100 and x < 100):\n return False\n return True\n \n\t\t# Construct a dictionary that the keys are ages and the values are ...
2
An array `arr` a **mountain** if the following properties hold: * `arr.length >= 3` * There exists some `i` with `0 < i < arr.length - 1` such that: * `arr[0] < arr[1] < ... < arr[i - 1] < arr[i]` * `arr[i] > arr[i + 1] > ... > arr[arr.length - 1]` Given a mountain array `arr`, return the index `i` su...
null
Python simple solution using counters beats 85%
friends-of-appropriate-ages
0
1
### Algorithm\n**Step 1**: construct a dictionary with age as key and number of members in that age group as values. This can be done using Counter in collections module.\n**Step 2**: iterate for every age group (not every person!!) say "me"\n**Step 3**: for every age group check condition take ("age","me") pair and ch...
9
There are `n` persons on a social media website. You are given an integer array `ages` where `ages[i]` is the age of the `ith` person. A Person `x` will not send a friend request to a person `y` (`x != y`) if any of the following conditions is true: * `age[y] <= 0.5 * age[x] + 7` * `age[y] > age[x]` * `age[y] >...
null
Python simple solution using counters beats 85%
friends-of-appropriate-ages
0
1
### Algorithm\n**Step 1**: construct a dictionary with age as key and number of members in that age group as values. This can be done using Counter in collections module.\n**Step 2**: iterate for every age group (not every person!!) say "me"\n**Step 3**: for every age group check condition take ("age","me") pair and ch...
9
An array `arr` a **mountain** if the following properties hold: * `arr.length >= 3` * There exists some `i` with `0 < i < arr.length - 1` such that: * `arr[0] < arr[1] < ... < arr[i - 1] < arr[i]` * `arr[i] > arr[i + 1] > ... > arr[arr.length - 1]` Given a mountain array `arr`, return the index `i` su...
null
Python - O(N) time, O(1) space. Better than 92%, simple prefix sum approach
friends-of-appropriate-ages
0
1
# Intuition\nWe focus on discovering how many people can a person of certain age request friendship. It turns out, a person Y can request ALL peoples that fall into ages that respect:\n\n1. age < Y\'s age\n2. age > (Y\'s age) // 2 + 7\n\nWe just need to find how many people fall into those constraints and sum the resul...
0
There are `n` persons on a social media website. You are given an integer array `ages` where `ages[i]` is the age of the `ith` person. A Person `x` will not send a friend request to a person `y` (`x != y`) if any of the following conditions is true: * `age[y] <= 0.5 * age[x] + 7` * `age[y] > age[x]` * `age[y] >...
null
Python - O(N) time, O(1) space. Better than 92%, simple prefix sum approach
friends-of-appropriate-ages
0
1
# Intuition\nWe focus on discovering how many people can a person of certain age request friendship. It turns out, a person Y can request ALL peoples that fall into ages that respect:\n\n1. age < Y\'s age\n2. age > (Y\'s age) // 2 + 7\n\nWe just need to find how many people fall into those constraints and sum the resul...
0
An array `arr` a **mountain** if the following properties hold: * `arr.length >= 3` * There exists some `i` with `0 < i < arr.length - 1` such that: * `arr[0] < arr[1] < ... < arr[i - 1] < arr[i]` * `arr[i] > arr[i + 1] > ... > arr[arr.length - 1]` Given a mountain array `arr`, return the index `i` su...
null
Python: O(n * log n) solution with binary search
friends-of-appropriate-ages
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
There are `n` persons on a social media website. You are given an integer array `ages` where `ages[i]` is the age of the `ith` person. A Person `x` will not send a friend request to a person `y` (`x != y`) if any of the following conditions is true: * `age[y] <= 0.5 * age[x] + 7` * `age[y] > age[x]` * `age[y] >...
null
Python: O(n * log n) solution with binary search
friends-of-appropriate-ages
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
An array `arr` a **mountain** if the following properties hold: * `arr.length >= 3` * There exists some `i` with `0 < i < arr.length - 1` such that: * `arr[0] < arr[1] < ... < arr[i - 1] < arr[i]` * `arr[i] > arr[i + 1] > ... > arr[arr.length - 1]` Given a mountain array `arr`, return the index `i` su...
null
O(n log n) solution using binary search
friends-of-appropriate-ages
0
1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nYou can solve this problem with a brutal force with nested loops, but it will likely get TLE. So, an optimized solution is to sort the source data first. Then, calculate the valid request numbers by determining the start and end indices o...
0
There are `n` persons on a social media website. You are given an integer array `ages` where `ages[i]` is the age of the `ith` person. A Person `x` will not send a friend request to a person `y` (`x != y`) if any of the following conditions is true: * `age[y] <= 0.5 * age[x] + 7` * `age[y] > age[x]` * `age[y] >...
null
O(n log n) solution using binary search
friends-of-appropriate-ages
0
1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nYou can solve this problem with a brutal force with nested loops, but it will likely get TLE. So, an optimized solution is to sort the source data first. Then, calculate the valid request numbers by determining the start and end indices o...
0
An array `arr` a **mountain** if the following properties hold: * `arr.length >= 3` * There exists some `i` with `0 < i < arr.length - 1` such that: * `arr[0] < arr[1] < ... < arr[i - 1] < arr[i]` * `arr[i] > arr[i + 1] > ... > arr[arr.length - 1]` Given a mountain array `arr`, return the index `i` su...
null
100% Faster
friends-of-appropriate-ages
0
1
# Complexity\n- Time complexity: $$O(n)$$.\n\n- Space complexity: $$O(120)$$ ~ $$O(1)$$.\n\n# Code\n```\nclass Solution:\n def numFriendRequests(self, ages: List[int]) -> int:\n cntr = Counter(ages)\n ages, pSum = [], []\n for age, cnt in sorted(cntr.items()):\n ages.append(age)\n ...
0
There are `n` persons on a social media website. You are given an integer array `ages` where `ages[i]` is the age of the `ith` person. A Person `x` will not send a friend request to a person `y` (`x != y`) if any of the following conditions is true: * `age[y] <= 0.5 * age[x] + 7` * `age[y] > age[x]` * `age[y] >...
null
100% Faster
friends-of-appropriate-ages
0
1
# Complexity\n- Time complexity: $$O(n)$$.\n\n- Space complexity: $$O(120)$$ ~ $$O(1)$$.\n\n# Code\n```\nclass Solution:\n def numFriendRequests(self, ages: List[int]) -> int:\n cntr = Counter(ages)\n ages, pSum = [], []\n for age, cnt in sorted(cntr.items()):\n ages.append(age)\n ...
0
An array `arr` a **mountain** if the following properties hold: * `arr.length >= 3` * There exists some `i` with `0 < i < arr.length - 1` such that: * `arr[0] < arr[1] < ... < arr[i - 1] < arr[i]` * `arr[i] > arr[i + 1] > ... > arr[arr.length - 1]` Given a mountain array `arr`, return the index `i` su...
null
bisect solution
friends-of-appropriate-ages
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
There are `n` persons on a social media website. You are given an integer array `ages` where `ages[i]` is the age of the `ith` person. A Person `x` will not send a friend request to a person `y` (`x != y`) if any of the following conditions is true: * `age[y] <= 0.5 * age[x] + 7` * `age[y] > age[x]` * `age[y] >...
null
bisect solution
friends-of-appropriate-ages
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
An array `arr` a **mountain** if the following properties hold: * `arr.length >= 3` * There exists some `i` with `0 < i < arr.length - 1` such that: * `arr[0] < arr[1] < ... < arr[i - 1] < arr[i]` * `arr[i] > arr[i + 1] > ... > arr[arr.length - 1]` Given a mountain array `arr`, return the index `i` su...
null
Python - O(n)Time, O(n) Space
friends-of-appropriate-ages
0
1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nInstead of checking every age with every other age (O(n^2)) we can generate a range of appropriate ages for every age and check the count of each age in the range and add it to result. Make sure to subtract 1 from the count of same age to...
0
There are `n` persons on a social media website. You are given an integer array `ages` where `ages[i]` is the age of the `ith` person. A Person `x` will not send a friend request to a person `y` (`x != y`) if any of the following conditions is true: * `age[y] <= 0.5 * age[x] + 7` * `age[y] > age[x]` * `age[y] >...
null
Python - O(n)Time, O(n) Space
friends-of-appropriate-ages
0
1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nInstead of checking every age with every other age (O(n^2)) we can generate a range of appropriate ages for every age and check the count of each age in the range and add it to result. Make sure to subtract 1 from the count of same age to...
0
An array `arr` a **mountain** if the following properties hold: * `arr.length >= 3` * There exists some `i` with `0 < i < arr.length - 1` such that: * `arr[0] < arr[1] < ... < arr[i - 1] < arr[i]` * `arr[i] > arr[i + 1] > ... > arr[arr.length - 1]` Given a mountain array `arr`, return the index `i` su...
null
Python Solution
most-profit-assigning-work
0
1
\n\n# Code\n```\nclass Solution:\n def maxProfitAssignment(self, difficulty: List[int], profit: List[int], worker: List[int]) -> int:\n d = {}\n # mapping the difficulty with the corresponding profit and then storing it in the dictionary\n for x in range(len(difficulty)) :\n if diffic...
1
You have `n` jobs and `m` workers. You are given three arrays: `difficulty`, `profit`, and `worker` where: * `difficulty[i]` and `profit[i]` are the difficulty and the profit of the `ith` job, and * `worker[j]` is the ability of `jth` worker (i.e., the `jth` worker can only complete a job with difficulty at most `...
null
Python Solution
most-profit-assigning-work
0
1
\n\n# Code\n```\nclass Solution:\n def maxProfitAssignment(self, difficulty: List[int], profit: List[int], worker: List[int]) -> int:\n d = {}\n # mapping the difficulty with the corresponding profit and then storing it in the dictionary\n for x in range(len(difficulty)) :\n if diffic...
1
There are `n` cars going to the same destination along a one-lane road. The destination is `target` miles away. You are given two integer array `position` and `speed`, both of length `n`, where `position[i]` is the position of the `ith` car and `speed[i]` is the speed of the `ith` car (in miles per hour). A car can n...
null
All Kind Of Solution With Explanation
most-profit-assigning-work
0
1
### All These Solutions except the very last one are inspired by @lee215 and @votrubac\n## Solution 1\n```\n1.Create a vector where each element is a pair comprised difficulty[i] and profit[i] for each i.\n2.Sort it and it will be sorted by difficulty[i] by default.\n3.Also sort the \'worker\', now for each worker[i] t...
2
You have `n` jobs and `m` workers. You are given three arrays: `difficulty`, `profit`, and `worker` where: * `difficulty[i]` and `profit[i]` are the difficulty and the profit of the `ith` job, and * `worker[j]` is the ability of `jth` worker (i.e., the `jth` worker can only complete a job with difficulty at most `...
null
All Kind Of Solution With Explanation
most-profit-assigning-work
0
1
### All These Solutions except the very last one are inspired by @lee215 and @votrubac\n## Solution 1\n```\n1.Create a vector where each element is a pair comprised difficulty[i] and profit[i] for each i.\n2.Sort it and it will be sorted by difficulty[i] by default.\n3.Also sort the \'worker\', now for each worker[i] t...
2
There are `n` cars going to the same destination along a one-lane road. The destination is `target` miles away. You are given two integer array `position` and `speed`, both of length `n`, where `position[i]` is the position of the `ith` car and `speed[i]` is the speed of the `ith` car (in miles per hour). A car can n...
null
Python|| Binary Search Solution Easy to understand
most-profit-assigning-work
0
1
```\nclass Solution:\n def maxProfitAssignment(self, difficulty: List[int], profit: List[int], worker: List[int]) -> int:\n """\n idea: \n - zip difficulty and profit\n - sort by difficulty \n \n - iterate through each worker\'s ability (worker)\n - find the greates...
1
You have `n` jobs and `m` workers. You are given three arrays: `difficulty`, `profit`, and `worker` where: * `difficulty[i]` and `profit[i]` are the difficulty and the profit of the `ith` job, and * `worker[j]` is the ability of `jth` worker (i.e., the `jth` worker can only complete a job with difficulty at most `...
null
Python|| Binary Search Solution Easy to understand
most-profit-assigning-work
0
1
```\nclass Solution:\n def maxProfitAssignment(self, difficulty: List[int], profit: List[int], worker: List[int]) -> int:\n """\n idea: \n - zip difficulty and profit\n - sort by difficulty \n \n - iterate through each worker\'s ability (worker)\n - find the greates...
1
There are `n` cars going to the same destination along a one-lane road. The destination is `target` miles away. You are given two integer array `position` and `speed`, both of length `n`, where `position[i]` is the position of the `ith` car and `speed[i]` is the speed of the `ith` car (in miles per hour). A car can n...
null
Python3 | Solved Using Binary Search W/ Sorting O((n+m)*logn) Runtime Solution!
most-profit-assigning-work
0
1
```\nclass Solution:\n #Time-Complexity: O(n + nlogn + n + mlog(n)) -> O((n+m) *logn)\n #Space-Complexity: O(n)\n def maxProfitAssignment(self, difficulty: List[int], profit: List[int], worker: List[int]) -> int:\n #Approach: First of all, linearly traverse each and every corresponding index\n #p...
4
You have `n` jobs and `m` workers. You are given three arrays: `difficulty`, `profit`, and `worker` where: * `difficulty[i]` and `profit[i]` are the difficulty and the profit of the `ith` job, and * `worker[j]` is the ability of `jth` worker (i.e., the `jth` worker can only complete a job with difficulty at most `...
null
Python3 | Solved Using Binary Search W/ Sorting O((n+m)*logn) Runtime Solution!
most-profit-assigning-work
0
1
```\nclass Solution:\n #Time-Complexity: O(n + nlogn + n + mlog(n)) -> O((n+m) *logn)\n #Space-Complexity: O(n)\n def maxProfitAssignment(self, difficulty: List[int], profit: List[int], worker: List[int]) -> int:\n #Approach: First of all, linearly traverse each and every corresponding index\n #p...
4
There are `n` cars going to the same destination along a one-lane road. The destination is `target` miles away. You are given two integer array `position` and `speed`, both of length `n`, where `position[i]` is the position of the `ith` car and `speed[i]` is the speed of the `ith` car (in miles per hour). A car can n...
null
Solution
most-profit-assigning-work
1
1
```C++ []\nclass Solution {\npublic:\n int maxProfitAssignment(vector<int>& difficulty, vector<int>& profit, vector<int>& worker) {\n int n = profit.size(), res = 0, l = 0, p = 0;\n vector<pair<int, int>> pairs;\n for(int i = 0; i < n; i++) pairs.emplace_back(difficulty[i], profit[i]);\n ...
2
You have `n` jobs and `m` workers. You are given three arrays: `difficulty`, `profit`, and `worker` where: * `difficulty[i]` and `profit[i]` are the difficulty and the profit of the `ith` job, and * `worker[j]` is the ability of `jth` worker (i.e., the `jth` worker can only complete a job with difficulty at most `...
null
Solution
most-profit-assigning-work
1
1
```C++ []\nclass Solution {\npublic:\n int maxProfitAssignment(vector<int>& difficulty, vector<int>& profit, vector<int>& worker) {\n int n = profit.size(), res = 0, l = 0, p = 0;\n vector<pair<int, int>> pairs;\n for(int i = 0; i < n; i++) pairs.emplace_back(difficulty[i], profit[i]);\n ...
2
There are `n` cars going to the same destination along a one-lane road. The destination is `target` miles away. You are given two integer array `position` and `speed`, both of length `n`, where `position[i]` is the position of the `ith` car and `speed[i]` is the speed of the `ith` car (in miles per hour). A car can n...
null
Python, sorting, bisect
most-profit-assigning-work
0
1
# Intuition\nThe main idea is to get maximum profit for current worker ability.\nFirst of all we need to mix together difficulty and profit, sort them and initialize dp variable with maximum value with at least current difficulty. \n\n# Complexity\n- Time complexity:\nO(N*LogN) for sorting and bisect\n\n- Space complex...
4
You have `n` jobs and `m` workers. You are given three arrays: `difficulty`, `profit`, and `worker` where: * `difficulty[i]` and `profit[i]` are the difficulty and the profit of the `ith` job, and * `worker[j]` is the ability of `jth` worker (i.e., the `jth` worker can only complete a job with difficulty at most `...
null
Python, sorting, bisect
most-profit-assigning-work
0
1
# Intuition\nThe main idea is to get maximum profit for current worker ability.\nFirst of all we need to mix together difficulty and profit, sort them and initialize dp variable with maximum value with at least current difficulty. \n\n# Complexity\n- Time complexity:\nO(N*LogN) for sorting and bisect\n\n- Space complex...
4
There are `n` cars going to the same destination along a one-lane road. The destination is `target` miles away. You are given two integer array `position` and `speed`, both of length `n`, where `position[i]` is the position of the `ith` car and `speed[i]` is the speed of the `ith` car (in miles per hour). A car can n...
null
No Binary Search || Python 3 || EXPLAINEDD
most-profit-assigning-work
0
1
Sort the array on the basis of profit (desc order) instead of difficulty after zipping them togther\nAlso sort the worker array in descending order\nNow if a task difficulty > worker[i] -> this task cant be done by any other worker too so j + 1\nif difficulty < worker[i] => this task can be done i + 1.\n`why not j + 1 ...
2
You have `n` jobs and `m` workers. You are given three arrays: `difficulty`, `profit`, and `worker` where: * `difficulty[i]` and `profit[i]` are the difficulty and the profit of the `ith` job, and * `worker[j]` is the ability of `jth` worker (i.e., the `jth` worker can only complete a job with difficulty at most `...
null
No Binary Search || Python 3 || EXPLAINEDD
most-profit-assigning-work
0
1
Sort the array on the basis of profit (desc order) instead of difficulty after zipping them togther\nAlso sort the worker array in descending order\nNow if a task difficulty > worker[i] -> this task cant be done by any other worker too so j + 1\nif difficulty < worker[i] => this task can be done i + 1.\n`why not j + 1 ...
2
There are `n` cars going to the same destination along a one-lane road. The destination is `target` miles away. You are given two integer array `position` and `speed`, both of length `n`, where `position[i]` is the position of the `ith` car and `speed[i]` is the speed of the `ith` car (in miles per hour). A car can n...
null
Python Beginner Friendly Solution || Sorting
most-profit-assigning-work
0
1
# Code\n```\nclass Solution:\n def maxProfitAssignment(self, difficulty: List[int], profit: List[int], worker: List[int]) -> int:\n temp=[]\n earning=0\n for i in range(len(profit)):\n temp.append([profit[i],difficulty[i]])\n temp.sort()\n temp.reverse()\n for i i...
0
You have `n` jobs and `m` workers. You are given three arrays: `difficulty`, `profit`, and `worker` where: * `difficulty[i]` and `profit[i]` are the difficulty and the profit of the `ith` job, and * `worker[j]` is the ability of `jth` worker (i.e., the `jth` worker can only complete a job with difficulty at most `...
null
Python Beginner Friendly Solution || Sorting
most-profit-assigning-work
0
1
# Code\n```\nclass Solution:\n def maxProfitAssignment(self, difficulty: List[int], profit: List[int], worker: List[int]) -> int:\n temp=[]\n earning=0\n for i in range(len(profit)):\n temp.append([profit[i],difficulty[i]])\n temp.sort()\n temp.reverse()\n for i i...
0
There are `n` cars going to the same destination along a one-lane road. The destination is `target` miles away. You are given two integer array `position` and `speed`, both of length `n`, where `position[i]` is the position of the `ith` car and `speed[i]` is the speed of the `ith` car (in miles per hour). A car can n...
null
Solution
making-a-large-island
1
1
```C++ []\nauto $$ = [] { return ios::sync_with_stdio(0), cin.tie(0), 0; }();\nint uf[500 * 500];\nint find_(int i) {\n return uf[i] < 0 ? i : uf[i] = find_(uf[i]);\n}\nvoid unite_(int i, int j) {\n i = find_(i), j = find_(j);\n if (i == j) return;\n if (-uf[i] > -uf[j]) swap(i, j);\n uf[j] += uf[i], uf[...
1
You are given an `n x n` binary matrix `grid`. You are allowed to change **at most one** `0` to be `1`. Return _the size of the largest **island** in_ `grid` _after applying this operation_. An **island** is a 4-directionally connected group of `1`s. **Example 1:** **Input:** grid = \[\[1,0\],\[0,1\]\] **Output:** ...
null
Solution
making-a-large-island
1
1
```C++ []\nauto $$ = [] { return ios::sync_with_stdio(0), cin.tie(0), 0; }();\nint uf[500 * 500];\nint find_(int i) {\n return uf[i] < 0 ? i : uf[i] = find_(uf[i]);\n}\nvoid unite_(int i, int j) {\n i = find_(i), j = find_(j);\n if (i == j) return;\n if (-uf[i] > -uf[j]) swap(i, j);\n uf[j] += uf[i], uf[...
1
Strings `s1` and `s2` are `k`**\-similar** (for some non-negative integer `k`) if we can swap the positions of two letters in `s1` exactly `k` times so that the resulting string equals `s2`. Given two anagrams `s1` and `s2`, return the smallest `k` for which `s1` and `s2` are `k`**\-similar**. **Example 1:** **Input...
null
DFS based solution, using unique id for each island
making-a-large-island
0
1
\nfirst store all the islands in a list using bfs/dfs\nmark all the islands with a index within the grid\ncreate a hash map with key as index and size of island as the value\nThis will be done by itetrating over teh entire grid once O(m*n)\nwe will have to iterate over the grid again, checking for 0s and flipping\never...
1
You are given an `n x n` binary matrix `grid`. You are allowed to change **at most one** `0` to be `1`. Return _the size of the largest **island** in_ `grid` _after applying this operation_. An **island** is a 4-directionally connected group of `1`s. **Example 1:** **Input:** grid = \[\[1,0\],\[0,1\]\] **Output:** ...
null
DFS based solution, using unique id for each island
making-a-large-island
0
1
\nfirst store all the islands in a list using bfs/dfs\nmark all the islands with a index within the grid\ncreate a hash map with key as index and size of island as the value\nThis will be done by itetrating over teh entire grid once O(m*n)\nwe will have to iterate over the grid again, checking for 0s and flipping\never...
1
Strings `s1` and `s2` are `k`**\-similar** (for some non-negative integer `k`) if we can swap the positions of two letters in `s1` exactly `k` times so that the resulting string equals `s2`. Given two anagrams `s1` and `s2`, return the smallest `k` for which `s1` and `s2` are `k`**\-similar**. **Example 1:** **Input...
null
Solution
count-unique-characters-of-all-substrings-of-a-given-string
1
1
```C++ []\nclass Solution {\npublic:\n int uniqueLetterString(string s) {\n int prev_count[26] = {}, prev_position[26];\n for (size_t i = 0; i < 26; ++i) prev_position[i] = -1;\n int result = 0;\n for (int i = 0, count = 0, n = static_cast<int>(s.size()); i < n; ++i)\n {\n ...
2
Let's define a function `countUniqueChars(s)` that returns the number of unique characters on `s`. * For example, calling `countUniqueChars(s)` if `s = "LEETCODE "` then `"L "`, `"T "`, `"C "`, `"O "`, `"D "` are the unique characters since they appear only once in `s`, therefore `countUniqueChars(s) = 5`. Given a ...
null
Solution
count-unique-characters-of-all-substrings-of-a-given-string
1
1
```C++ []\nclass Solution {\npublic:\n int uniqueLetterString(string s) {\n int prev_count[26] = {}, prev_position[26];\n for (size_t i = 0; i < 26; ++i) prev_position[i] = -1;\n int result = 0;\n for (int i = 0, count = 0, n = static_cast<int>(s.size()); i < n; ++i)\n {\n ...
2
There is an exam room with `n` seats in a single row labeled from `0` to `n - 1`. When a student enters the room, they must sit in the seat that maximizes the distance to the closest person. If there are multiple such seats, they sit in the seat with the lowest number. If no one is in the room, then the student sits a...
null
Solution by Python, calculating each char contribution
count-unique-characters-of-all-substrings-of-a-given-string
0
1
# Intuition\nTo calculate each char in string contruibute to final answer\nI learned it from(Chinese Speaking): https://www.youtube.com/watch?v=NngeskF1wsw&t=679s\n# Approach\nsuppose we have many A in string, such that:\n\n```\nB A B B A B A\n i j k\n\n```\nQ: Suppose 3 As have position of i, j, k, how we gonna...
1
Let's define a function `countUniqueChars(s)` that returns the number of unique characters on `s`. * For example, calling `countUniqueChars(s)` if `s = "LEETCODE "` then `"L "`, `"T "`, `"C "`, `"O "`, `"D "` are the unique characters since they appear only once in `s`, therefore `countUniqueChars(s) = 5`. Given a ...
null
Solution by Python, calculating each char contribution
count-unique-characters-of-all-substrings-of-a-given-string
0
1
# Intuition\nTo calculate each char in string contruibute to final answer\nI learned it from(Chinese Speaking): https://www.youtube.com/watch?v=NngeskF1wsw&t=679s\n# Approach\nsuppose we have many A in string, such that:\n\n```\nB A B B A B A\n i j k\n\n```\nQ: Suppose 3 As have position of i, j, k, how we gonna...
1
There is an exam room with `n` seats in a single row labeled from `0` to `n - 1`. When a student enters the room, they must sit in the seat that maximizes the distance to the closest person. If there are multiple such seats, they sit in the seat with the lowest number. If no one is in the room, then the student sits a...
null
Python O(n) with intuition / step-by-step thought process
count-unique-characters-of-all-substrings-of-a-given-string
0
1
This is one of my first Hard and I\'m writing in extreme detail to help myself fully understand and internalize this. Even after solving it I have trouble understanding most other solution posts.\n\nIt\'s easiest to understand what this problem actually means with a brute force solution:\n```\nclass Solution:\n def ...
6
Let's define a function `countUniqueChars(s)` that returns the number of unique characters on `s`. * For example, calling `countUniqueChars(s)` if `s = "LEETCODE "` then `"L "`, `"T "`, `"C "`, `"O "`, `"D "` are the unique characters since they appear only once in `s`, therefore `countUniqueChars(s) = 5`. Given a ...
null
Python O(n) with intuition / step-by-step thought process
count-unique-characters-of-all-substrings-of-a-given-string
0
1
This is one of my first Hard and I\'m writing in extreme detail to help myself fully understand and internalize this. Even after solving it I have trouble understanding most other solution posts.\n\nIt\'s easiest to understand what this problem actually means with a brute force solution:\n```\nclass Solution:\n def ...
6
There is an exam room with `n` seats in a single row labeled from `0` to `n - 1`. When a student enters the room, they must sit in the seat that maximizes the distance to the closest person. If there are multiple such seats, they sit in the seat with the lowest number. If no one is in the room, then the student sits a...
null
Python simple O(n)
count-unique-characters-of-all-substrings-of-a-given-string
0
1
\tclass Solution:\n\t\tdef uniqueLetterString(self, s: str) -> int:\n\t\t\tprev = [-1] * len(s)\n\t\t\tnex = [len(s)] * len(s)\n\n\t\t\tindex = {}\n\t\t\tfor i, c in enumerate(s):\n\t\t\t\tif c in index:\n\t\t\t\t\tprev[i] = index[c] \n\t\t\t\tindex[c] = i\n\n\t\t\tindex = {}\n\t\t\tfor i in range(len(s) - 1, -1, -1...
1
Let's define a function `countUniqueChars(s)` that returns the number of unique characters on `s`. * For example, calling `countUniqueChars(s)` if `s = "LEETCODE "` then `"L "`, `"T "`, `"C "`, `"O "`, `"D "` are the unique characters since they appear only once in `s`, therefore `countUniqueChars(s) = 5`. Given a ...
null
Python simple O(n)
count-unique-characters-of-all-substrings-of-a-given-string
0
1
\tclass Solution:\n\t\tdef uniqueLetterString(self, s: str) -> int:\n\t\t\tprev = [-1] * len(s)\n\t\t\tnex = [len(s)] * len(s)\n\n\t\t\tindex = {}\n\t\t\tfor i, c in enumerate(s):\n\t\t\t\tif c in index:\n\t\t\t\t\tprev[i] = index[c] \n\t\t\t\tindex[c] = i\n\n\t\t\tindex = {}\n\t\t\tfor i in range(len(s) - 1, -1, -1...
1
There is an exam room with `n` seats in a single row labeled from `0` to `n - 1`. When a student enters the room, they must sit in the seat that maximizes the distance to the closest person. If there are multiple such seats, they sit in the seat with the lowest number. If no one is in the room, then the student sits a...
null
Simple Python3 solution O(N) time, O(1) space using defaultdict
count-unique-characters-of-all-substrings-of-a-given-string
0
1
Adapted from [https://leetcode.com/its_dark/](its_dark) solution: https://leetcode.com/problems/count-unique-characters-of-all-substrings-of-a-given-string/discuss/129021/O(N)-Java-Solution-DP-Clear-and-easy-to-Understand/265186\n\n```\nfrom collections import defaultdict\nclass Solution:\n def uniqueLetterString(se...
14
Let's define a function `countUniqueChars(s)` that returns the number of unique characters on `s`. * For example, calling `countUniqueChars(s)` if `s = "LEETCODE "` then `"L "`, `"T "`, `"C "`, `"O "`, `"D "` are the unique characters since they appear only once in `s`, therefore `countUniqueChars(s) = 5`. Given a ...
null
Simple Python3 solution O(N) time, O(1) space using defaultdict
count-unique-characters-of-all-substrings-of-a-given-string
0
1
Adapted from [https://leetcode.com/its_dark/](its_dark) solution: https://leetcode.com/problems/count-unique-characters-of-all-substrings-of-a-given-string/discuss/129021/O(N)-Java-Solution-DP-Clear-and-easy-to-Understand/265186\n\n```\nfrom collections import defaultdict\nclass Solution:\n def uniqueLetterString(se...
14
There is an exam room with `n` seats in a single row labeled from `0` to `n - 1`. When a student enters the room, they must sit in the seat that maximizes the distance to the closest person. If there are multiple such seats, they sit in the seat with the lowest number. If no one is in the room, then the student sits a...
null
python solution | detail explained and easy to understand
count-unique-characters-of-all-substrings-of-a-given-string
0
1
we may need read the problem carefully, if we clearly understand what is this asking for, it will be easy to find out a solution... \nso, "returns the number of unique characters on s", what does this mean? \ne.g.\n```\nIncorrect undersanding:\nSTRING = AAB\nsub-strings\nA -> 1\nA -> 0 already count A, hence 0 here\nB ...
2
Let's define a function `countUniqueChars(s)` that returns the number of unique characters on `s`. * For example, calling `countUniqueChars(s)` if `s = "LEETCODE "` then `"L "`, `"T "`, `"C "`, `"O "`, `"D "` are the unique characters since they appear only once in `s`, therefore `countUniqueChars(s) = 5`. Given a ...
null
python solution | detail explained and easy to understand
count-unique-characters-of-all-substrings-of-a-given-string
0
1
we may need read the problem carefully, if we clearly understand what is this asking for, it will be easy to find out a solution... \nso, "returns the number of unique characters on s", what does this mean? \ne.g.\n```\nIncorrect undersanding:\nSTRING = AAB\nsub-strings\nA -> 1\nA -> 0 already count A, hence 0 here\nB ...
2
There is an exam room with `n` seats in a single row labeled from `0` to `n - 1`. When a student enters the room, they must sit in the seat that maximizes the distance to the closest person. If there are multiple such seats, they sit in the seat with the lowest number. If no one is in the room, then the student sits a...
null
Python - DP solution O(N)
count-unique-characters-of-all-substrings-of-a-given-string
0
1
"d" stores the last 2 indices of the current letter. "a" stands for the sum of results of all the substrings ending with the current letter "c". \n```\nclass Solution:\n def uniqueLetterString(self, s: str) -> int:\n d = defaultdict(lambda:(0, 0))\n res = a = 0\n for i, c in enumerate(s, 1):\n ...
7
Let's define a function `countUniqueChars(s)` that returns the number of unique characters on `s`. * For example, calling `countUniqueChars(s)` if `s = "LEETCODE "` then `"L "`, `"T "`, `"C "`, `"O "`, `"D "` are the unique characters since they appear only once in `s`, therefore `countUniqueChars(s) = 5`. Given a ...
null
Python - DP solution O(N)
count-unique-characters-of-all-substrings-of-a-given-string
0
1
"d" stores the last 2 indices of the current letter. "a" stands for the sum of results of all the substrings ending with the current letter "c". \n```\nclass Solution:\n def uniqueLetterString(self, s: str) -> int:\n d = defaultdict(lambda:(0, 0))\n res = a = 0\n for i, c in enumerate(s, 1):\n ...
7
There is an exam room with `n` seats in a single row labeled from `0` to `n - 1`. When a student enters the room, they must sit in the seat that maximizes the distance to the closest person. If there are multiple such seats, they sit in the seat with the lowest number. If no one is in the room, then the student sits a...
null
Solution
consecutive-numbers-sum
1
1
```C++ []\nclass Solution {\npublic:\n int consecutiveNumbersSum(int n) {\n int ans=1;\n for(int i=2;i<n;i++) {\n if((i*(i+1))/2 > n) return ans;\n if((n - (i*(i+1))/2)%i==0) ans++;\n }\n return ans;\n }\n};\n```\n\n```Python3 []\nclass Solution:\n def consecut...
1
Given an integer `n`, return _the number of ways you can write_ `n` _as the sum of consecutive positive integers._ **Example 1:** **Input:** n = 5 **Output:** 2 **Explanation:** 5 = 2 + 3 **Example 2:** **Input:** n = 9 **Output:** 3 **Explanation:** 9 = 4 + 5 = 2 + 3 + 4 **Example 3:** **Input:** n = 15 **Output...
null
Solution
consecutive-numbers-sum
1
1
```C++ []\nclass Solution {\npublic:\n int consecutiveNumbersSum(int n) {\n int ans=1;\n for(int i=2;i<n;i++) {\n if((i*(i+1))/2 > n) return ans;\n if((n - (i*(i+1))/2)%i==0) ans++;\n }\n return ans;\n }\n};\n```\n\n```Python3 []\nclass Solution:\n def consecut...
1
Given a balanced parentheses string `s`, return _the **score** of the string_. The **score** of a balanced parentheses string is based on the following rule: * `"() "` has score `1`. * `AB` has score `A + B`, where `A` and `B` are balanced parentheses strings. * `(A)` has score `2 * A`, where `A` is a balanced ...
null
✔️ PYTHON || EXPLAINED || ;]
consecutive-numbers-sum
0
1
**UPVOTE IF HELPFuuL**\nFirstly the question demands sum of consecutive ```positive``` integers.\n\nLet there be ```k``` positive integers that sum to ```num```.\n\n**Only possible values of k are ```1 <= k <= \u221A( 2*num )```**\n\nBecause sum of first k ```positive``` numbers is **( k * ( k+1 ) ) / 2**\n\nHence our ...
5
Given an integer `n`, return _the number of ways you can write_ `n` _as the sum of consecutive positive integers._ **Example 1:** **Input:** n = 5 **Output:** 2 **Explanation:** 5 = 2 + 3 **Example 2:** **Input:** n = 9 **Output:** 3 **Explanation:** 9 = 4 + 5 = 2 + 3 + 4 **Example 3:** **Input:** n = 15 **Output...
null
✔️ PYTHON || EXPLAINED || ;]
consecutive-numbers-sum
0
1
**UPVOTE IF HELPFuuL**\nFirstly the question demands sum of consecutive ```positive``` integers.\n\nLet there be ```k``` positive integers that sum to ```num```.\n\n**Only possible values of k are ```1 <= k <= \u221A( 2*num )```**\n\nBecause sum of first k ```positive``` numbers is **( k * ( k+1 ) ) / 2**\n\nHence our ...
5
Given a balanced parentheses string `s`, return _the **score** of the string_. The **score** of a balanced parentheses string is based on the following rule: * `"() "` has score `1`. * `AB` has score `A + B`, where `A` and `B` are balanced parentheses strings. * `(A)` has score `2 * A`, where `A` is a balanced ...
null
[Python] Quick maths (slightly different from other solns)
consecutive-numbers-sum
0
1
If n can be written as the sum of consecutive integers, say from y+1, y+2, ..., x, then it is also the difference between the sum of the first x positive integers and the first y positive integers. Thus, we can write\nn = x(x+1)/2-y(y+1)/2<=>\n8n = 4x^2+4x+1-(4y^2+4y+1)<=>\n8n =(2x+1)^2 - (2y+1)^2<=>\n8n = (2x-2y)(2x+...
1
Given an integer `n`, return _the number of ways you can write_ `n` _as the sum of consecutive positive integers._ **Example 1:** **Input:** n = 5 **Output:** 2 **Explanation:** 5 = 2 + 3 **Example 2:** **Input:** n = 9 **Output:** 3 **Explanation:** 9 = 4 + 5 = 2 + 3 + 4 **Example 3:** **Input:** n = 15 **Output...
null
[Python] Quick maths (slightly different from other solns)
consecutive-numbers-sum
0
1
If n can be written as the sum of consecutive integers, say from y+1, y+2, ..., x, then it is also the difference between the sum of the first x positive integers and the first y positive integers. Thus, we can write\nn = x(x+1)/2-y(y+1)/2<=>\n8n = 4x^2+4x+1-(4y^2+4y+1)<=>\n8n =(2x+1)^2 - (2y+1)^2<=>\n8n = (2x-2y)(2x+...
1
Given a balanced parentheses string `s`, return _the **score** of the string_. The **score** of a balanced parentheses string is based on the following rule: * `"() "` has score `1`. * `AB` has score `A + B`, where `A` and `B` are balanced parentheses strings. * `(A)` has score `2 * A`, where `A` is a balanced ...
null
8 lines Python3 code
consecutive-numbers-sum
0
1
Let say integer **n** is equal to sum of **i** consecutive positive integers. Then \n**n=a+(a+1)+(a+2)..+(a+i-1)**\n**=ai+(0+1+2+...+(i-1))**\nso **(n-(0+1+2+...+(i-1)))/i==a**, which means if **(n-(0+1+2+...+(i-1))) % i ==0**, there will be integer **a** and **i** satisfies the requirement.\n\n\n\n```\nclass Solution:...
7
Given an integer `n`, return _the number of ways you can write_ `n` _as the sum of consecutive positive integers._ **Example 1:** **Input:** n = 5 **Output:** 2 **Explanation:** 5 = 2 + 3 **Example 2:** **Input:** n = 9 **Output:** 3 **Explanation:** 9 = 4 + 5 = 2 + 3 + 4 **Example 3:** **Input:** n = 15 **Output...
null
8 lines Python3 code
consecutive-numbers-sum
0
1
Let say integer **n** is equal to sum of **i** consecutive positive integers. Then \n**n=a+(a+1)+(a+2)..+(a+i-1)**\n**=ai+(0+1+2+...+(i-1))**\nso **(n-(0+1+2+...+(i-1)))/i==a**, which means if **(n-(0+1+2+...+(i-1))) % i ==0**, there will be integer **a** and **i** satisfies the requirement.\n\n\n\n```\nclass Solution:...
7
Given a balanced parentheses string `s`, return _the **score** of the string_. The **score** of a balanced parentheses string is based on the following rule: * `"() "` has score `1`. * `AB` has score `A + B`, where `A` and `B` are balanced parentheses strings. * `(A)` has score `2 * A`, where `A` is a balanced ...
null
Solution
positions-of-large-groups
1
1
```C++ []\nclass Solution {\npublic:\n vector<vector<int>> largeGroupPositions(string s) {\n vector<vector<int>> ans;\n int start = 0, n = s.length(), end;\n for (end = 0; end < n; ++end) {\n if (s[end] != s[start]) {\n if (end-start >= 3) {\n ans.pus...
2
In a string `s` of lowercase letters, these letters form consecutive groups of the same character. For example, a string like `s = "abbxxxxzyy "` has the groups `"a "`, `"bb "`, `"xxxx "`, `"z "`, and `"yy "`. A group is identified by an interval `[start, end]`, where `start` and `end` denote the start and end indice...
null
Solution
positions-of-large-groups
1
1
```C++ []\nclass Solution {\npublic:\n vector<vector<int>> largeGroupPositions(string s) {\n vector<vector<int>> ans;\n int start = 0, n = s.length(), end;\n for (end = 0; end < n; ++end) {\n if (s[end] != s[start]) {\n if (end-start >= 3) {\n ans.pus...
2
There are `n` workers. You are given two integer arrays `quality` and `wage` where `quality[i]` is the quality of the `ith` worker and `wage[i]` is the minimum wage expectation for the `ith` worker. We want to hire exactly `k` workers to form a paid group. To hire a group of `k` workers, we must pay them according to ...
null
Python Two Pointer - O(n) - Time Complexity in Top 92 %
positions-of-large-groups
0
1
```\nclass Solution:\n def largeGroupPositions(self, S: str) -> List[List[int]]:\n left = 0 \n return_list = []\n S += \'1\'\n for index, letter in enumerate(S):\n if letter != S[left]:\n if index - left >= 3:\n return_list.append([left, index ...
11
In a string `s` of lowercase letters, these letters form consecutive groups of the same character. For example, a string like `s = "abbxxxxzyy "` has the groups `"a "`, `"bb "`, `"xxxx "`, `"z "`, and `"yy "`. A group is identified by an interval `[start, end]`, where `start` and `end` denote the start and end indice...
null
Python Two Pointer - O(n) - Time Complexity in Top 92 %
positions-of-large-groups
0
1
```\nclass Solution:\n def largeGroupPositions(self, S: str) -> List[List[int]]:\n left = 0 \n return_list = []\n S += \'1\'\n for index, letter in enumerate(S):\n if letter != S[left]:\n if index - left >= 3:\n return_list.append([left, index ...
11
There are `n` workers. You are given two integer arrays `quality` and `wage` where `quality[i]` is the quality of the `ith` worker and `wage[i]` is the minimum wage expectation for the `ith` worker. We want to hire exactly `k` workers to form a paid group. To hire a group of `k` workers, we must pay them according to ...
null
Straight forward solutions
positions-of-large-groups
0
1
# Code\n```\nclass Solution:\n def largeGroupPositions(self, s: str) -> List[List[int]]:\n n = len(s)\n if n < 3:\n return ""\n \n temp, prev, cnt = [[0, 0]], s[0], 1\n for k, char in enumerate(s[1:]):\n if prev == char:\n cnt += 1\n ...
0
In a string `s` of lowercase letters, these letters form consecutive groups of the same character. For example, a string like `s = "abbxxxxzyy "` has the groups `"a "`, `"bb "`, `"xxxx "`, `"z "`, and `"yy "`. A group is identified by an interval `[start, end]`, where `start` and `end` denote the start and end indice...
null
Straight forward solutions
positions-of-large-groups
0
1
# Code\n```\nclass Solution:\n def largeGroupPositions(self, s: str) -> List[List[int]]:\n n = len(s)\n if n < 3:\n return ""\n \n temp, prev, cnt = [[0, 0]], s[0], 1\n for k, char in enumerate(s[1:]):\n if prev == char:\n cnt += 1\n ...
0
There are `n` workers. You are given two integer arrays `quality` and `wage` where `quality[i]` is the quality of the `ith` worker and `wage[i]` is the minimum wage expectation for the `ith` worker. We want to hire exactly `k` workers to form a paid group. To hire a group of `k` workers, we must pay them according to ...
null
Simple Python3 solution w/ for loops
positions-of-large-groups
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
In a string `s` of lowercase letters, these letters form consecutive groups of the same character. For example, a string like `s = "abbxxxxzyy "` has the groups `"a "`, `"bb "`, `"xxxx "`, `"z "`, and `"yy "`. A group is identified by an interval `[start, end]`, where `start` and `end` denote the start and end indice...
null
Simple Python3 solution w/ for loops
positions-of-large-groups
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
There are `n` workers. You are given two integer arrays `quality` and `wage` where `quality[i]` is the quality of the `ith` worker and `wage[i]` is the minimum wage expectation for the `ith` worker. We want to hire exactly `k` workers to form a paid group. To hire a group of `k` workers, we must pay them according to ...
null
Python easy solution
positions-of-large-groups
0
1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nUsing start, end, temp and prev variable and then just iterate through loop in s.\n\n# Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass...
0
In a string `s` of lowercase letters, these letters form consecutive groups of the same character. For example, a string like `s = "abbxxxxzyy "` has the groups `"a "`, `"bb "`, `"xxxx "`, `"z "`, and `"yy "`. A group is identified by an interval `[start, end]`, where `start` and `end` denote the start and end indice...
null
Python easy solution
positions-of-large-groups
0
1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nUsing start, end, temp and prev variable and then just iterate through loop in s.\n\n# Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass...
0
There are `n` workers. You are given two integer arrays `quality` and `wage` where `quality[i]` is the quality of the `ith` worker and `wage[i]` is the minimum wage expectation for the `ith` worker. We want to hire exactly `k` workers to form a paid group. To hire a group of `k` workers, we must pay them according to ...
null
Simple Python3 Solution || Upto 100 % Faster
positions-of-large-groups
0
1
\n![image.png](https://assets.leetcode.com/users/images/986e9196-2b4d-41b2-85cb-dce19d6738bc_1696501712.3068585.png)\n\n# Complexity\n- Time complexity:\nO(2n)\n\n- Space complexity:\nO(n)\n\n# Code\n```\nclass Solution:\n def largeGroupPositions(self, s: str) -> List[List[int]]:\n if len(set(s)) == 1:\n ...
0
In a string `s` of lowercase letters, these letters form consecutive groups of the same character. For example, a string like `s = "abbxxxxzyy "` has the groups `"a "`, `"bb "`, `"xxxx "`, `"z "`, and `"yy "`. A group is identified by an interval `[start, end]`, where `start` and `end` denote the start and end indice...
null
Simple Python3 Solution || Upto 100 % Faster
positions-of-large-groups
0
1
\n![image.png](https://assets.leetcode.com/users/images/986e9196-2b4d-41b2-85cb-dce19d6738bc_1696501712.3068585.png)\n\n# Complexity\n- Time complexity:\nO(2n)\n\n- Space complexity:\nO(n)\n\n# Code\n```\nclass Solution:\n def largeGroupPositions(self, s: str) -> List[List[int]]:\n if len(set(s)) == 1:\n ...
0
There are `n` workers. You are given two integer arrays `quality` and `wage` where `quality[i]` is the quality of the `ith` worker and `wage[i]` is the minimum wage expectation for the `ith` worker. We want to hire exactly `k` workers to form a paid group. To hire a group of `k` workers, we must pay them according to ...
null
Solution
masking-personal-information
1
1
```C++ []\nclass Solution {\npublic:\n string maskPII(string S) {\n auto at = S.find("@");\n if (at != string::npos) {\n transform(S.begin(), S.end(), S.begin(), ::tolower);\n return S.substr(0, 1) + "*****" + S.substr(at - 1);\n }\n string digits;\n for (cons...
1
You are given a personal information string `s`, representing either an **email address** or a **phone number**. Return _the **masked** personal information using the below rules_. **Email address:** An email address is: * A **name** consisting of uppercase and lowercase English letters, followed by * The `'@'` ...
null
Solution
masking-personal-information
1
1
```C++ []\nclass Solution {\npublic:\n string maskPII(string S) {\n auto at = S.find("@");\n if (at != string::npos) {\n transform(S.begin(), S.end(), S.begin(), ::tolower);\n return S.substr(0, 1) + "*****" + S.substr(at - 1);\n }\n string digits;\n for (cons...
1
There is a special square room with mirrors on each of the four walls. Except for the southwest corner, there are receptors on each of the remaining corners, numbered `0`, `1`, and `2`. The square room has walls of length `p` and a laser ray from the southwest corner first meets the east wall at a distance `q` from th...
null
Follow the rules and solve
masking-personal-information
0
1
\n\n# Code\n```\nclass Solution:\n def maskPII(self, s: str) -> str:\n # Email\n if \'@\' in s:\n s = s.lower()\n a = s.split(\'@\')[0]\n b = s.split(\'@\')[1]\n a = a[0]+\'*\'*5+a[-1]\n return a+\'@\'+b\n # Phone Number\n else:\n ...
1
You are given a personal information string `s`, representing either an **email address** or a **phone number**. Return _the **masked** personal information using the below rules_. **Email address:** An email address is: * A **name** consisting of uppercase and lowercase English letters, followed by * The `'@'` ...
null
Follow the rules and solve
masking-personal-information
0
1
\n\n# Code\n```\nclass Solution:\n def maskPII(self, s: str) -> str:\n # Email\n if \'@\' in s:\n s = s.lower()\n a = s.split(\'@\')[0]\n b = s.split(\'@\')[1]\n a = a[0]+\'*\'*5+a[-1]\n return a+\'@\'+b\n # Phone Number\n else:\n ...
1
There is a special square room with mirrors on each of the four walls. Except for the southwest corner, there are receptors on each of the remaining corners, numbered `0`, `1`, and `2`. The square room has walls of length `p` and a laser ray from the southwest corner first meets the east wall at a distance `q` from th...
null
Python by case solution
masking-personal-information
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 a personal information string `s`, representing either an **email address** or a **phone number**. Return _the **masked** personal information using the below rules_. **Email address:** An email address is: * A **name** consisting of uppercase and lowercase English letters, followed by * The `'@'` ...
null
Python by case solution
masking-personal-information
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
There is a special square room with mirrors on each of the four walls. Except for the southwest corner, there are receptors on each of the remaining corners, numbered `0`, `1`, and `2`. The square room has walls of length `p` and a laser ray from the southwest corner first meets the east wall at a distance `q` from th...
null
Easy Solution || Helpful for beginners || Clearly Understandable...
masking-personal-information
0
1
# INFORMATION:\n```\nNAME : NARRESH KUMAR S\nSITE : nareshkumar.allgen.tech\n```\n# Code\n```\nclass Solution:\n def maskPII(self, s: str) -> str:\n def phNo(s):\n n = ""\n res = ""\n for i in s:\n if i.isdigit():\n n += i\n l = len...
0
You are given a personal information string `s`, representing either an **email address** or a **phone number**. Return _the **masked** personal information using the below rules_. **Email address:** An email address is: * A **name** consisting of uppercase and lowercase English letters, followed by * The `'@'` ...
null
Easy Solution || Helpful for beginners || Clearly Understandable...
masking-personal-information
0
1
# INFORMATION:\n```\nNAME : NARRESH KUMAR S\nSITE : nareshkumar.allgen.tech\n```\n# Code\n```\nclass Solution:\n def maskPII(self, s: str) -> str:\n def phNo(s):\n n = ""\n res = ""\n for i in s:\n if i.isdigit():\n n += i\n l = len...
0
There is a special square room with mirrors on each of the four walls. Except for the southwest corner, there are receptors on each of the remaining corners, numbered `0`, `1`, and `2`. The square room has walls of length `p` and a laser ray from the southwest corner first meets the east wall at a distance `q` from th...
null