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 |
|---|---|---|---|---|---|---|---|
Solution | profitable-schemes | 1 | 1 | ```C++ []\nconstexpr int MAX = 128;\nconstexpr int MOD = 1000000007;\nint sum[MAX], dp[MAX][MAX];\nint Add(int a, int b, int p = MOD) {\n int c = a + b;\n return c < p ? c : c - p;\n}\nint Sub(int a, int b, int p = MOD) {\n int c = a - b;\n return c < 0 ? c + p : c;\n}\nclass Solution {\npublic:\n int profitable... | 1 | There is a group of `n` members, and a list of various crimes they could commit. The `ith` crime generates a `profit[i]` and requires `group[i]` members to participate in it. If a member participates in one crime, that member can't participate in another crime.
Let's call a **profitable scheme** any subset of these cr... | null |
Solution | profitable-schemes | 1 | 1 | ```C++ []\nconstexpr int MAX = 128;\nconstexpr int MOD = 1000000007;\nint sum[MAX], dp[MAX][MAX];\nint Add(int a, int b, int p = MOD) {\n int c = a + b;\n return c < p ? c : c - p;\n}\nint Sub(int a, int b, int p = MOD) {\n int c = a - b;\n return c < 0 ? c + p : c;\n}\nclass Solution {\npublic:\n int profitable... | 1 | You are given two integer arrays `persons` and `times`. In an election, the `ith` vote was cast for `persons[i]` at time `times[i]`.
For each query at a time `t`, find the person that was leading the election at time `t`. Votes cast at time `t` will count towards our query. In the case of a tie, the most recent vote (... | null |
✔️✔️Easy Solutions in Python ✔️✔️with Explanation | profitable-schemes | 0 | 1 | # Intuition - Use dfs and dp - by bruteforcing\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach - knapsack problem with additional check\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ ... | 1 | There is a group of `n` members, and a list of various crimes they could commit. The `ith` crime generates a `profit[i]` and requires `group[i]` members to participate in it. If a member participates in one crime, that member can't participate in another crime.
Let's call a **profitable scheme** any subset of these cr... | null |
✔️✔️Easy Solutions in Python ✔️✔️with Explanation | profitable-schemes | 0 | 1 | # Intuition - Use dfs and dp - by bruteforcing\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach - knapsack problem with additional check\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ ... | 1 | You are given two integer arrays `persons` and `times`. In an election, the `ith` vote was cast for `persons[i]` at time `times[i]`.
For each query at a time `t`, find the person that was leading the election at time `t`. Votes cast at time `t` will count towards our query. In the case of a tie, the most recent vote (... | null |
Short Python Solution | profitable-schemes | 0 | 1 | \n# Complexity\n- Time complexity: $$ O(n*minProfit*len(group))$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$ O(n*minProfit*len(group))$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution:\n def profitableSchemes(self, n: int, minProfit: int, ... | 1 | There is a group of `n` members, and a list of various crimes they could commit. The `ith` crime generates a `profit[i]` and requires `group[i]` members to participate in it. If a member participates in one crime, that member can't participate in another crime.
Let's call a **profitable scheme** any subset of these cr... | null |
Short Python Solution | profitable-schemes | 0 | 1 | \n# Complexity\n- Time complexity: $$ O(n*minProfit*len(group))$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$ O(n*minProfit*len(group))$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution:\n def profitableSchemes(self, n: int, minProfit: int, ... | 1 | You are given two integer arrays `persons` and `times`. In an election, the `ith` vote was cast for `persons[i]` at time `times[i]`.
For each query at a time `t`, find the person that was leading the election at time `t`. Votes cast at time `t` will count towards our query. In the case of a tie, the most recent vote (... | null |
Python Solution Top Down DFS with 3D Cache | profitable-schemes | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 1 | There is a group of `n` members, and a list of various crimes they could commit. The `ith` crime generates a `profit[i]` and requires `group[i]` members to participate in it. If a member participates in one crime, that member can't participate in another crime.
Let's call a **profitable scheme** any subset of these cr... | null |
Python Solution Top Down DFS with 3D Cache | profitable-schemes | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 1 | You are given two integer arrays `persons` and `times`. In an election, the `ith` vote was cast for `persons[i]` at time `times[i]`.
For each query at a time `t`, find the person that was leading the election at time `t`. Votes cast at time `t` will count towards our query. In the case of a tie, the most recent vote (... | null |
Python short and clean 1-liner. DP. Functional programming. | profitable-schemes | 0 | 1 | # Approach\nTry both, picking and skipping, for each `group` until there are no more `people` or `group` left.\n\nSince there are overlappimg subproblems, and optimal sub-structure, cache / memoize the results. (DP)\n\n# Complexity\n- Time complexity: $$O(n * k * m)$$\n\n- Space complexity: $$O(n * k * m)$$\n\nwhere,\n... | 3 | There is a group of `n` members, and a list of various crimes they could commit. The `ith` crime generates a `profit[i]` and requires `group[i]` members to participate in it. If a member participates in one crime, that member can't participate in another crime.
Let's call a **profitable scheme** any subset of these cr... | null |
Python short and clean 1-liner. DP. Functional programming. | profitable-schemes | 0 | 1 | # Approach\nTry both, picking and skipping, for each `group` until there are no more `people` or `group` left.\n\nSince there are overlappimg subproblems, and optimal sub-structure, cache / memoize the results. (DP)\n\n# Complexity\n- Time complexity: $$O(n * k * m)$$\n\n- Space complexity: $$O(n * k * m)$$\n\nwhere,\n... | 3 | You are given two integer arrays `persons` and `times`. In an election, the `ith` vote was cast for `persons[i]` at time `times[i]`.
For each query at a time `t`, find the person that was leading the election at time `t`. Votes cast at time `t` will count towards our query. In the case of a tie, the most recent vote (... | null |
Detailed Explanation Ever - Most Optimised code with 100% Runtime and Memory Acceptance in C++ | decoded-string-at-index | 1 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe code aims to decode an encoded string by iteratively expanding it based on the digits found in the string. The goal is to find the kth character (1-indexed) in the decoded string efficiently.\n\n---\n\n# Approach\n<!-- Describe your a... | 12 | You are given an encoded string `s`. To decode the string to a tape, the encoded string is read one character at a time and the following steps are taken:
* If the character read is a letter, that letter is written onto the tape.
* If the character read is a digit `d`, the entire current tape is repeatedly written... | null |
Detailed Explanation Ever - Most Optimised code with 100% Runtime and Memory Acceptance in C++ | decoded-string-at-index | 1 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe code aims to decode an encoded string by iteratively expanding it based on the digits found in the string. The goal is to find the kth character (1-indexed) in the decoded string efficiently.\n\n---\n\n# Approach\n<!-- Describe your a... | 12 | You are given two string arrays `words1` and `words2`.
A string `b` is a **subset** of string `a` if every letter in `b` occurs in `a` including multiplicity.
* For example, `"wrr "` is a subset of `"warrior "` but is not a subset of `"world "`.
A string `a` from `words1` is **universal** if for every string `b` i... | null |
🚀100% || Reverse || Stack || Commented Code🚀 | decoded-string-at-index | 1 | 1 | # Problem Description\nThe tasked is **decoding** an encoded string following specific **rules**. \n- The encoded string is read character by character, and actions are taken accordingly: \n - letters are directly written to a tape,\n - digits determine how many times the current content of the tape is repeated. ... | 242 | You are given an encoded string `s`. To decode the string to a tape, the encoded string is read one character at a time and the following steps are taken:
* If the character read is a letter, that letter is written onto the tape.
* If the character read is a digit `d`, the entire current tape is repeatedly written... | null |
🚀100% || Reverse || Stack || Commented Code🚀 | decoded-string-at-index | 1 | 1 | # Problem Description\nThe tasked is **decoding** an encoded string following specific **rules**. \n- The encoded string is read character by character, and actions are taken accordingly: \n - letters are directly written to a tape,\n - digits determine how many times the current content of the tape is repeated. ... | 242 | You are given two string arrays `words1` and `words2`.
A string `b` is a **subset** of string `a` if every letter in `b` occurs in `a` including multiplicity.
* For example, `"wrr "` is a subset of `"warrior "` but is not a subset of `"world "`.
A string `a` from `words1` is **universal** if for every string `b` i... | null |
✅ 97.47% Reverse Traversal | decoded-string-at-index | 1 | 1 | # Interview Guide: "Decoded String at Index" Problem\n\n## Problem Understanding\n\nThe "Decoded String at Index" problem requires you to decode a given string based on specific rules. When a letter is encountered, it\'s written as is; when a digit is encountered, the decoded string so far is repeated that many times. ... | 146 | You are given an encoded string `s`. To decode the string to a tape, the encoded string is read one character at a time and the following steps are taken:
* If the character read is a letter, that letter is written onto the tape.
* If the character read is a digit `d`, the entire current tape is repeatedly written... | null |
✅ 97.47% Reverse Traversal | decoded-string-at-index | 1 | 1 | # Interview Guide: "Decoded String at Index" Problem\n\n## Problem Understanding\n\nThe "Decoded String at Index" problem requires you to decode a given string based on specific rules. When a letter is encountered, it\'s written as is; when a digit is encountered, the decoded string so far is repeated that many times. ... | 146 | You are given two string arrays `words1` and `words2`.
A string `b` is a **subset** of string `a` if every letter in `b` occurs in `a` including multiplicity.
* For example, `"wrr "` is a subset of `"warrior "` but is not a subset of `"world "`.
A string `a` from `words1` is **universal** if for every string `b` i... | null |
Easy to Understand python solution (beats 80%) | decoded-string-at-index | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nSave the length of actual array ending at each index. (lArray)\nRecursively Find the index where it is same as k.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: \n<!-- Add your t... | 1 | You are given an encoded string `s`. To decode the string to a tape, the encoded string is read one character at a time and the following steps are taken:
* If the character read is a letter, that letter is written onto the tape.
* If the character read is a digit `d`, the entire current tape is repeatedly written... | null |
Easy to Understand python solution (beats 80%) | decoded-string-at-index | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nSave the length of actual array ending at each index. (lArray)\nRecursively Find the index where it is same as k.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: \n<!-- Add your t... | 1 | You are given two string arrays `words1` and `words2`.
A string `b` is a **subset** of string `a` if every letter in `b` occurs in `a` including multiplicity.
* For example, `"wrr "` is a subset of `"warrior "` but is not a subset of `"world "`.
A string `a` from `words1` is **universal** if for every string `b` i... | null |
Decode At Index Solution in Python3 | decoded-string-at-index | 0 | 1 | \n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nHere\'s a step-by-step explanation of the code:\n\n1. Initialize variables:\n\n- n stores the length of the input string s.\n- i is an index variable used to iterate through the string s.\n- count is a variable used to keep track of the length of ... | 1 | You are given an encoded string `s`. To decode the string to a tape, the encoded string is read one character at a time and the following steps are taken:
* If the character read is a letter, that letter is written onto the tape.
* If the character read is a digit `d`, the entire current tape is repeatedly written... | null |
Decode At Index Solution in Python3 | decoded-string-at-index | 0 | 1 | \n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nHere\'s a step-by-step explanation of the code:\n\n1. Initialize variables:\n\n- n stores the length of the input string s.\n- i is an index variable used to iterate through the string s.\n- count is a variable used to keep track of the length of ... | 1 | You are given two string arrays `words1` and `words2`.
A string `b` is a **subset** of string `a` if every letter in `b` occurs in `a` including multiplicity.
* For example, `"wrr "` is a subset of `"warrior "` but is not a subset of `"world "`.
A string `a` from `words1` is **universal** if for every string `b` i... | null |
📈Beats🧭 99.73% ✅ | 🔥Clean & Concise Code | Easy Understanding🔥 | decoded-string-at-index | 1 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe code aims to decode an encoded string by iteratively expanding it based on the digits found in the string. The goal is to find the kth character (1-indexed) in the decoded string efficiently.\n\n---\n\n# Approach\n<!-- Describe your a... | 2 | You are given an encoded string `s`. To decode the string to a tape, the encoded string is read one character at a time and the following steps are taken:
* If the character read is a letter, that letter is written onto the tape.
* If the character read is a digit `d`, the entire current tape is repeatedly written... | null |
📈Beats🧭 99.73% ✅ | 🔥Clean & Concise Code | Easy Understanding🔥 | decoded-string-at-index | 1 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe code aims to decode an encoded string by iteratively expanding it based on the digits found in the string. The goal is to find the kth character (1-indexed) in the decoded string efficiently.\n\n---\n\n# Approach\n<!-- Describe your a... | 2 | You are given two string arrays `words1` and `words2`.
A string `b` is a **subset** of string `a` if every letter in `b` occurs in `a` including multiplicity.
* For example, `"wrr "` is a subset of `"warrior "` but is not a subset of `"world "`.
A string `a` from `words1` is **universal** if for every string `b` i... | null |
Python3 Solution | decoded-string-at-index | 0 | 1 | \n```\nclass Solution:\n def decodeAtIndex(self, s: str, k: int) -> str:\n n=len(s)\n i=0\n count=0\n while i<n:\n if s[i].isnumeric():\n if (int(s[i])-1)*count>=k:\n i=0\n count=0\n continue\n ... | 0 | You are given an encoded string `s`. To decode the string to a tape, the encoded string is read one character at a time and the following steps are taken:
* If the character read is a letter, that letter is written onto the tape.
* If the character read is a digit `d`, the entire current tape is repeatedly written... | null |
Python3 Solution | decoded-string-at-index | 0 | 1 | \n```\nclass Solution:\n def decodeAtIndex(self, s: str, k: int) -> str:\n n=len(s)\n i=0\n count=0\n while i<n:\n if s[i].isnumeric():\n if (int(s[i])-1)*count>=k:\n i=0\n count=0\n continue\n ... | 0 | You are given two string arrays `words1` and `words2`.
A string `b` is a **subset** of string `a` if every letter in `b` occurs in `a` including multiplicity.
* For example, `"wrr "` is a subset of `"warrior "` but is not a subset of `"world "`.
A string `a` from `words1` is **universal** if for every string `b` i... | null |
【Video】How I think about a solution - Python Java, C++ | decoded-string-at-index | 1 | 1 | Welcome to my article! This artcle starts with "How we think about a solution". In other words, that is my thought process to solve the question. This article explains how I get to my solution instead of just posting solution codes or out of blue algorithms. I hope this aricle is helpful for someone.\n\n# Intuition\ntr... | 40 | You are given an encoded string `s`. To decode the string to a tape, the encoded string is read one character at a time and the following steps are taken:
* If the character read is a letter, that letter is written onto the tape.
* If the character read is a digit `d`, the entire current tape is repeatedly written... | null |
【Video】How I think about a solution - Python Java, C++ | decoded-string-at-index | 1 | 1 | Welcome to my article! This artcle starts with "How we think about a solution". In other words, that is my thought process to solve the question. This article explains how I get to my solution instead of just posting solution codes or out of blue algorithms. I hope this aricle is helpful for someone.\n\n# Intuition\ntr... | 40 | You are given two string arrays `words1` and `words2`.
A string `b` is a **subset** of string `a` if every letter in `b` occurs in `a` including multiplicity.
* For example, `"wrr "` is a subset of `"warrior "` but is not a subset of `"world "`.
A string `a` from `words1` is **universal** if for every string `b` i... | null |
Explain to solution in easiest method......Try it..(^_^) | decoded-string-at-index | 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 an encoded string `s`. To decode the string to a tape, the encoded string is read one character at a time and the following steps are taken:
* If the character read is a letter, that letter is written onto the tape.
* If the character read is a digit `d`, the entire current tape is repeatedly written... | null |
Explain to solution in easiest method......Try it..(^_^) | decoded-string-at-index | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 0 | You are given two string arrays `words1` and `words2`.
A string `b` is a **subset** of string `a` if every letter in `b` occurs in `a` including multiplicity.
* For example, `"wrr "` is a subset of `"warrior "` but is not a subset of `"world "`.
A string `a` from `words1` is **universal** if for every string `b` i... | null |
⭐Explained Python 2 Pointers Solution | boats-to-save-people | 0 | 1 | **OBSERVATIONS:**\n```\nLets take an example: People = [1, 1, 2, 3, 9, 10, 11, 12] and Limit = 12\n```\n\n1. Since we want to minimise the number of boats used, we must try to form pair of largest and smallest ... | 53 | You are given an array `people` where `people[i]` is the weight of the `ith` person, and an **infinite number of boats** where each boat can carry a maximum weight of `limit`. Each boat carries at most two people at the same time, provided the sum of the weight of those people is at most `limit`.
Return _the minimum n... | null |
⭐Explained Python 2 Pointers Solution | boats-to-save-people | 0 | 1 | **OBSERVATIONS:**\n```\nLets take an example: People = [1, 1, 2, 3, 9, 10, 11, 12] and Limit = 12\n```\n\n1. Since we want to minimise the number of boats used, we must try to form pair of largest and smallest ... | 53 | Given a string `s`, reverse the string according to the following rules:
* All the characters that are not English letters remain in the same position.
* All the English letters (lowercase or uppercase) should be reversed.
Return `s` _after reversing it_.
**Example 1:**
**Input:** s = "ab-cd"
**Output:** "dc-ba... | null |
[Java, Python & C++] Easy to Understand and Efficient Solutions. | boats-to-save-people | 1 | 1 | # Approach\nTwo Pointer Approach\n\n\n# Complexity\n- Time complexity: O(nlogn)\n\n- Space complexity: O(n)\n\n\n# Code\n### Java\n```\nclass Solution {\n public int numRescueBoats(int[] people, int limit) {\n Arrays.sort(people);\n int start = 0; \n int end = people.length - 1;\n int res... | 6 | You are given an array `people` where `people[i]` is the weight of the `ith` person, and an **infinite number of boats** where each boat can carry a maximum weight of `limit`. Each boat carries at most two people at the same time, provided the sum of the weight of those people is at most `limit`.
Return _the minimum n... | null |
[Java, Python & C++] Easy to Understand and Efficient Solutions. | boats-to-save-people | 1 | 1 | # Approach\nTwo Pointer Approach\n\n\n# Complexity\n- Time complexity: O(nlogn)\n\n- Space complexity: O(n)\n\n\n# Code\n### Java\n```\nclass Solution {\n public int numRescueBoats(int[] people, int limit) {\n Arrays.sort(people);\n int start = 0; \n int end = people.length - 1;\n int res... | 6 | Given a string `s`, reverse the string according to the following rules:
* All the characters that are not English letters remain in the same position.
* All the English letters (lowercase or uppercase) should be reversed.
Return `s` _after reversing it_.
**Example 1:**
**Input:** s = "ab-cd"
**Output:** "dc-ba... | null |
✅✅Python🔥Java🔥C++🔥Simple Solution🔥Easy to Understand🔥 | boats-to-save-people | 1 | 1 | # Please UPVOTE \uD83D\uDC4D\n\n**!! BIG ANNOUNCEMENT !!**\nI am currently Giving away my premium content well-structured assignments and study materials to clear interviews at top companies related to computer science and data science to my current Subscribers this week. I planned to give for next 10,000 Subscribers a... | 18 | You are given an array `people` where `people[i]` is the weight of the `ith` person, and an **infinite number of boats** where each boat can carry a maximum weight of `limit`. Each boat carries at most two people at the same time, provided the sum of the weight of those people is at most `limit`.
Return _the minimum n... | null |
✅✅Python🔥Java🔥C++🔥Simple Solution🔥Easy to Understand🔥 | boats-to-save-people | 1 | 1 | # Please UPVOTE \uD83D\uDC4D\n\n**!! BIG ANNOUNCEMENT !!**\nI am currently Giving away my premium content well-structured assignments and study materials to clear interviews at top companies related to computer science and data science to my current Subscribers this week. I planned to give for next 10,000 Subscribers a... | 18 | Given a string `s`, reverse the string according to the following rules:
* All the characters that are not English letters remain in the same position.
* All the English letters (lowercase or uppercase) should be reversed.
Return `s` _after reversing it_.
**Example 1:**
**Input:** s = "ab-cd"
**Output:** "dc-ba... | null |
Solution | boats-to-save-people | 1 | 1 | ```C++ []\nclass Solution {\npublic:\n int numRescueBoats(vector<int>& people, int limit) {\n std::ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);\n int freq[30001] = {0};\n int hv = INT_MIN;\n int lt = INT_MAX;\n for(int i : people){\n hv = max(hv, i);\n ... | 1 | You are given an array `people` where `people[i]` is the weight of the `ith` person, and an **infinite number of boats** where each boat can carry a maximum weight of `limit`. Each boat carries at most two people at the same time, provided the sum of the weight of those people is at most `limit`.
Return _the minimum n... | null |
Solution | boats-to-save-people | 1 | 1 | ```C++ []\nclass Solution {\npublic:\n int numRescueBoats(vector<int>& people, int limit) {\n std::ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);\n int freq[30001] = {0};\n int hv = INT_MIN;\n int lt = INT_MAX;\n for(int i : people){\n hv = max(hv, i);\n ... | 1 | Given a string `s`, reverse the string according to the following rules:
* All the characters that are not English letters remain in the same position.
* All the English letters (lowercase or uppercase) should be reversed.
Return `s` _after reversing it_.
**Example 1:**
**Input:** s = "ab-cd"
**Output:** "dc-ba... | null |
Python BS-paring with heaviest within limit O(n^2) worsest O(nlogn) ave | boats-to-save-people | 0 | 1 | # Intuition\nI know pairing the heaviest with the next heaviest within limit is an overkill and the following code using BS is not as efficient as pairing with the lightest. But to me, it\'s really more intuitive that the more greedy way to pair the heaviest with the next heaviest within limit.\n<!-- Describe your firs... | 1 | You are given an array `people` where `people[i]` is the weight of the `ith` person, and an **infinite number of boats** where each boat can carry a maximum weight of `limit`. Each boat carries at most two people at the same time, provided the sum of the weight of those people is at most `limit`.
Return _the minimum n... | null |
Python BS-paring with heaviest within limit O(n^2) worsest O(nlogn) ave | boats-to-save-people | 0 | 1 | # Intuition\nI know pairing the heaviest with the next heaviest within limit is an overkill and the following code using BS is not as efficient as pairing with the lightest. But to me, it\'s really more intuitive that the more greedy way to pair the heaviest with the next heaviest within limit.\n<!-- Describe your firs... | 1 | Given a string `s`, reverse the string according to the following rules:
* All the characters that are not English letters remain in the same position.
* All the English letters (lowercase or uppercase) should be reversed.
Return `s` _after reversing it_.
**Example 1:**
**Input:** s = "ab-cd"
**Output:** "dc-ba... | null |
April 3rd Daily Challenge | | 🐍 | | Two pointer approach | | Fastest | boats-to-save-people | 0 | 1 | \n# Approach\n<!-- Describe your approach to solving the problem. -->\n-> Sort the given array\n-> Take two pointers on either side of the array\n-> If sum of items on both sides <= Limit , then i+=1 and j-=1\n-> Else decrease right pointer by 1\n-> Increment the result by repeating the above process until starting poi... | 1 | You are given an array `people` where `people[i]` is the weight of the `ith` person, and an **infinite number of boats** where each boat can carry a maximum weight of `limit`. Each boat carries at most two people at the same time, provided the sum of the weight of those people is at most `limit`.
Return _the minimum n... | null |
April 3rd Daily Challenge | | 🐍 | | Two pointer approach | | Fastest | boats-to-save-people | 0 | 1 | \n# Approach\n<!-- Describe your approach to solving the problem. -->\n-> Sort the given array\n-> Take two pointers on either side of the array\n-> If sum of items on both sides <= Limit , then i+=1 and j-=1\n-> Else decrease right pointer by 1\n-> Increment the result by repeating the above process until starting poi... | 1 | Given a string `s`, reverse the string according to the following rules:
* All the characters that are not English letters remain in the same position.
* All the English letters (lowercase or uppercase) should be reversed.
Return `s` _after reversing it_.
**Example 1:**
**Input:** s = "ab-cd"
**Output:** "dc-ba... | null |
Solution | reachable-nodes-in-subdivided-graph | 1 | 1 | ```C++ []\nclass Solution {\n public:\n int reachableNodes(vector<vector<int>>& edges, int maxMoves, int n) {\n vector<vector<pair<int, int>>> graph(n);\n vector<int> dist(graph.size(), maxMoves + 1);\n\n for (const vector<int>& edge : edges) {\n const int u = edge[0];\n const int v = edge[1];\n ... | 1 | You are given an undirected graph (the **"original graph "**) with `n` nodes labeled from `0` to `n - 1`. You decide to **subdivide** each edge in the graph into a chain of nodes, with the number of new nodes varying between each edge.
The graph is given as a 2D array of `edges` where `edges[i] = [ui, vi, cnti]` indic... | null |
Solution | reachable-nodes-in-subdivided-graph | 1 | 1 | ```C++ []\nclass Solution {\n public:\n int reachableNodes(vector<vector<int>>& edges, int maxMoves, int n) {\n vector<vector<pair<int, int>>> graph(n);\n vector<int> dist(graph.size(), maxMoves + 1);\n\n for (const vector<int>& edge : edges) {\n const int u = edge[0];\n const int v = edge[1];\n ... | 1 | Given a **circular integer array** `nums` of length `n`, return _the maximum possible sum of a non-empty **subarray** of_ `nums`.
A **circular array** means the end of the array connects to the beginning of the array. Formally, the next element of `nums[i]` is `nums[(i + 1) % n]` and the previous element of `nums[i]` ... | null |
Clear and simple python3 solution | Dijkstra's algorithm + additional count | reachable-nodes-in-subdivided-graph | 0 | 1 | # Complexity\n\n- Time complexity: $$O(n^2)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(n^2)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n``` python3 []\nimport heapq\n\nclass Solution:\n def reachableNodes(self, edges: List[List[int]], maxMoves: int, n... | 1 | You are given an undirected graph (the **"original graph "**) with `n` nodes labeled from `0` to `n - 1`. You decide to **subdivide** each edge in the graph into a chain of nodes, with the number of new nodes varying between each edge.
The graph is given as a 2D array of `edges` where `edges[i] = [ui, vi, cnti]` indic... | null |
Clear and simple python3 solution | Dijkstra's algorithm + additional count | reachable-nodes-in-subdivided-graph | 0 | 1 | # Complexity\n\n- Time complexity: $$O(n^2)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(n^2)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n``` python3 []\nimport heapq\n\nclass Solution:\n def reachableNodes(self, edges: List[List[int]], maxMoves: int, n... | 1 | Given a **circular integer array** `nums` of length `n`, return _the maximum possible sum of a non-empty **subarray** of_ `nums`.
A **circular array** means the end of the array connects to the beginning of the array. Formally, the next element of `nums[i]` is `nums[(i + 1) % n]` and the previous element of `nums[i]` ... | null |
[Python] BFS - 3 Steps | reachable-nodes-in-subdivided-graph | 0 | 1 | **Approach:**\n\nPerform BFS (starting with M steps at node 0) to find the \nmaximum number of steps remaining after reaching each node.\n```v``` is a map of node to maximum steps remaining after reaching node.\n\nFor each pair of original nodes, the number of new nodes between them is ```n```.\nSay node ```a``` and ``... | 10 | You are given an undirected graph (the **"original graph "**) with `n` nodes labeled from `0` to `n - 1`. You decide to **subdivide** each edge in the graph into a chain of nodes, with the number of new nodes varying between each edge.
The graph is given as a 2D array of `edges` where `edges[i] = [ui, vi, cnti]` indic... | null |
[Python] BFS - 3 Steps | reachable-nodes-in-subdivided-graph | 0 | 1 | **Approach:**\n\nPerform BFS (starting with M steps at node 0) to find the \nmaximum number of steps remaining after reaching each node.\n```v``` is a map of node to maximum steps remaining after reaching node.\n\nFor each pair of original nodes, the number of new nodes between them is ```n```.\nSay node ```a``` and ``... | 10 | Given a **circular integer array** `nums` of length `n`, return _the maximum possible sum of a non-empty **subarray** of_ `nums`.
A **circular array** means the end of the array connects to the beginning of the array. Formally, the next element of `nums[i]` is `nums[(i + 1) % n]` and the previous element of `nums[i]` ... | null |
✅BFS || Python | reachable-nodes-in-subdivided-graph | 0 | 1 | \n# Code\n```\nclass Solution:\n def reachableNodes(self, edges: List[List[int]], maxMoves: int, n: int) -> int:\n graph=[[0 for i in range(n)]for i in range(n)]\n for v in edges:\n graph[v[0]][v[1]]=v[2]+1\n graph[v[1]][v[0]]=v[2]+1\n q=[[0,0]]\n heapify(q)\n ... | 0 | You are given an undirected graph (the **"original graph "**) with `n` nodes labeled from `0` to `n - 1`. You decide to **subdivide** each edge in the graph into a chain of nodes, with the number of new nodes varying between each edge.
The graph is given as a 2D array of `edges` where `edges[i] = [ui, vi, cnti]` indic... | null |
✅BFS || Python | reachable-nodes-in-subdivided-graph | 0 | 1 | \n# Code\n```\nclass Solution:\n def reachableNodes(self, edges: List[List[int]], maxMoves: int, n: int) -> int:\n graph=[[0 for i in range(n)]for i in range(n)]\n for v in edges:\n graph[v[0]][v[1]]=v[2]+1\n graph[v[1]][v[0]]=v[2]+1\n q=[[0,0]]\n heapify(q)\n ... | 0 | Given a **circular integer array** `nums` of length `n`, return _the maximum possible sum of a non-empty **subarray** of_ `nums`.
A **circular array** means the end of the array connects to the beginning of the array. Formally, the next element of `nums[i]` is `nums[(i + 1) % n]` and the previous element of `nums[i]` ... | null |
Python 3: Dijkstra's solution with comments | reachable-nodes-in-subdivided-graph | 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 an undirected graph (the **"original graph "**) with `n` nodes labeled from `0` to `n - 1`. You decide to **subdivide** each edge in the graph into a chain of nodes, with the number of new nodes varying between each edge.
The graph is given as a 2D array of `edges` where `edges[i] = [ui, vi, cnti]` indic... | null |
Python 3: Dijkstra's solution with comments | reachable-nodes-in-subdivided-graph | 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 **circular integer array** `nums` of length `n`, return _the maximum possible sum of a non-empty **subarray** of_ `nums`.
A **circular array** means the end of the array connects to the beginning of the array. Formally, the next element of `nums[i]` is `nums[(i + 1) % n]` and the previous element of `nums[i]` ... | null |
Why is everyone complicating the solution <My Solution> | reachable-nodes-in-subdivided-graph | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe extra nodes that we have to add in between can be considered as the edge length between the two nodes. If there is edge from ```u``` to ```v``` with edge length ```w```, then ```v``` is at the ```w+1``` moves from ```u```.\n\n# Approa... | 0 | You are given an undirected graph (the **"original graph "**) with `n` nodes labeled from `0` to `n - 1`. You decide to **subdivide** each edge in the graph into a chain of nodes, with the number of new nodes varying between each edge.
The graph is given as a 2D array of `edges` where `edges[i] = [ui, vi, cnti]` indic... | null |
Why is everyone complicating the solution <My Solution> | reachable-nodes-in-subdivided-graph | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe extra nodes that we have to add in between can be considered as the edge length between the two nodes. If there is edge from ```u``` to ```v``` with edge length ```w```, then ```v``` is at the ```w+1``` moves from ```u```.\n\n# Approa... | 0 | Given a **circular integer array** `nums` of length `n`, return _the maximum possible sum of a non-empty **subarray** of_ `nums`.
A **circular array** means the end of the array connects to the beginning of the array. Formally, the next element of `nums[i]` is `nums[(i + 1) % n]` and the previous element of `nums[i]` ... | null |
Solution | projection-area-of-3d-shapes | 1 | 1 | ```C++ []\nclass Solution {\npublic:\n int projectionArea(vector<vector<int>>& grid) {\n int n = grid.size(), area = 0;\n vector<int> x_v(n), y_v(n);\n for (int x = 0; x < n; x++) {\n for (int y = 0; y < n; y++) {\n int v = grid[x][y];\n if (v) {\n ... | 2 | You are given an `n x n` `grid` where we place some `1 x 1 x 1` cubes that are axis-aligned with the `x`, `y`, and `z` axes.
Each value `v = grid[i][j]` represents a tower of `v` cubes placed on top of the cell `(i, j)`.
We view the projection of these cubes onto the `xy`, `yz`, and `zx` planes.
A **projection** is ... | null |
Solution | projection-area-of-3d-shapes | 1 | 1 | ```C++ []\nclass Solution {\npublic:\n int projectionArea(vector<vector<int>>& grid) {\n int n = grid.size(), area = 0;\n vector<int> x_v(n), y_v(n);\n for (int x = 0; x < n; x++) {\n for (int y = 0; y < n; y++) {\n int v = grid[x][y];\n if (v) {\n ... | 2 | A **complete binary tree** is a binary tree in which every level, except possibly the last, is completely filled, and all nodes are as far left as possible.
Design an algorithm to insert a new node to a complete binary tree keeping it complete after the insertion.
Implement the `CBTInserter` class:
* `CBTInserter(... | null |
“You don't have to be a mathematician to have a feel for numbers.” - John Forbes Nash | projection-area-of-3d-shapes | 0 | 1 | \n# Code\n```\nclass Solution:\n def projectionArea(self, grid: List[List[int]]) -> int:\n \n if len(grid)==1:\n return 1+grid[0][0]*2\n s=0\n l=[]\n for j in range(len(grid)):\n f2=0\n for i in range(len(grid)):\n f2=max(grid[i][j],f... | 0 | You are given an `n x n` `grid` where we place some `1 x 1 x 1` cubes that are axis-aligned with the `x`, `y`, and `z` axes.
Each value `v = grid[i][j]` represents a tower of `v` cubes placed on top of the cell `(i, j)`.
We view the projection of these cubes onto the `xy`, `yz`, and `zx` planes.
A **projection** is ... | null |
“You don't have to be a mathematician to have a feel for numbers.” - John Forbes Nash | projection-area-of-3d-shapes | 0 | 1 | \n# Code\n```\nclass Solution:\n def projectionArea(self, grid: List[List[int]]) -> int:\n \n if len(grid)==1:\n return 1+grid[0][0]*2\n s=0\n l=[]\n for j in range(len(grid)):\n f2=0\n for i in range(len(grid)):\n f2=max(grid[i][j],f... | 0 | A **complete binary tree** is a binary tree in which every level, except possibly the last, is completely filled, and all nodes are as far left as possible.
Design an algorithm to insert a new node to a complete binary tree keeping it complete after the insertion.
Implement the `CBTInserter` class:
* `CBTInserter(... | null |
python || bruteforce solution | projection-area-of-3d-shapes | 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 an `n x n` `grid` where we place some `1 x 1 x 1` cubes that are axis-aligned with the `x`, `y`, and `z` axes.
Each value `v = grid[i][j]` represents a tower of `v` cubes placed on top of the cell `(i, j)`.
We view the projection of these cubes onto the `xy`, `yz`, and `zx` planes.
A **projection** is ... | null |
python || bruteforce solution | projection-area-of-3d-shapes | 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 | A **complete binary tree** is a binary tree in which every level, except possibly the last, is completely filled, and all nodes are as far left as possible.
Design an algorithm to insert a new node to a complete binary tree keeping it complete after the insertion.
Implement the `CBTInserter` class:
* `CBTInserter(... | null |
Easiest Solution | projection-area-of-3d-shapes | 1 | 1 | \n\n# Code\n```java []\nclass Solution {\n public int projectionArea(int[][] grid) \n {\n int x=0,y=0,z=0;\n\n for(int i=0;i<grid.length;i++)\n {\n for(int j=0;j<grid[0].length;j++)\n {\n if(grid[i][j]!=0) x++;\n }\n }\n\n for(int ... | 0 | You are given an `n x n` `grid` where we place some `1 x 1 x 1` cubes that are axis-aligned with the `x`, `y`, and `z` axes.
Each value `v = grid[i][j]` represents a tower of `v` cubes placed on top of the cell `(i, j)`.
We view the projection of these cubes onto the `xy`, `yz`, and `zx` planes.
A **projection** is ... | null |
Easiest Solution | projection-area-of-3d-shapes | 1 | 1 | \n\n# Code\n```java []\nclass Solution {\n public int projectionArea(int[][] grid) \n {\n int x=0,y=0,z=0;\n\n for(int i=0;i<grid.length;i++)\n {\n for(int j=0;j<grid[0].length;j++)\n {\n if(grid[i][j]!=0) x++;\n }\n }\n\n for(int ... | 0 | A **complete binary tree** is a binary tree in which every level, except possibly the last, is completely filled, and all nodes are as far left as possible.
Design an algorithm to insert a new node to a complete binary tree keeping it complete after the insertion.
Implement the `CBTInserter` class:
* `CBTInserter(... | null |
Python: two one-liners | projection-area-of-3d-shapes | 0 | 1 | \n# Complexity\n- Time complexity: Both solutions are $$O(n^2)$$ which is the time needed to iterate over the matrix anyways.\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: Both are technically $$O(n)$$ due to the unpacking in the `zip(*grid)` call, but this is probably optimized by the P... | 0 | You are given an `n x n` `grid` where we place some `1 x 1 x 1` cubes that are axis-aligned with the `x`, `y`, and `z` axes.
Each value `v = grid[i][j]` represents a tower of `v` cubes placed on top of the cell `(i, j)`.
We view the projection of these cubes onto the `xy`, `yz`, and `zx` planes.
A **projection** is ... | null |
Python: two one-liners | projection-area-of-3d-shapes | 0 | 1 | \n# Complexity\n- Time complexity: Both solutions are $$O(n^2)$$ which is the time needed to iterate over the matrix anyways.\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: Both are technically $$O(n)$$ due to the unpacking in the `zip(*grid)` call, but this is probably optimized by the P... | 0 | A **complete binary tree** is a binary tree in which every level, except possibly the last, is completely filled, and all nodes are as far left as possible.
Design an algorithm to insert a new node to a complete binary tree keeping it complete after the insertion.
Implement the `CBTInserter` class:
* `CBTInserter(... | null |
a lot of loops | projection-area-of-3d-shapes | 0 | 1 | \n# Code\n```\nclass Solution:\n def projectionArea(self, grid: List[List[int]]) -> int:\n [\n [1,2],\n [3,4]\n ]\n todown = 0\n for row in grid:\n for el in row:\n if el!=0:\n todown+=1\n toright = 0\n for r... | 0 | You are given an `n x n` `grid` where we place some `1 x 1 x 1` cubes that are axis-aligned with the `x`, `y`, and `z` axes.
Each value `v = grid[i][j]` represents a tower of `v` cubes placed on top of the cell `(i, j)`.
We view the projection of these cubes onto the `xy`, `yz`, and `zx` planes.
A **projection** is ... | null |
a lot of loops | projection-area-of-3d-shapes | 0 | 1 | \n# Code\n```\nclass Solution:\n def projectionArea(self, grid: List[List[int]]) -> int:\n [\n [1,2],\n [3,4]\n ]\n todown = 0\n for row in grid:\n for el in row:\n if el!=0:\n todown+=1\n toright = 0\n for r... | 0 | A **complete binary tree** is a binary tree in which every level, except possibly the last, is completely filled, and all nodes are as far left as possible.
Design an algorithm to insert a new node to a complete binary tree keeping it complete after the insertion.
Implement the `CBTInserter` class:
* `CBTInserter(... | null |
Sol | projection-area-of-3d-shapes | 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 an `n x n` `grid` where we place some `1 x 1 x 1` cubes that are axis-aligned with the `x`, `y`, and `z` axes.
Each value `v = grid[i][j]` represents a tower of `v` cubes placed on top of the cell `(i, j)`.
We view the projection of these cubes onto the `xy`, `yz`, and `zx` planes.
A **projection** is ... | null |
Sol | projection-area-of-3d-shapes | 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 | A **complete binary tree** is a binary tree in which every level, except possibly the last, is completely filled, and all nodes are as far left as possible.
Design an algorithm to insert a new node to a complete binary tree keeping it complete after the insertion.
Implement the `CBTInserter` class:
* `CBTInserter(... | null |
Simple Solution | 30 ms | Beats 99% | Accepted 🔥🚀🚀 | projection-area-of-3d-shapes | 0 | 1 | # Code\n```\nclass Solution:\n def projectionArea(self, x: List[List[int]]) -> int:\n s=len(x)*len(x[0])\n y=list(zip(*x))\n for i in x: s-=i.count(0)\n y=[list(y[i]) for i in range(len(y))]\n for i in x: s+=max(i)\n for i in y: s+=max(i)\n return s\n``` | 0 | You are given an `n x n` `grid` where we place some `1 x 1 x 1` cubes that are axis-aligned with the `x`, `y`, and `z` axes.
Each value `v = grid[i][j]` represents a tower of `v` cubes placed on top of the cell `(i, j)`.
We view the projection of these cubes onto the `xy`, `yz`, and `zx` planes.
A **projection** is ... | null |
Simple Solution | 30 ms | Beats 99% | Accepted 🔥🚀🚀 | projection-area-of-3d-shapes | 0 | 1 | # Code\n```\nclass Solution:\n def projectionArea(self, x: List[List[int]]) -> int:\n s=len(x)*len(x[0])\n y=list(zip(*x))\n for i in x: s-=i.count(0)\n y=[list(y[i]) for i in range(len(y))]\n for i in x: s+=max(i)\n for i in y: s+=max(i)\n return s\n``` | 0 | A **complete binary tree** is a binary tree in which every level, except possibly the last, is completely filled, and all nodes are as far left as possible.
Design an algorithm to insert a new node to a complete binary tree keeping it complete after the insertion.
Implement the `CBTInserter` class:
* `CBTInserter(... | null |
FREE BOBI python solution using counter | uncommon-words-from-two-sentences | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 1 | A **sentence** is a string of single-space separated words where each word consists only of lowercase letters.
A word is **uncommon** if it appears exactly once in one of the sentences, and **does not appear** in the other sentence.
Given two **sentences** `s1` and `s2`, return _a list of all the **uncommon words**_.... | null |
FREE BOBI python solution using counter | uncommon-words-from-two-sentences | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 1 | Your music player contains `n` different songs. You want to listen to `goal` songs (not necessarily different) during your trip. To avoid boredom, you will create a playlist so that:
* Every song is played **at least once**.
* A song can only be played again only if `k` other songs have been played.
Given `n`, `g... | null |
Python3 easy solution | uncommon-words-from-two-sentences | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 1 | A **sentence** is a string of single-space separated words where each word consists only of lowercase letters.
A word is **uncommon** if it appears exactly once in one of the sentences, and **does not appear** in the other sentence.
Given two **sentences** `s1` and `s2`, return _a list of all the **uncommon words**_.... | null |
Python3 easy solution | uncommon-words-from-two-sentences | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 1 | Your music player contains `n` different songs. You want to listen to `goal` songs (not necessarily different) during your trip. To avoid boredom, you will create a playlist so that:
* Every song is played **at least once**.
* A song can only be played again only if `k` other songs have been played.
Given `n`, `g... | null |
Python Easy Solution || Hash Table | uncommon-words-from-two-sentences | 0 | 1 | # Complexity\n- Time complexity:\nO(n+m)\n\n- Space complexity:\nO(n+m)\n\n# Code\n```\nclass Solution:\n def uncommonFromSentences(self, s1: str, s2: str) -> List[str]:\n dic={}\n res=[]\n s1=s1.rsplit()\n s2=s2.rsplit()\n for i in s1+s2:\n if i in dic:\n ... | 3 | A **sentence** is a string of single-space separated words where each word consists only of lowercase letters.
A word is **uncommon** if it appears exactly once in one of the sentences, and **does not appear** in the other sentence.
Given two **sentences** `s1` and `s2`, return _a list of all the **uncommon words**_.... | null |
Python Easy Solution || Hash Table | uncommon-words-from-two-sentences | 0 | 1 | # Complexity\n- Time complexity:\nO(n+m)\n\n- Space complexity:\nO(n+m)\n\n# Code\n```\nclass Solution:\n def uncommonFromSentences(self, s1: str, s2: str) -> List[str]:\n dic={}\n res=[]\n s1=s1.rsplit()\n s2=s2.rsplit()\n for i in s1+s2:\n if i in dic:\n ... | 3 | Your music player contains `n` different songs. You want to listen to `goal` songs (not necessarily different) during your trip. To avoid boredom, you will create a playlist so that:
* Every song is played **at least once**.
* A song can only be played again only if `k` other songs have been played.
Given `n`, `g... | null |
Accepted Python3: One-Liner using Counter from collections | uncommon-words-from-two-sentences | 0 | 1 | ```\nfrom collections import Counter as c\n\nclass Solution:\n def uncommonFromSentences(self, A: str, B: str) -> List[str]:\n return [k for k, v in c(A.split() + B.split()).items() if v == 1]\n``` | 14 | A **sentence** is a string of single-space separated words where each word consists only of lowercase letters.
A word is **uncommon** if it appears exactly once in one of the sentences, and **does not appear** in the other sentence.
Given two **sentences** `s1` and `s2`, return _a list of all the **uncommon words**_.... | null |
Accepted Python3: One-Liner using Counter from collections | uncommon-words-from-two-sentences | 0 | 1 | ```\nfrom collections import Counter as c\n\nclass Solution:\n def uncommonFromSentences(self, A: str, B: str) -> List[str]:\n return [k for k, v in c(A.split() + B.split()).items() if v == 1]\n``` | 14 | Your music player contains `n` different songs. You want to listen to `goal` songs (not necessarily different) during your trip. To avoid boredom, you will create a playlist so that:
* Every song is played **at least once**.
* A song can only be played again only if `k` other songs have been played.
Given `n`, `g... | null |
Solution | spiral-matrix-iii | 1 | 1 | ```C++ []\nclass Solution {\npublic:\n vector<vector<int>> spiralMatrixIII(int rows, int cols, int rStart, int cStart) {\n \n ios_base::sync_with_stdio(false);\n cin.tie(NULL);\n cout.tie(NULL);\n\n vector<vector<int>> result;\n int total = 0;\n\n int rowStart = rStar... | 1 | You start at the cell `(rStart, cStart)` of an `rows x cols` grid facing east. The northwest corner is at the first row and column in the grid, and the southeast corner is at the last row and column.
You will walk in a clockwise spiral shape to visit every position in this grid. Whenever you move outside the grid's bo... | null |
Solution | spiral-matrix-iii | 1 | 1 | ```C++ []\nclass Solution {\npublic:\n vector<vector<int>> spiralMatrixIII(int rows, int cols, int rStart, int cStart) {\n \n ios_base::sync_with_stdio(false);\n cin.tie(NULL);\n cout.tie(NULL);\n\n vector<vector<int>> result;\n int total = 0;\n\n int rowStart = rStar... | 1 | A parentheses string is valid if and only if:
* It is the empty string,
* It can be written as `AB` (`A` concatenated with `B`), where `A` and `B` are valid strings, or
* It can be written as `(A)`, where `A` is a valid string.
You are given a parentheses string `s`. In one move, you can insert a parenthesis at... | null |
Easy Python Solution Based on Spiral Matrix I and II | spiral-matrix-iii | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nAfter every iteration of a row or column we need to widen our range.\nIf the first row we\'re reading is length of two when we read if in reverse direction we need to add one more element to it.\nEg. Lets read a row in to the left directi... | 3 | You start at the cell `(rStart, cStart)` of an `rows x cols` grid facing east. The northwest corner is at the first row and column in the grid, and the southeast corner is at the last row and column.
You will walk in a clockwise spiral shape to visit every position in this grid. Whenever you move outside the grid's bo... | null |
Easy Python Solution Based on Spiral Matrix I and II | spiral-matrix-iii | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nAfter every iteration of a row or column we need to widen our range.\nIf the first row we\'re reading is length of two when we read if in reverse direction we need to add one more element to it.\nEg. Lets read a row in to the left directi... | 3 | A parentheses string is valid if and only if:
* It is the empty string,
* It can be written as `AB` (`A` concatenated with `B`), where `A` and `B` are valid strings, or
* It can be written as `(A)`, where `A` is a valid string.
You are given a parentheses string `s`. In one move, you can insert a parenthesis at... | null |
simple simulation solution || python | spiral-matrix-iii | 1 | 1 | # Intuition and Approach\n* start the simulation from starting cell and insert position of cells in to ans which lie within the matrix\n\n# Complexity\n- Time complexity: O(N^2)\n\n- Space complexity: O(N^2)\n\n# Code\n```\nclass Solution:\n def spiralMatrixIII(self, m: int, n: int, i: int, j: int) -> List[List[int]... | 1 | You start at the cell `(rStart, cStart)` of an `rows x cols` grid facing east. The northwest corner is at the first row and column in the grid, and the southeast corner is at the last row and column.
You will walk in a clockwise spiral shape to visit every position in this grid. Whenever you move outside the grid's bo... | null |
simple simulation solution || python | spiral-matrix-iii | 1 | 1 | # Intuition and Approach\n* start the simulation from starting cell and insert position of cells in to ans which lie within the matrix\n\n# Complexity\n- Time complexity: O(N^2)\n\n- Space complexity: O(N^2)\n\n# Code\n```\nclass Solution:\n def spiralMatrixIII(self, m: int, n: int, i: int, j: int) -> List[List[int]... | 1 | A parentheses string is valid if and only if:
* It is the empty string,
* It can be written as `AB` (`A` concatenated with `B`), where `A` and `B` are valid strings, or
* It can be written as `(A)`, where `A` is a valid string.
You are given a parentheses string `s`. In one move, you can insert a parenthesis at... | null |
easy understanding for beginners | spiral-matrix-iii | 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(rows * cols)\n\n- Space complexity:\nO(rows * cols)\n\n# Code\n```\nclass Solution:\n def spiralMatrixIII(self, rows: int, cols:... | 0 | You start at the cell `(rStart, cStart)` of an `rows x cols` grid facing east. The northwest corner is at the first row and column in the grid, and the southeast corner is at the last row and column.
You will walk in a clockwise spiral shape to visit every position in this grid. Whenever you move outside the grid's bo... | null |
easy understanding for beginners | spiral-matrix-iii | 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(rows * cols)\n\n- Space complexity:\nO(rows * cols)\n\n# Code\n```\nclass Solution:\n def spiralMatrixIII(self, rows: int, cols:... | 0 | A parentheses string is valid if and only if:
* It is the empty string,
* It can be written as `AB` (`A` concatenated with `B`), where `A` and `B` are valid strings, or
* It can be written as `(A)`, where `A` is a valid string.
You are given a parentheses string `s`. In one move, you can insert a parenthesis at... | null |
Best java submission with 99.9% beat | spiral-matrix-iii | 1 | 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)$$ -->\no(m*n) where m = no. of rows and n = no. of columns\n99.6% beat \n\n- Space ... | 0 | You start at the cell `(rStart, cStart)` of an `rows x cols` grid facing east. The northwest corner is at the first row and column in the grid, and the southeast corner is at the last row and column.
You will walk in a clockwise spiral shape to visit every position in this grid. Whenever you move outside the grid's bo... | null |
Best java submission with 99.9% beat | spiral-matrix-iii | 1 | 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)$$ -->\no(m*n) where m = no. of rows and n = no. of columns\n99.6% beat \n\n- Space ... | 0 | A parentheses string is valid if and only if:
* It is the empty string,
* It can be written as `AB` (`A` concatenated with `B`), where `A` and `B` are valid strings, or
* It can be written as `(A)`, where `A` is a valid string.
You are given a parentheses string `s`. In one move, you can insert a parenthesis at... | null |
Python - Color Solution - Video Solution | possible-bipartition | 0 | 1 | I have explained this [here](https://youtu.be/Zqvdg0TmAnE).\n\n```\nclass Solution:\n def possibleBipartition(self, n: int, dislikes: List[List[int]]) -> bool:\n \n g = defaultdict(list)\n for x,y in dislikes:\n g[x].append(y)\n g[y].append(x)\n \n color = {}\... | 2 | We want to split a group of `n` people (labeled from `1` to `n`) into two groups of **any size**. Each person may dislike some other people, and they should not go into the same group.
Given the integer `n` and the array `dislikes` where `dislikes[i] = [ai, bi]` indicates that the person labeled `ai` does not like the... | null |
Python - Color Solution - Video Solution | possible-bipartition | 0 | 1 | I have explained this [here](https://youtu.be/Zqvdg0TmAnE).\n\n```\nclass Solution:\n def possibleBipartition(self, n: int, dislikes: List[List[int]]) -> bool:\n \n g = defaultdict(list)\n for x,y in dislikes:\n g[x].append(y)\n g[y].append(x)\n \n color = {}\... | 2 | Given an array of integers `nums`, half of the integers in `nums` are **odd**, and the other half are **even**.
Sort the array so that whenever `nums[i]` is odd, `i` is **odd**, and whenever `nums[i]` is even, `i` is **even**.
Return _any answer array that satisfies this condition_.
**Example 1:**
**Input:** nums =... | null |
Solution | possible-bipartition | 1 | 1 | ```C++ []\nvoid make(int n,int size[],int par[]){\n for(int i=0;i<n;i++){\n size[i] = 1;\n par[i] = i;\n }\n}\nint find(int a,int par[]){\n if(par[a]==a){\n return a;\n }\n par[a] = find(par[a],par);\n return par[a];\n}\nvoid Union(int a,int b,int size[],int par[]){\n a = find(... | 1 | We want to split a group of `n` people (labeled from `1` to `n`) into two groups of **any size**. Each person may dislike some other people, and they should not go into the same group.
Given the integer `n` and the array `dislikes` where `dislikes[i] = [ai, bi]` indicates that the person labeled `ai` does not like the... | null |
Solution | possible-bipartition | 1 | 1 | ```C++ []\nvoid make(int n,int size[],int par[]){\n for(int i=0;i<n;i++){\n size[i] = 1;\n par[i] = i;\n }\n}\nint find(int a,int par[]){\n if(par[a]==a){\n return a;\n }\n par[a] = find(par[a],par);\n return par[a];\n}\nvoid Union(int a,int b,int size[],int par[]){\n a = find(... | 1 | Given an array of integers `nums`, half of the integers in `nums` are **odd**, and the other half are **even**.
Sort the array so that whenever `nums[i]` is odd, `i` is **odd**, and whenever `nums[i]` is even, `i` is **even**.
Return _any answer array that satisfies this condition_.
**Example 1:**
**Input:** nums =... | null |
[Python] Union-Find in O(E), The Best | possible-bipartition | 0 | 1 | # Approach\nKeeping root and rank arrays of size $$n$$ is unnecessary. The hashmap-based union-find implementation below supports all value types, and keeps neither single-node ranks nor roots of root nodes in the maps.\n\nThe Best!\n\n# Complexity\n- Time complexity: $$O(E \\cdot\\alpha(E)) \\approx O(E)$$\n- Space co... | 1 | We want to split a group of `n` people (labeled from `1` to `n`) into two groups of **any size**. Each person may dislike some other people, and they should not go into the same group.
Given the integer `n` and the array `dislikes` where `dislikes[i] = [ai, bi]` indicates that the person labeled `ai` does not like the... | null |
[Python] Union-Find in O(E), The Best | possible-bipartition | 0 | 1 | # Approach\nKeeping root and rank arrays of size $$n$$ is unnecessary. The hashmap-based union-find implementation below supports all value types, and keeps neither single-node ranks nor roots of root nodes in the maps.\n\nThe Best!\n\n# Complexity\n- Time complexity: $$O(E \\cdot\\alpha(E)) \\approx O(E)$$\n- Space co... | 1 | Given an array of integers `nums`, half of the integers in `nums` are **odd**, and the other half are **even**.
Sort the array so that whenever `nums[i]` is odd, `i` is **odd**, and whenever `nums[i]` is even, `i` is **even**.
Return _any answer array that satisfies this condition_.
**Example 1:**
**Input:** nums =... | null |
Python || DFS, BFS, Union-Find & Odd-Cycle Solutions | possible-bipartition | 0 | 1 | # Code\n```\nfrom collections import deque\nfrom dataclasses import dataclass\nfrom functools import cached_property\nfrom typing import Optional\n\nUNEXPLORED = None\n\n\nclass Solution:\n def possibleBipartition(self, n: int, dislikes: list[list[int]]) -> bool:\n """\n we first create a graph, say g,... | 1 | We want to split a group of `n` people (labeled from `1` to `n`) into two groups of **any size**. Each person may dislike some other people, and they should not go into the same group.
Given the integer `n` and the array `dislikes` where `dislikes[i] = [ai, bi]` indicates that the person labeled `ai` does not like the... | null |
Python || DFS, BFS, Union-Find & Odd-Cycle Solutions | possible-bipartition | 0 | 1 | # Code\n```\nfrom collections import deque\nfrom dataclasses import dataclass\nfrom functools import cached_property\nfrom typing import Optional\n\nUNEXPLORED = None\n\n\nclass Solution:\n def possibleBipartition(self, n: int, dislikes: list[list[int]]) -> bool:\n """\n we first create a graph, say g,... | 1 | Given an array of integers `nums`, half of the integers in `nums` are **odd**, and the other half are **even**.
Sort the array so that whenever `nums[i]` is odd, `i` is **odd**, and whenever `nums[i]` is even, `i` is **even**.
Return _any answer array that satisfies this condition_.
**Example 1:**
**Input:** nums =... | null |
Python BFS solution | possible-bipartition | 0 | 1 | ```\nclass Solution:\n def possibleBipartition(self, n: int, dislikes: List[List[int]]) -> bool:\n visited=[0]*n\n group=[-1]*n\n adj=[[] for _ in range(n)]\n for i,j in dislikes:\n adj[i-1].append(j-1)\n adj[j-1].append(i-1)\n \n for k in range(n):... | 1 | We want to split a group of `n` people (labeled from `1` to `n`) into two groups of **any size**. Each person may dislike some other people, and they should not go into the same group.
Given the integer `n` and the array `dislikes` where `dislikes[i] = [ai, bi]` indicates that the person labeled `ai` does not like the... | null |
Python BFS solution | possible-bipartition | 0 | 1 | ```\nclass Solution:\n def possibleBipartition(self, n: int, dislikes: List[List[int]]) -> bool:\n visited=[0]*n\n group=[-1]*n\n adj=[[] for _ in range(n)]\n for i,j in dislikes:\n adj[i-1].append(j-1)\n adj[j-1].append(i-1)\n \n for k in range(n):... | 1 | Given an array of integers `nums`, half of the integers in `nums` are **odd**, and the other half are **even**.
Sort the array so that whenever `nums[i]` is odd, `i` is **odd**, and whenever `nums[i]` is even, `i` is **even**.
Return _any answer array that satisfies this condition_.
**Example 1:**
**Input:** nums =... | null |
Beats 100% | CodeDominar Solution | possible-bipartition | 0 | 1 | - **Time complexity:** `O(V + E), where V is the number of vertices and E is the number of edges in the graph.`\n\n# Code\n```\nclass Solution:\n def possibleBipartition(self, n: int, dislikes: List[List[int]]) -> bool: \n # Create an adjacency list representation of the graph\n adj_list = [[] for ... | 37 | We want to split a group of `n` people (labeled from `1` to `n`) into two groups of **any size**. Each person may dislike some other people, and they should not go into the same group.
Given the integer `n` and the array `dislikes` where `dislikes[i] = [ai, bi]` indicates that the person labeled `ai` does not like the... | null |
Beats 100% | CodeDominar Solution | possible-bipartition | 0 | 1 | - **Time complexity:** `O(V + E), where V is the number of vertices and E is the number of edges in the graph.`\n\n# Code\n```\nclass Solution:\n def possibleBipartition(self, n: int, dislikes: List[List[int]]) -> bool: \n # Create an adjacency list representation of the graph\n adj_list = [[] for ... | 37 | Given an array of integers `nums`, half of the integers in `nums` are **odd**, and the other half are **even**.
Sort the array so that whenever `nums[i]` is odd, `i` is **odd**, and whenever `nums[i]` is even, `i` is **even**.
Return _any answer array that satisfies this condition_.
**Example 1:**
**Input:** nums =... | null |
Python/C++/Java sol by DFS and coloring. [w/ Graph] | possible-bipartition | 1 | 1 | Sol by DFS and coloring.\n\n---\n\n**Hint**:\n\nThink of **graph**, **node coloring**, and **DFS**.\n\nAbstract model transformation:\n\n**Person** <-> **Node**\n\nP1 **dislikes P2** <-> Node 1 and Node 2 **share one edge**, and they should be **drawed with different two colors** (i.e., for dislike relation)\n\n\nIf we... | 251 | We want to split a group of `n` people (labeled from `1` to `n`) into two groups of **any size**. Each person may dislike some other people, and they should not go into the same group.
Given the integer `n` and the array `dislikes` where `dislikes[i] = [ai, bi]` indicates that the person labeled `ai` does not like the... | null |
Python/C++/Java sol by DFS and coloring. [w/ Graph] | possible-bipartition | 1 | 1 | Sol by DFS and coloring.\n\n---\n\n**Hint**:\n\nThink of **graph**, **node coloring**, and **DFS**.\n\nAbstract model transformation:\n\n**Person** <-> **Node**\n\nP1 **dislikes P2** <-> Node 1 and Node 2 **share one edge**, and they should be **drawed with different two colors** (i.e., for dislike relation)\n\n\nIf we... | 251 | Given an array of integers `nums`, half of the integers in `nums` are **odd**, and the other half are **even**.
Sort the array so that whenever `nums[i]` is odd, `i` is **odd**, and whenever `nums[i]` is even, `i` is **even**.
Return _any answer array that satisfies this condition_.
**Example 1:**
**Input:** nums =... | null |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.