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 |
|---|---|---|---|---|---|---|---|
Easy python solution | binary-string-with-substrings-representing-1-to-n | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nImplement integer to binary your own way. Avoid in build functions. Best will be if you implement the find function yourself too. \nProtip : there van be atmost len(s)^2 unique numbers generated from the string. So if the n is bigger than... | 0 | Given a binary string `s` and a positive integer `n`, return `true` _if the binary representation of all the integers in the range_ `[1, n]` _are **substrings** of_ `s`_, or_ `false` _otherwise_.
A **substring** is a contiguous sequence of characters within a string.
**Example 1:**
**Input:** s = "0110", n = 3
**Out... | null |
Easy python solution | binary-string-with-substrings-representing-1-to-n | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nImplement integer to binary your own way. Avoid in build functions. Best will be if you implement the find function yourself too. \nProtip : there van be atmost len(s)^2 unique numbers generated from the string. So if the n is bigger than... | 0 | Given a string `text` and an array of strings `words`, return _an array of all index pairs_ `[i, j]` _so that the substring_ `text[i...j]` _is in `words`_.
Return the pairs `[i, j]` in sorted order (i.e., sort them by their first coordinate, and in case of ties sort them by their second coordinate).
**Example 1:**
*... | We only need to check substrings of length at most 30, because 10^9 has 30 bits. |
We only need to test n < 1023 after analysis | binary-string-with-substrings-representing-1-to-n | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nActually, we don\'t need to test numbers more than 1023, so it could be much faster in theory.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nFirst, once we check `1 + X`, we don\'t need to check `X` since it\'s a... | 0 | Given a binary string `s` and a positive integer `n`, return `true` _if the binary representation of all the integers in the range_ `[1, n]` _are **substrings** of_ `s`_, or_ `false` _otherwise_.
A **substring** is a contiguous sequence of characters within a string.
**Example 1:**
**Input:** s = "0110", n = 3
**Out... | null |
We only need to test n < 1023 after analysis | binary-string-with-substrings-representing-1-to-n | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nActually, we don\'t need to test numbers more than 1023, so it could be much faster in theory.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nFirst, once we check `1 + X`, we don\'t need to check `X` since it\'s a... | 0 | Given a string `text` and an array of strings `words`, return _an array of all index pairs_ `[i, j]` _so that the substring_ `text[i...j]` _is in `words`_.
Return the pairs `[i, j]` in sorted order (i.e., sort them by their first coordinate, and in case of ties sort them by their second coordinate).
**Example 1:**
*... | We only need to check substrings of length at most 30, because 10^9 has 30 bits. |
Solution | convert-to-base-2 | 1 | 1 | ```C++ []\nclass Solution {\npublic:\n string baseNeg2(int n) {\n if (n == 0)\n return "0";\n string out = "";\n while (n) {\n out = ((n&1) ? "1" : "0") + out;\n n = -(n >> 1);\n }\n return out;\n }\n};\n```\n\n```Python3 []\nclass Solution:\n ... | 2 | Given an integer `n`, return _a binary string representing its representation in base_ `-2`.
**Note** that the returned string should not have leading zeros unless the string is `"0 "`.
**Example 1:**
**Input:** n = 2
**Output:** "110 "
**Explantion:** (-2)2 + (-2)1 = 2
**Example 2:**
**Input:** n = 3
**Output:**... | null |
Python4 | convert-to-base-2 | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 0 | Given an integer `n`, return _a binary string representing its representation in base_ `-2`.
**Note** that the returned string should not have leading zeros unless the string is `"0 "`.
**Example 1:**
**Input:** n = 2
**Output:** "110 "
**Explantion:** (-2)2 + (-2)1 = 2
**Example 2:**
**Input:** n = 3
**Output:**... | null |
convert to base -2 | convert-to-base-2 | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 0 | Given an integer `n`, return _a binary string representing its representation in base_ `-2`.
**Note** that the returned string should not have leading zeros unless the string is `"0 "`.
**Example 1:**
**Input:** n = 2
**Output:** "110 "
**Explantion:** (-2)2 + (-2)1 = 2
**Example 2:**
**Input:** n = 3
**Output:**... | null |
C++ and Python simple solution | binary-prefix-divisible-by-5 | 0 | 1 | **C++ :**\n\n```\nclass Solution {\npublic:\n vector<bool> prefixesDivBy5(vector<int>& nums) {\n \n vector<bool> res;\n int num;\n \n for(int i = 0; i < nums.size(); ++i)\n {\n num = (num * 2 + nums[i]) % 5;\n res.push_back(num == 0);\n }\n ... | 25 | You are given a binary array `nums` (**0-indexed**).
We define `xi` as the number whose binary representation is the subarray `nums[0..i]` (from most-significant-bit to least-significant-bit).
* For example, if `nums = [1,0,1]`, then `x0 = 1`, `x1 = 2`, and `x2 = 5`.
Return _an array of booleans_ `answer` _where_ ... | null |
C++ and Python simple solution | binary-prefix-divisible-by-5 | 0 | 1 | **C++ :**\n\n```\nclass Solution {\npublic:\n vector<bool> prefixesDivBy5(vector<int>& nums) {\n \n vector<bool> res;\n int num;\n \n for(int i = 0; i < nums.size(); ++i)\n {\n num = (num * 2 + nums[i]) % 5;\n res.push_back(num == 0);\n }\n ... | 25 | For two strings `s` and `t`, we say "`t` divides `s` " if and only if `s = t + ... + t` (i.e., `t` is concatenated with itself one or more times).
Given two strings `str1` and `str2`, return _the largest string_ `x` _such that_ `x` _divides both_ `str1` _and_ `str2`.
**Example 1:**
**Input:** str1 = "ABCABC ", str2... | If X is the first i digits of the array as a binary number, then 2X + A[i] is the first i+1 digits. |
Java and Python Solution | binary-prefix-divisible-by-5 | 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(n)\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n... | 1 | You are given a binary array `nums` (**0-indexed**).
We define `xi` as the number whose binary representation is the subarray `nums[0..i]` (from most-significant-bit to least-significant-bit).
* For example, if `nums = [1,0,1]`, then `x0 = 1`, `x1 = 2`, and `x2 = 5`.
Return _an array of booleans_ `answer` _where_ ... | null |
Java and Python Solution | binary-prefix-divisible-by-5 | 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(n)\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n... | 1 | For two strings `s` and `t`, we say "`t` divides `s` " if and only if `s = t + ... + t` (i.e., `t` is concatenated with itself one or more times).
Given two strings `str1` and `str2`, return _the largest string_ `x` _such that_ `x` _divides both_ `str1` _and_ `str2`.
**Example 1:**
**Input:** str1 = "ABCABC ", str2... | If X is the first i digits of the array as a binary number, then 2X + A[i] is the first i+1 digits. |
Java, C++, Python | 🚀 A pinch of math in 7 lines explained | binary-prefix-divisible-by-5 | 1 | 1 | > \u26A0\uFE0F **Disclaimer**: The original solution was crafted in Java.\n\nDont forget to upvote if you like the content below. \uD83D\uDE43\n\n# Intuition\nThe task requires us to check whether the binary prefix of each number in an array is divisible by 5. We need to return a boolean array where each index correspo... | 2 | You are given a binary array `nums` (**0-indexed**).
We define `xi` as the number whose binary representation is the subarray `nums[0..i]` (from most-significant-bit to least-significant-bit).
* For example, if `nums = [1,0,1]`, then `x0 = 1`, `x1 = 2`, and `x2 = 5`.
Return _an array of booleans_ `answer` _where_ ... | null |
Java, C++, Python | 🚀 A pinch of math in 7 lines explained | binary-prefix-divisible-by-5 | 1 | 1 | > \u26A0\uFE0F **Disclaimer**: The original solution was crafted in Java.\n\nDont forget to upvote if you like the content below. \uD83D\uDE43\n\n# Intuition\nThe task requires us to check whether the binary prefix of each number in an array is divisible by 5. We need to return a boolean array where each index correspo... | 2 | For two strings `s` and `t`, we say "`t` divides `s` " if and only if `s = t + ... + t` (i.e., `t` is concatenated with itself one or more times).
Given two strings `str1` and `str2`, return _the largest string_ `x` _such that_ `x` _divides both_ `str1` _and_ `str2`.
**Example 1:**
**Input:** str1 = "ABCABC ", str2... | If X is the first i digits of the array as a binary number, then 2X + A[i] is the first i+1 digits. |
Solution | binary-prefix-divisible-by-5 | 1 | 1 | ```C++ []\nclass Solution {\npublic:\n vector<bool> prefixesDivBy5(vector<int>& nums) {\n vector<bool> r;\n int n=0;\n for(int b : nums){\n n = ((n<<1) | b) % 5;\n r.push_back(n==0);\n }\n return r;\n }\n};\n```\n\n```Python3 []\nclass Solution:\n def pr... | 2 | You are given a binary array `nums` (**0-indexed**).
We define `xi` as the number whose binary representation is the subarray `nums[0..i]` (from most-significant-bit to least-significant-bit).
* For example, if `nums = [1,0,1]`, then `x0 = 1`, `x1 = 2`, and `x2 = 5`.
Return _an array of booleans_ `answer` _where_ ... | null |
Solution | binary-prefix-divisible-by-5 | 1 | 1 | ```C++ []\nclass Solution {\npublic:\n vector<bool> prefixesDivBy5(vector<int>& nums) {\n vector<bool> r;\n int n=0;\n for(int b : nums){\n n = ((n<<1) | b) % 5;\n r.push_back(n==0);\n }\n return r;\n }\n};\n```\n\n```Python3 []\nclass Solution:\n def pr... | 2 | For two strings `s` and `t`, we say "`t` divides `s` " if and only if `s = t + ... + t` (i.e., `t` is concatenated with itself one or more times).
Given two strings `str1` and `str2`, return _the largest string_ `x` _such that_ `x` _divides both_ `str1` _and_ `str2`.
**Example 1:**
**Input:** str1 = "ABCABC ", str2... | If X is the first i digits of the array as a binary number, then 2X + A[i] is the first i+1 digits. |
|| Easy Solution || DFA || | binary-prefix-divisible-by-5 | 1 | 1 | # Intuition\nUsing Deterministic Finite Automata \n\n# Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nConstant\n\n# Code\n```\nclass Solution {\n public List<Boolean> prefixesDivBy5(int[] nums) {\n List<Boolean> res = new ArrayList<>();\n int daigram[][] ={{0,1},{2,3},{4,0},{1,2},{3,4}};\... | 1 | You are given a binary array `nums` (**0-indexed**).
We define `xi` as the number whose binary representation is the subarray `nums[0..i]` (from most-significant-bit to least-significant-bit).
* For example, if `nums = [1,0,1]`, then `x0 = 1`, `x1 = 2`, and `x2 = 5`.
Return _an array of booleans_ `answer` _where_ ... | null |
|| Easy Solution || DFA || | binary-prefix-divisible-by-5 | 1 | 1 | # Intuition\nUsing Deterministic Finite Automata \n\n# Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nConstant\n\n# Code\n```\nclass Solution {\n public List<Boolean> prefixesDivBy5(int[] nums) {\n List<Boolean> res = new ArrayList<>();\n int daigram[][] ={{0,1},{2,3},{4,0},{1,2},{3,4}};\... | 1 | For two strings `s` and `t`, we say "`t` divides `s` " if and only if `s = t + ... + t` (i.e., `t` is concatenated with itself one or more times).
Given two strings `str1` and `str2`, return _the largest string_ `x` _such that_ `x` _divides both_ `str1` _and_ `str2`.
**Example 1:**
**Input:** str1 = "ABCABC ", str2... | If X is the first i digits of the array as a binary number, then 2X + A[i] is the first i+1 digits. |
Easy Python List boolean | binary-prefix-divisible-by-5 | 0 | 1 | \n# Complexity\n- Time complexity: O(N)\n\n- Space complexity: O(N)\n# Code\n```\nclass Solution(object):\n def prefixesDivBy5(self, nums):\n l, top = [True] * len(nums), 0\n for i in range(len(nums)):\n top = top * 2 + nums[i]\n l[i] = top % 5 == 0\n return l\n``` | 0 | You are given a binary array `nums` (**0-indexed**).
We define `xi` as the number whose binary representation is the subarray `nums[0..i]` (from most-significant-bit to least-significant-bit).
* For example, if `nums = [1,0,1]`, then `x0 = 1`, `x1 = 2`, and `x2 = 5`.
Return _an array of booleans_ `answer` _where_ ... | null |
Easy Python List boolean | binary-prefix-divisible-by-5 | 0 | 1 | \n# Complexity\n- Time complexity: O(N)\n\n- Space complexity: O(N)\n# Code\n```\nclass Solution(object):\n def prefixesDivBy5(self, nums):\n l, top = [True] * len(nums), 0\n for i in range(len(nums)):\n top = top * 2 + nums[i]\n l[i] = top % 5 == 0\n return l\n``` | 0 | For two strings `s` and `t`, we say "`t` divides `s` " if and only if `s = t + ... + t` (i.e., `t` is concatenated with itself one or more times).
Given two strings `str1` and `str2`, return _the largest string_ `x` _such that_ `x` _divides both_ `str1` _and_ `str2`.
**Example 1:**
**Input:** str1 = "ABCABC ", str2... | If X is the first i digits of the array as a binary number, then 2X + A[i] is the first i+1 digits. |
Python 3 solution. Very interesting result!!! | binary-prefix-divisible-by-5 | 0 | 1 | \n\n\n# Code\n```\nclass Solution:\n def prefixesDivBy5(self, nums: List[int]) -> List[bool]:\n tmp = 0\n res = [0] * len(nums)\n for i, num in e... | 0 | You are given a binary array `nums` (**0-indexed**).
We define `xi` as the number whose binary representation is the subarray `nums[0..i]` (from most-significant-bit to least-significant-bit).
* For example, if `nums = [1,0,1]`, then `x0 = 1`, `x1 = 2`, and `x2 = 5`.
Return _an array of booleans_ `answer` _where_ ... | null |
Python 3 solution. Very interesting result!!! | binary-prefix-divisible-by-5 | 0 | 1 | \n\n\n# Code\n```\nclass Solution:\n def prefixesDivBy5(self, nums: List[int]) -> List[bool]:\n tmp = 0\n res = [0] * len(nums)\n for i, num in e... | 0 | For two strings `s` and `t`, we say "`t` divides `s` " if and only if `s = t + ... + t` (i.e., `t` is concatenated with itself one or more times).
Given two strings `str1` and `str2`, return _the largest string_ `x` _such that_ `x` _divides both_ `str1` _and_ `str2`.
**Example 1:**
**Input:** str1 = "ABCABC ", str2... | If X is the first i digits of the array as a binary number, then 2X + A[i] is the first i+1 digits. |
1018. Binary Prefix Divisible by 5 || Solution for Python3 | binary-prefix-divisible-by-5 | 0 | 1 | ```\nclass Solution:\n def prefixesDivBy5(self, nums: List[int]) -> List[bool]:\n l = []\n decimal_num = 0\n\n for i in range(len(nums)):\n decimal_num = decimal_num * 2 + nums[i]\n\n if decimal_num % 5 == 0:\n l.append(True)\n else:\n ... | 0 | You are given a binary array `nums` (**0-indexed**).
We define `xi` as the number whose binary representation is the subarray `nums[0..i]` (from most-significant-bit to least-significant-bit).
* For example, if `nums = [1,0,1]`, then `x0 = 1`, `x1 = 2`, and `x2 = 5`.
Return _an array of booleans_ `answer` _where_ ... | null |
1018. Binary Prefix Divisible by 5 || Solution for Python3 | binary-prefix-divisible-by-5 | 0 | 1 | ```\nclass Solution:\n def prefixesDivBy5(self, nums: List[int]) -> List[bool]:\n l = []\n decimal_num = 0\n\n for i in range(len(nums)):\n decimal_num = decimal_num * 2 + nums[i]\n\n if decimal_num % 5 == 0:\n l.append(True)\n else:\n ... | 0 | For two strings `s` and `t`, we say "`t` divides `s` " if and only if `s = t + ... + t` (i.e., `t` is concatenated with itself one or more times).
Given two strings `str1` and `str2`, return _the largest string_ `x` _such that_ `x` _divides both_ `str1` _and_ `str2`.
**Example 1:**
**Input:** str1 = "ABCABC ", str2... | If X is the first i digits of the array as a binary number, then 2X + A[i] is the first i+1 digits. |
Fast solution on Python. Runtime 84ms - 100%!!! | binary-prefix-divisible-by-5 | 0 | 1 | \n# Code\n```\nclass Solution:\n def prefixesDivBy5(self, nums: List[int]) -> List[bool]:\n \n num, k, ans = 0, 1, []\n for i in nums:\n num = (num*2+i)%5\n ans.append(num == 0)\n return ans\n\n\n``` | 0 | You are given a binary array `nums` (**0-indexed**).
We define `xi` as the number whose binary representation is the subarray `nums[0..i]` (from most-significant-bit to least-significant-bit).
* For example, if `nums = [1,0,1]`, then `x0 = 1`, `x1 = 2`, and `x2 = 5`.
Return _an array of booleans_ `answer` _where_ ... | null |
Fast solution on Python. Runtime 84ms - 100%!!! | binary-prefix-divisible-by-5 | 0 | 1 | \n# Code\n```\nclass Solution:\n def prefixesDivBy5(self, nums: List[int]) -> List[bool]:\n \n num, k, ans = 0, 1, []\n for i in nums:\n num = (num*2+i)%5\n ans.append(num == 0)\n return ans\n\n\n``` | 0 | For two strings `s` and `t`, we say "`t` divides `s` " if and only if `s = t + ... + t` (i.e., `t` is concatenated with itself one or more times).
Given two strings `str1` and `str2`, return _the largest string_ `x` _such that_ `x` _divides both_ `str1` _and_ `str2`.
**Example 1:**
**Input:** str1 = "ABCABC ", str2... | If X is the first i digits of the array as a binary number, then 2X + A[i] is the first i+1 digits. |
80% TC and 77% SC easy python solution | next-greater-node-in-linked-list | 0 | 1 | ```\ndef nextLargerNodes(self, head: Optional[ListNode]) -> List[int]:\n\tans = []\n\tstack = []\n\ti = 0\n\tcurr = head\n\twhile(curr):\n\t# just for the length of the linked list.\n\t\tans.append(0)\n\t\tcurr = curr.next\n\twhile(head):\n\t\twhile(stack and stack[-1][1] < head.val):\n\t\t\tindex, _ = stack.pop()\n\t\... | 2 | You are given the `head` of a linked list with `n` nodes.
For each node in the list, find the value of the **next greater node**. That is, for each node, find the value of the first node that is next to it and has a **strictly larger** value than it.
Return an integer array `answer` where `answer[i]` is the value of ... | null |
80% TC and 77% SC easy python solution | next-greater-node-in-linked-list | 0 | 1 | ```\ndef nextLargerNodes(self, head: Optional[ListNode]) -> List[int]:\n\tans = []\n\tstack = []\n\ti = 0\n\tcurr = head\n\twhile(curr):\n\t# just for the length of the linked list.\n\t\tans.append(0)\n\t\tcurr = curr.next\n\twhile(head):\n\t\twhile(stack and stack[-1][1] < head.val):\n\t\t\tindex, _ = stack.pop()\n\t\... | 2 | You are given an `m x n` binary matrix `matrix`.
You can choose any number of columns in the matrix and flip every cell in that column (i.e., Change the value of the cell from `0` to `1` or vice versa).
Return _the maximum number of rows that have all values equal after some number of flips_.
**Example 1:**
**Input... | We can use a stack that stores nodes in monotone decreasing order of value. When we see a node_j with a larger value, every node_i in the stack has next_larger(node_i) = node_j . |
Next Greater Node in Linked List (Python) | next-greater-node-in-linked-list | 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)$$ --... | 2 | You are given the `head` of a linked list with `n` nodes.
For each node in the list, find the value of the **next greater node**. That is, for each node, find the value of the first node that is next to it and has a **strictly larger** value than it.
Return an integer array `answer` where `answer[i]` is the value of ... | null |
Next Greater Node in Linked List (Python) | next-greater-node-in-linked-list | 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)$$ --... | 2 | You are given an `m x n` binary matrix `matrix`.
You can choose any number of columns in the matrix and flip every cell in that column (i.e., Change the value of the cell from `0` to `1` or vice versa).
Return _the maximum number of rows that have all values equal after some number of flips_.
**Example 1:**
**Input... | We can use a stack that stores nodes in monotone decreasing order of value. When we see a node_j with a larger value, every node_i in the stack has next_larger(node_i) = node_j . |
Python3 Solution with explanation | next-greater-node-in-linked-list | 0 | 1 | As we traverse the linked list, we can use a stack to store a tuple (index, value), where the index is the position of the element in the linkedlist.\n\n```\n# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, x):\n# self.val = x\n# self.next = None\n\nclass Solution:\n ... | 35 | You are given the `head` of a linked list with `n` nodes.
For each node in the list, find the value of the **next greater node**. That is, for each node, find the value of the first node that is next to it and has a **strictly larger** value than it.
Return an integer array `answer` where `answer[i]` is the value of ... | null |
Python3 Solution with explanation | next-greater-node-in-linked-list | 0 | 1 | As we traverse the linked list, we can use a stack to store a tuple (index, value), where the index is the position of the element in the linkedlist.\n\n```\n# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, x):\n# self.val = x\n# self.next = None\n\nclass Solution:\n ... | 35 | You are given an `m x n` binary matrix `matrix`.
You can choose any number of columns in the matrix and flip every cell in that column (i.e., Change the value of the cell from `0` to `1` or vice versa).
Return _the maximum number of rows that have all values equal after some number of flips_.
**Example 1:**
**Input... | We can use a stack that stores nodes in monotone decreasing order of value. When we see a node_j with a larger value, every node_i in the stack has next_larger(node_i) = node_j . |
python solution use monotonic stack beats 99% | next-greater-node-in-linked-list | 0 | 1 | # Intuition\n# ***Upvote If Its Useful***\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)$$ -->\n\n# Code\n```\n# Definition for sing... | 1 | You are given the `head` of a linked list with `n` nodes.
For each node in the list, find the value of the **next greater node**. That is, for each node, find the value of the first node that is next to it and has a **strictly larger** value than it.
Return an integer array `answer` where `answer[i]` is the value of ... | null |
python solution use monotonic stack beats 99% | next-greater-node-in-linked-list | 0 | 1 | # Intuition\n# ***Upvote If Its Useful***\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)$$ -->\n\n# Code\n```\n# Definition for sing... | 1 | You are given an `m x n` binary matrix `matrix`.
You can choose any number of columns in the matrix and flip every cell in that column (i.e., Change the value of the cell from `0` to `1` or vice versa).
Return _the maximum number of rows that have all values equal after some number of flips_.
**Example 1:**
**Input... | We can use a stack that stores nodes in monotone decreasing order of value. When we see a node_j with a larger value, every node_i in the stack has next_larger(node_i) = node_j . |
python 98% | easy | next-greater-node-in-linked-list | 0 | 1 | ```\n# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution:\n def nextLargerNodes(self, head: ListNode) -> List[int]:\n \n \n u=[]\n \n while head:\n u.ap... | 7 | You are given the `head` of a linked list with `n` nodes.
For each node in the list, find the value of the **next greater node**. That is, for each node, find the value of the first node that is next to it and has a **strictly larger** value than it.
Return an integer array `answer` where `answer[i]` is the value of ... | null |
python 98% | easy | next-greater-node-in-linked-list | 0 | 1 | ```\n# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution:\n def nextLargerNodes(self, head: ListNode) -> List[int]:\n \n \n u=[]\n \n while head:\n u.ap... | 7 | You are given an `m x n` binary matrix `matrix`.
You can choose any number of columns in the matrix and flip every cell in that column (i.e., Change the value of the cell from `0` to `1` or vice versa).
Return _the maximum number of rows that have all values equal after some number of flips_.
**Example 1:**
**Input... | We can use a stack that stores nodes in monotone decreasing order of value. When we see a node_j with a larger value, every node_i in the stack has next_larger(node_i) = node_j . |
Python stack w/ comment | next-greater-node-in-linked-list | 0 | 1 | ```py\n\'\'\'\nw: linked list + stack\n for such type of question, we could only know the value of node when we get there,\n then using a stack to store the previous information should do the job, the key here is \n how to construct the stack. In stead of only storing the value, we store (value, index) so\n we ... | 9 | You are given the `head` of a linked list with `n` nodes.
For each node in the list, find the value of the **next greater node**. That is, for each node, find the value of the first node that is next to it and has a **strictly larger** value than it.
Return an integer array `answer` where `answer[i]` is the value of ... | null |
Python stack w/ comment | next-greater-node-in-linked-list | 0 | 1 | ```py\n\'\'\'\nw: linked list + stack\n for such type of question, we could only know the value of node when we get there,\n then using a stack to store the previous information should do the job, the key here is \n how to construct the stack. In stead of only storing the value, we store (value, index) so\n we ... | 9 | You are given an `m x n` binary matrix `matrix`.
You can choose any number of columns in the matrix and flip every cell in that column (i.e., Change the value of the cell from `0` to `1` or vice versa).
Return _the maximum number of rows that have all values equal after some number of flips_.
**Example 1:**
**Input... | We can use a stack that stores nodes in monotone decreasing order of value. When we see a node_j with a larger value, every node_i in the stack has next_larger(node_i) = node_j . |
Python3 Solution | number-of-enclaves | 0 | 1 | \n```\nclass Solution:\n def numEnclaves(self, grid: List[List[int]]) -> int:\n m=len(grid)\n n=len(grid[0])\n\n stack=[]\n for i in range(m):\n if grid[i][0]:\n stack.append((i,0))\n\n if grid[i][n-1]:\n stack.append((i,n-1)) \n\n ... | 2 | You are given an `m x n` binary matrix `grid`, where `0` represents a sea cell and `1` represents a land cell.
A **move** consists of walking from one land cell to another adjacent (**4-directionally**) land cell or walking off the boundary of the `grid`.
Return _the number of land cells in_ `grid` _for which we cann... | null |
Python3 Solution | number-of-enclaves | 0 | 1 | \n```\nclass Solution:\n def numEnclaves(self, grid: List[List[int]]) -> int:\n m=len(grid)\n n=len(grid[0])\n\n stack=[]\n for i in range(m):\n if grid[i][0]:\n stack.append((i,0))\n\n if grid[i][n-1]:\n stack.append((i,n-1)) \n\n ... | 2 | Given two numbers `arr1` and `arr2` in base **\-2**, return the result of adding them together.
Each number is given in _array format_: as an array of 0s and 1s, from most significant bit to least significant bit. For example, `arr = [1,1,0,1]` represents the number `(-2)^3 + (-2)^2 + (-2)^0 = -3`. A number `arr` in _... | Can you model this problem as a graph problem? Create n * m + 1 nodes where n * m nodes represents each cell of the map and one extra node to represent the exterior of the map. In the map add edges between neighbors on land cells. And add edges between the exterior and land nodes which are in the boundary.
Return as a... |
Python O(m*n) code for reference | number-of-enclaves | 0 | 1 | \n```\nclass Solution:\n def numEnclaves(self, grid: List[List[int]]) -> int:\n m,n,ans = len(grid),len(grid[0]),0\n def move(i,j,grid):\n if( i<0 or j < 0 or i>=m or j>=n ):\n return False,0\n elif(grid[i][j] == 0 ):\n return True , 0\n gr... | 1 | You are given an `m x n` binary matrix `grid`, where `0` represents a sea cell and `1` represents a land cell.
A **move** consists of walking from one land cell to another adjacent (**4-directionally**) land cell or walking off the boundary of the `grid`.
Return _the number of land cells in_ `grid` _for which we cann... | null |
Python O(m*n) code for reference | number-of-enclaves | 0 | 1 | \n```\nclass Solution:\n def numEnclaves(self, grid: List[List[int]]) -> int:\n m,n,ans = len(grid),len(grid[0]),0\n def move(i,j,grid):\n if( i<0 or j < 0 or i>=m or j>=n ):\n return False,0\n elif(grid[i][j] == 0 ):\n return True , 0\n gr... | 1 | Given two numbers `arr1` and `arr2` in base **\-2**, return the result of adding them together.
Each number is given in _array format_: as an array of 0s and 1s, from most significant bit to least significant bit. For example, `arr = [1,1,0,1]` represents the number `(-2)^3 + (-2)^2 + (-2)^0 = -3`. A number `arr` in _... | Can you model this problem as a graph problem? Create n * m + 1 nodes where n * m nodes represents each cell of the map and one extra node to represent the exterior of the map. In the map add edges between neighbors on land cells. And add edges between the exterior and land nodes which are in the boundary.
Return as a... |
Two Approaches ||TLE to Success|| Easy with Explanation | number-of-enclaves | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe first thought after seeing the question was that it\'s quit understood we have to use dfs(Travelling along all side and choose the one we want) with somehow marking the cell we visit .So first i tried with traversing each land and if ... | 1 | You are given an `m x n` binary matrix `grid`, where `0` represents a sea cell and `1` represents a land cell.
A **move** consists of walking from one land cell to another adjacent (**4-directionally**) land cell or walking off the boundary of the `grid`.
Return _the number of land cells in_ `grid` _for which we cann... | null |
Two Approaches ||TLE to Success|| Easy with Explanation | number-of-enclaves | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe first thought after seeing the question was that it\'s quit understood we have to use dfs(Travelling along all side and choose the one we want) with somehow marking the cell we visit .So first i tried with traversing each land and if ... | 1 | Given two numbers `arr1` and `arr2` in base **\-2**, return the result of adding them together.
Each number is given in _array format_: as an array of 0s and 1s, from most significant bit to least significant bit. For example, `arr = [1,1,0,1]` represents the number `(-2)^3 + (-2)^2 + (-2)^0 = -3`. A number `arr` in _... | Can you model this problem as a graph problem? Create n * m + 1 nodes where n * m nodes represents each cell of the map and one extra node to represent the exterior of the map. In the map add edges between neighbors on land cells. And add edges between the exterior and land nodes which are in the boundary.
Return as a... |
Python Easy O(n) Stack DFS Beats 99% Explained | number-of-enclaves | 0 | 1 | # Intuition\nIn graph search problems it\'s always easier to start at the border or boundaries and search inwards. Thus, despite the problem asking for the number of cells forming islands that do not touch the border of the grid, it\'s easier to count the inverse: the number of cells that are connected to the border of... | 1 | You are given an `m x n` binary matrix `grid`, where `0` represents a sea cell and `1` represents a land cell.
A **move** consists of walking from one land cell to another adjacent (**4-directionally**) land cell or walking off the boundary of the `grid`.
Return _the number of land cells in_ `grid` _for which we cann... | null |
Python Easy O(n) Stack DFS Beats 99% Explained | number-of-enclaves | 0 | 1 | # Intuition\nIn graph search problems it\'s always easier to start at the border or boundaries and search inwards. Thus, despite the problem asking for the number of cells forming islands that do not touch the border of the grid, it\'s easier to count the inverse: the number of cells that are connected to the border of... | 1 | Given two numbers `arr1` and `arr2` in base **\-2**, return the result of adding them together.
Each number is given in _array format_: as an array of 0s and 1s, from most significant bit to least significant bit. For example, `arr = [1,1,0,1]` represents the number `(-2)^3 + (-2)^2 + (-2)^0 = -3`. A number `arr` in _... | Can you model this problem as a graph problem? Create n * m + 1 nodes where n * m nodes represents each cell of the map and one extra node to represent the exterior of the map. In the map add edges between neighbors on land cells. And add edges between the exterior and land nodes which are in the boundary.
Return as a... |
✅🐍Python3 || simplest solution 🔥🔥|| detailed explained | number-of-enclaves | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n**Using DFS**\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n- we know doing moves, we want to come to border 1\'s and after that we can tip off of the board.\n- so it is wise to start from boarder 1\'s and make d... | 1 | You are given an `m x n` binary matrix `grid`, where `0` represents a sea cell and `1` represents a land cell.
A **move** consists of walking from one land cell to another adjacent (**4-directionally**) land cell or walking off the boundary of the `grid`.
Return _the number of land cells in_ `grid` _for which we cann... | null |
✅🐍Python3 || simplest solution 🔥🔥|| detailed explained | number-of-enclaves | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n**Using DFS**\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n- we know doing moves, we want to come to border 1\'s and after that we can tip off of the board.\n- so it is wise to start from boarder 1\'s and make d... | 1 | Given two numbers `arr1` and `arr2` in base **\-2**, return the result of adding them together.
Each number is given in _array format_: as an array of 0s and 1s, from most significant bit to least significant bit. For example, `arr = [1,1,0,1]` represents the number `(-2)^3 + (-2)^2 + (-2)^0 = -3`. A number `arr` in _... | Can you model this problem as a graph problem? Create n * m + 1 nodes where n * m nodes represents each cell of the map and one extra node to represent the exterior of the map. In the map add edges between neighbors on land cells. And add edges between the exterior and land nodes which are in the boundary.
Return as a... |
[C++/Python] Union-Find | number-of-enclaves | 0 | 1 | # Complexity\n- Time complexity: $$O(mn*\u03B1(mn))$$, where m and n are the dimensions of the input matrix, and $$\u03B1$$ is the inverse Ackermann function, which grows very slowly and can be considered as a constant for all practical purposes.\nThe overall time complexity comes from two parts. Firstly, the Union-Fin... | 1 | You are given an `m x n` binary matrix `grid`, where `0` represents a sea cell and `1` represents a land cell.
A **move** consists of walking from one land cell to another adjacent (**4-directionally**) land cell or walking off the boundary of the `grid`.
Return _the number of land cells in_ `grid` _for which we cann... | null |
[C++/Python] Union-Find | number-of-enclaves | 0 | 1 | # Complexity\n- Time complexity: $$O(mn*\u03B1(mn))$$, where m and n are the dimensions of the input matrix, and $$\u03B1$$ is the inverse Ackermann function, which grows very slowly and can be considered as a constant for all practical purposes.\nThe overall time complexity comes from two parts. Firstly, the Union-Fin... | 1 | Given two numbers `arr1` and `arr2` in base **\-2**, return the result of adding them together.
Each number is given in _array format_: as an array of 0s and 1s, from most significant bit to least significant bit. For example, `arr = [1,1,0,1]` represents the number `(-2)^3 + (-2)^2 + (-2)^0 = -3`. A number `arr` in _... | Can you model this problem as a graph problem? Create n * m + 1 nodes where n * m nodes represents each cell of the map and one extra node to represent the exterior of the map. In the map add edges between neighbors on land cells. And add edges between the exterior and land nodes which are in the boundary.
Return as a... |
Solution | remove-outermost-parentheses | 1 | 1 | ```C++ []\nclass Solution {\npublic:\n string removeOuterParentheses(string S) {\n string res;\n int opened = 0;\n for (char c : S) {\n if (c == \'(\' && opened++ > 0) res += c;\n if (c == \')\' && opened-- > 1) res += c;\n }\n return res;\n }\n};\n```\n\n`... | 463 | A valid parentheses string is either empty `" "`, `"( " + A + ") "`, or `A + B`, where `A` and `B` are valid parentheses strings, and `+` represents string concatenation.
* For example, `" "`, `"() "`, `"(())() "`, and `"(()(())) "` are all valid parentheses strings.
A valid parentheses string `s` is primitive if i... | null |
Solution | remove-outermost-parentheses | 1 | 1 | ```C++ []\nclass Solution {\npublic:\n string removeOuterParentheses(string S) {\n string res;\n int opened = 0;\n for (char c : S) {\n if (c == \'(\' && opened++ > 0) res += c;\n if (c == \')\' && opened-- > 1) res += c;\n }\n return res;\n }\n};\n```\n\n`... | 463 | Given two strings `first` and `second`, consider occurrences in some text of the form `"first second third "`, where `second` comes immediately after `first`, and `third` comes immediately after `second`.
Return _an array of all the words_ `third` _for each occurrence of_ `"first second third "`.
**Example 1:**
**In... | Can you find the primitive decomposition? The number of ( and ) characters must be equal. |
💡One Pass | FAANG SDE-1 Interview😯 | remove-outermost-parentheses | 1 | 1 | ```\nVery Easy Beginner Friendly Solution \uD83D\uDCA1\nDo not use stack to prevent more extra space.\n\n\nPlease do Upvote if it helps :)\n```\n\n# Complexity\n- Time complexity: O(n) //One pass\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(n) //For resultant string\n<!-- Add your spa... | 54 | A valid parentheses string is either empty `" "`, `"( " + A + ") "`, or `A + B`, where `A` and `B` are valid parentheses strings, and `+` represents string concatenation.
* For example, `" "`, `"() "`, `"(())() "`, and `"(()(())) "` are all valid parentheses strings.
A valid parentheses string `s` is primitive if i... | null |
💡One Pass | FAANG SDE-1 Interview😯 | remove-outermost-parentheses | 1 | 1 | ```\nVery Easy Beginner Friendly Solution \uD83D\uDCA1\nDo not use stack to prevent more extra space.\n\n\nPlease do Upvote if it helps :)\n```\n\n# Complexity\n- Time complexity: O(n) //One pass\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(n) //For resultant string\n<!-- Add your spa... | 54 | Given two strings `first` and `second`, consider occurrences in some text of the form `"first second third "`, where `second` comes immediately after `first`, and `third` comes immediately after `second`.
Return _an array of all the words_ `third` _for each occurrence of_ `"first second third "`.
**Example 1:**
**In... | Can you find the primitive decomposition? The number of ( and ) characters must be equal. |
Easy Python Solution! | remove-outermost-parentheses | 0 | 1 | \n# Approach\n<!-- Describe your approach to solving the problem. -->\nComment if you need any explaination or have any doubts.\n# Complexity\n- Time complexity: O(N)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```... | 1 | A valid parentheses string is either empty `" "`, `"( " + A + ") "`, or `A + B`, where `A` and `B` are valid parentheses strings, and `+` represents string concatenation.
* For example, `" "`, `"() "`, `"(())() "`, and `"(()(())) "` are all valid parentheses strings.
A valid parentheses string `s` is primitive if i... | null |
Easy Python Solution! | remove-outermost-parentheses | 0 | 1 | \n# Approach\n<!-- Describe your approach to solving the problem. -->\nComment if you need any explaination or have any doubts.\n# Complexity\n- Time complexity: O(N)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```... | 1 | Given two strings `first` and `second`, consider occurrences in some text of the form `"first second third "`, where `second` comes immediately after `first`, and `third` comes immediately after `second`.
Return _an array of all the words_ `third` _for each occurrence of_ `"first second third "`.
**Example 1:**
**In... | Can you find the primitive decomposition? The number of ( and ) characters must be equal. |
Solution | sum-of-root-to-leaf-binary-numbers | 1 | 1 | ```C++ []\nclass Solution {\npublic:\nvoid helper(TreeNode* root, int val, int& res){\n if(!root) return;\n\n val = val | root->val;\n if(!root->left && !root->right){\n res+=val;\n return;\n }\n helper(root->left, val<<1, res);\n helper(root->right, val<<1, res);\n}\nvoid helper1(TreeN... | 1 | You are given the `root` of a binary tree where each node has a value `0` or `1`. Each root-to-leaf path represents a binary number starting with the most significant bit.
* For example, if the path is `0 -> 1 -> 1 -> 0 -> 1`, then this could represent `01101` in binary, which is `13`.
For all leaves in the tree, c... | null |
Solution | sum-of-root-to-leaf-binary-numbers | 1 | 1 | ```C++ []\nclass Solution {\npublic:\nvoid helper(TreeNode* root, int val, int& res){\n if(!root) return;\n\n val = val | root->val;\n if(!root->left && !root->right){\n res+=val;\n return;\n }\n helper(root->left, val<<1, res);\n helper(root->right, val<<1, res);\n}\nvoid helper1(TreeN... | 1 | You have `n` `tiles`, where each tile has one letter `tiles[i]` printed on it.
Return _the number of possible non-empty sequences of letters_ you can make using the letters printed on those `tiles`.
**Example 1:**
**Input:** tiles = "AAB "
**Output:** 8
**Explanation:** The possible sequences are "A ", "B ", "AA... | Find each path, then transform that path to an integer in base 10. |
✔️ [Python3] 5-LINES ☜ ( ͡❛ 👅 ͡❛), Explained | sum-of-root-to-leaf-binary-numbers | 0 | 1 | We use the recursive Depth First Search here to build all binary numbers from the root-to-leaf path and sum them together. When a leaf node is reached, the function returns the built number. For the rest of the nodes, the function simply sums results from recursive calls. For building the binary number in the path we u... | 26 | You are given the `root` of a binary tree where each node has a value `0` or `1`. Each root-to-leaf path represents a binary number starting with the most significant bit.
* For example, if the path is `0 -> 1 -> 1 -> 0 -> 1`, then this could represent `01101` in binary, which is `13`.
For all leaves in the tree, c... | null |
✔️ [Python3] 5-LINES ☜ ( ͡❛ 👅 ͡❛), Explained | sum-of-root-to-leaf-binary-numbers | 0 | 1 | We use the recursive Depth First Search here to build all binary numbers from the root-to-leaf path and sum them together. When a leaf node is reached, the function returns the built number. For the rest of the nodes, the function simply sums results from recursive calls. For building the binary number in the path we u... | 26 | You have `n` `tiles`, where each tile has one letter `tiles[i]` printed on it.
Return _the number of possible non-empty sequences of letters_ you can make using the letters printed on those `tiles`.
**Example 1:**
**Input:** tiles = "AAB "
**Output:** 8
**Explanation:** The possible sequences are "A ", "B ", "AA... | Find each path, then transform that path to an integer in base 10. |
Very easy DFS python 🐍 solution | sum-of-root-to-leaf-binary-numbers | 0 | 1 | ```\nclass Solution:\n def sumRootToLeaf(self, root: TreeNode) -> int:\n total=0\n \n stack=[(root,str(root.val))]\n \n while stack:\n node,binVal=stack.pop()\n \n if node.left:\n stack.append((node.left,binVal+str(node.left.val)))\n ... | 11 | You are given the `root` of a binary tree where each node has a value `0` or `1`. Each root-to-leaf path represents a binary number starting with the most significant bit.
* For example, if the path is `0 -> 1 -> 1 -> 0 -> 1`, then this could represent `01101` in binary, which is `13`.
For all leaves in the tree, c... | null |
Very easy DFS python 🐍 solution | sum-of-root-to-leaf-binary-numbers | 0 | 1 | ```\nclass Solution:\n def sumRootToLeaf(self, root: TreeNode) -> int:\n total=0\n \n stack=[(root,str(root.val))]\n \n while stack:\n node,binVal=stack.pop()\n \n if node.left:\n stack.append((node.left,binVal+str(node.left.val)))\n ... | 11 | You have `n` `tiles`, where each tile has one letter `tiles[i]` printed on it.
Return _the number of possible non-empty sequences of letters_ you can make using the letters printed on those `tiles`.
**Example 1:**
**Input:** tiles = "AAB "
**Output:** 8
**Explanation:** The possible sequences are "A ", "B ", "AA... | Find each path, then transform that path to an integer in base 10. |
Solution | camelcase-matching | 1 | 1 | ```C++ []\nclass Solution {\n public:\n vector<bool> camelMatch(vector<string>& queries, string pattern) {\n vector<bool> ans;\n\n for (const string& q : queries)\n ans.push_back(isMatch(q, pattern));\n\n return ans;\n }\n private:\n bool isMatch(const string& q, const string& pattern) {\n int j = 0... | 1 | Given an array of strings `queries` and a string `pattern`, return a boolean array `answer` where `answer[i]` is `true` if `queries[i]` matches `pattern`, and `false` otherwise.
A query word `queries[i]` matches `pattern` if you can insert lowercase English letters pattern so that it equals the query. You may insert e... | null |
Solution | camelcase-matching | 1 | 1 | ```C++ []\nclass Solution {\n public:\n vector<bool> camelMatch(vector<string>& queries, string pattern) {\n vector<bool> ans;\n\n for (const string& q : queries)\n ans.push_back(isMatch(q, pattern));\n\n return ans;\n }\n private:\n bool isMatch(const string& q, const string& pattern) {\n int j = 0... | 1 | Given the `root` of a binary tree and an integer `limit`, delete all **insufficient nodes** in the tree simultaneously, and return _the root of the resulting binary tree_.
A node is **insufficient** if every root to **leaf** path intersecting this node has a sum strictly less than `limit`.
A **leaf** is a node with n... | Given a single pattern and word, how can we solve it? One way to do it is using a DP (pos1, pos2) where pos1 is a pointer to the word and pos2 to the pattern and returns true if we can match the pattern with the given word. We have two scenarios: The first one is when `word[pos1] == pattern[pos2]`, then the transition ... |
Python Easy Solution Faster Than 97.4% | camelcase-matching | 0 | 1 | # Complexity\n- Time complexity: O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution:\n def match(self, query, pattern):\n pidx = 0\n for i in range(len(query)):\n if qu... | 1 | Given an array of strings `queries` and a string `pattern`, return a boolean array `answer` where `answer[i]` is `true` if `queries[i]` matches `pattern`, and `false` otherwise.
A query word `queries[i]` matches `pattern` if you can insert lowercase English letters pattern so that it equals the query. You may insert e... | null |
Python Easy Solution Faster Than 97.4% | camelcase-matching | 0 | 1 | # Complexity\n- Time complexity: O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution:\n def match(self, query, pattern):\n pidx = 0\n for i in range(len(query)):\n if qu... | 1 | Given the `root` of a binary tree and an integer `limit`, delete all **insufficient nodes** in the tree simultaneously, and return _the root of the resulting binary tree_.
A node is **insufficient** if every root to **leaf** path intersecting this node has a sum strictly less than `limit`.
A **leaf** is a node with n... | Given a single pattern and word, how can we solve it? One way to do it is using a DP (pos1, pos2) where pos1 is a pointer to the word and pos2 to the pattern and returns true if we can match the pattern with the given word. We have two scenarios: The first one is when `word[pos1] == pattern[pos2]`, then the transition ... |
Python3 solution | camelcase-matching | 0 | 1 | ```\nclass Solution:\n def camelMatch(self, queries: List[str], pattern: str) -> List[bool]:\n res = []\n for word in queries:\n i = j = 0\n while i < len(word):\n if j < len(pattern) and word[i] == pattern[j]:\n i += 1\n j += 1... | 4 | Given an array of strings `queries` and a string `pattern`, return a boolean array `answer` where `answer[i]` is `true` if `queries[i]` matches `pattern`, and `false` otherwise.
A query word `queries[i]` matches `pattern` if you can insert lowercase English letters pattern so that it equals the query. You may insert e... | null |
Python3 solution | camelcase-matching | 0 | 1 | ```\nclass Solution:\n def camelMatch(self, queries: List[str], pattern: str) -> List[bool]:\n res = []\n for word in queries:\n i = j = 0\n while i < len(word):\n if j < len(pattern) and word[i] == pattern[j]:\n i += 1\n j += 1... | 4 | Given the `root` of a binary tree and an integer `limit`, delete all **insufficient nodes** in the tree simultaneously, and return _the root of the resulting binary tree_.
A node is **insufficient** if every root to **leaf** path intersecting this node has a sum strictly less than `limit`.
A **leaf** is a node with n... | Given a single pattern and word, how can we solve it? One way to do it is using a DP (pos1, pos2) where pos1 is a pointer to the word and pos2 to the pattern and returns true if we can match the pattern with the given word. We have two scenarios: The first one is when `word[pos1] == pattern[pos2]`, then the transition ... |
82% TC and 68% SC easy python solution | camelcase-matching | 0 | 1 | ```\ndef camelMatch(self, queries: List[str], pattern: str) -> List[bool]:\n\tclass Trie:\n\t\tdef __init__(self):\n\t\t\tself.root = dict()\n\t\tdef insert(self, word):\n\t\t\tc = self.root\n\t\t\tfor char in word:\n\t\t\t\tif(char not in c):\n\t\t\t\t\tc[char] = dict()\n\t\t\t\tc = c[char]\n\t\tdef find(self, word):\... | 2 | Given an array of strings `queries` and a string `pattern`, return a boolean array `answer` where `answer[i]` is `true` if `queries[i]` matches `pattern`, and `false` otherwise.
A query word `queries[i]` matches `pattern` if you can insert lowercase English letters pattern so that it equals the query. You may insert e... | null |
82% TC and 68% SC easy python solution | camelcase-matching | 0 | 1 | ```\ndef camelMatch(self, queries: List[str], pattern: str) -> List[bool]:\n\tclass Trie:\n\t\tdef __init__(self):\n\t\t\tself.root = dict()\n\t\tdef insert(self, word):\n\t\t\tc = self.root\n\t\t\tfor char in word:\n\t\t\t\tif(char not in c):\n\t\t\t\t\tc[char] = dict()\n\t\t\t\tc = c[char]\n\t\tdef find(self, word):\... | 2 | Given the `root` of a binary tree and an integer `limit`, delete all **insufficient nodes** in the tree simultaneously, and return _the root of the resulting binary tree_.
A node is **insufficient** if every root to **leaf** path intersecting this node has a sum strictly less than `limit`.
A **leaf** is a node with n... | Given a single pattern and word, how can we solve it? One way to do it is using a DP (pos1, pos2) where pos1 is a pointer to the word and pos2 to the pattern and returns true if we can match the pattern with the given word. We have two scenarios: The first one is when `word[pos1] == pattern[pos2]`, then the transition ... |
Python - Two Pointer - Memory usage less than 100% | camelcase-matching | 0 | 1 | ```\nclass Solution:\n def camelMatch(self, queries: List[str], pattern: str) -> List[bool]:\n \n def match(p, q):\n i = 0\n for j, c in enumerate(q):\n if i < len(p) and p[i] == q[j]: i += 1\n elif q[j].isupper(): return False\n return i =... | 10 | Given an array of strings `queries` and a string `pattern`, return a boolean array `answer` where `answer[i]` is `true` if `queries[i]` matches `pattern`, and `false` otherwise.
A query word `queries[i]` matches `pattern` if you can insert lowercase English letters pattern so that it equals the query. You may insert e... | null |
Python - Two Pointer - Memory usage less than 100% | camelcase-matching | 0 | 1 | ```\nclass Solution:\n def camelMatch(self, queries: List[str], pattern: str) -> List[bool]:\n \n def match(p, q):\n i = 0\n for j, c in enumerate(q):\n if i < len(p) and p[i] == q[j]: i += 1\n elif q[j].isupper(): return False\n return i =... | 10 | Given the `root` of a binary tree and an integer `limit`, delete all **insufficient nodes** in the tree simultaneously, and return _the root of the resulting binary tree_.
A node is **insufficient** if every root to **leaf** path intersecting this node has a sum strictly less than `limit`.
A **leaf** is a node with n... | Given a single pattern and word, how can we solve it? One way to do it is using a DP (pos1, pos2) where pos1 is a pointer to the word and pos2 to the pattern and returns true if we can match the pattern with the given word. We have two scenarios: The first one is when `word[pos1] == pattern[pos2]`, then the transition ... |
Python - 2 Pointers | camelcase-matching | 0 | 1 | # Code\n```python\nclass Solution:\n def camelMatch(self, queries: List[str], pattern: str) -> List[bool]:\n def matches(query, pattern):\n j = 0\n for i in range(len(query)):\n # If the current character in the pattern matches the\n # current character ... | 0 | Given an array of strings `queries` and a string `pattern`, return a boolean array `answer` where `answer[i]` is `true` if `queries[i]` matches `pattern`, and `false` otherwise.
A query word `queries[i]` matches `pattern` if you can insert lowercase English letters pattern so that it equals the query. You may insert e... | null |
Python - 2 Pointers | camelcase-matching | 0 | 1 | # Code\n```python\nclass Solution:\n def camelMatch(self, queries: List[str], pattern: str) -> List[bool]:\n def matches(query, pattern):\n j = 0\n for i in range(len(query)):\n # If the current character in the pattern matches the\n # current character ... | 0 | Given the `root` of a binary tree and an integer `limit`, delete all **insufficient nodes** in the tree simultaneously, and return _the root of the resulting binary tree_.
A node is **insufficient** if every root to **leaf** path intersecting this node has a sum strictly less than `limit`.
A **leaf** is a node with n... | Given a single pattern and word, how can we solve it? One way to do it is using a DP (pos1, pos2) where pos1 is a pointer to the word and pos2 to the pattern and returns true if we can match the pattern with the given word. We have two scenarios: The first one is when `word[pos1] == pattern[pos2]`, then the transition ... |
80% TC and 80% M Easy Solution for Beginners | camelcase-matching | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 0 | Given an array of strings `queries` and a string `pattern`, return a boolean array `answer` where `answer[i]` is `true` if `queries[i]` matches `pattern`, and `false` otherwise.
A query word `queries[i]` matches `pattern` if you can insert lowercase English letters pattern so that it equals the query. You may insert e... | null |
80% TC and 80% M Easy Solution for Beginners | camelcase-matching | 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 the `root` of a binary tree and an integer `limit`, delete all **insufficient nodes** in the tree simultaneously, and return _the root of the resulting binary tree_.
A node is **insufficient** if every root to **leaf** path intersecting this node has a sum strictly less than `limit`.
A **leaf** is a node with n... | Given a single pattern and word, how can we solve it? One way to do it is using a DP (pos1, pos2) where pos1 is a pointer to the word and pos2 to the pattern and returns true if we can match the pattern with the given word. We have two scenarios: The first one is when `word[pos1] == pattern[pos2]`, then the transition ... |
Python - Two Pointers | camelcase-matching | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWhen query[i] == pattern[j] increment both pointers. If there is a mismatch, then the only scenario where we reject is when query[i] is uppercase character, otherwise we keep matching by just incrementing our i pointer (query string point... | 0 | Given an array of strings `queries` and a string `pattern`, return a boolean array `answer` where `answer[i]` is `true` if `queries[i]` matches `pattern`, and `false` otherwise.
A query word `queries[i]` matches `pattern` if you can insert lowercase English letters pattern so that it equals the query. You may insert e... | null |
Python - Two Pointers | camelcase-matching | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWhen query[i] == pattern[j] increment both pointers. If there is a mismatch, then the only scenario where we reject is when query[i] is uppercase character, otherwise we keep matching by just incrementing our i pointer (query string point... | 0 | Given the `root` of a binary tree and an integer `limit`, delete all **insufficient nodes** in the tree simultaneously, and return _the root of the resulting binary tree_.
A node is **insufficient** if every root to **leaf** path intersecting this node has a sum strictly less than `limit`.
A **leaf** is a node with n... | Given a single pattern and word, how can we solve it? One way to do it is using a DP (pos1, pos2) where pos1 is a pointer to the word and pos2 to the pattern and returns true if we can match the pattern with the given word. We have two scenarios: The first one is when `word[pos1] == pattern[pos2]`, then the transition ... |
Solution | video-stitching | 1 | 1 | ```C++ []\nclass Solution {\n public:\n int videoStitching(vector<vector<int>>& clips, int time) {\n int ans = 0;\n int end = 0;\n int farthest = 0;\n\n sort(std::begin(clips), std::end(clips));\n\n int i = 0;\n while (farthest < time) {\n while (i < clips.size() && clips[i][0] <= end)\n ... | 1 | You are given a series of video clips from a sporting event that lasted `time` seconds. These video clips can be overlapping with each other and have varying lengths.
Each video clip is described by an array `clips` where `clips[i] = [starti, endi]` indicates that the ith clip started at `starti` and ended at `endi`.
... | null |
Solution | video-stitching | 1 | 1 | ```C++ []\nclass Solution {\n public:\n int videoStitching(vector<vector<int>>& clips, int time) {\n int ans = 0;\n int end = 0;\n int farthest = 0;\n\n sort(std::begin(clips), std::end(clips));\n\n int i = 0;\n while (farthest < time) {\n while (i < clips.size() && clips[i][0] <= end)\n ... | 1 | Given a string `s`, return _the_ _lexicographically smallest_ _subsequence_ _of_ `s` _that contains all the distinct characters of_ `s` _exactly once_.
**Example 1:**
**Input:** s = "bcabc "
**Output:** "abc "
**Example 2:**
**Input:** s = "cbacdcbc "
**Output:** "acdb "
**Constraints:**
* `1 <= s.length <=... | What if we sort the intervals? Considering the sorted intervals, how can we solve the problem with dynamic programming? Let's consider a DP(pos, limit) where pos represents the position of the current interval we are gonna take the decision and limit is the current covered area from [0 - limit]. This DP returns the mi... |
[Python] Greedy With Sorting - Comprehensive Explanation | video-stitching | 0 | 1 | # Intuition\n\nThe problem is to stitch video clips in a way that the resulting video covers the entire desired time, and we should use as few clips as possible. To achieve this, we need to select clips that start at or before the current end time and extend the video as far as possible.\n\n# Algorithm\n1. Sort the inp... | 1 | You are given a series of video clips from a sporting event that lasted `time` seconds. These video clips can be overlapping with each other and have varying lengths.
Each video clip is described by an array `clips` where `clips[i] = [starti, endi]` indicates that the ith clip started at `starti` and ended at `endi`.
... | null |
[Python] Greedy With Sorting - Comprehensive Explanation | video-stitching | 0 | 1 | # Intuition\n\nThe problem is to stitch video clips in a way that the resulting video covers the entire desired time, and we should use as few clips as possible. To achieve this, we need to select clips that start at or before the current end time and extend the video as far as possible.\n\n# Algorithm\n1. Sort the inp... | 1 | Given a string `s`, return _the_ _lexicographically smallest_ _subsequence_ _of_ `s` _that contains all the distinct characters of_ `s` _exactly once_.
**Example 1:**
**Input:** s = "bcabc "
**Output:** "abc "
**Example 2:**
**Input:** s = "cbacdcbc "
**Output:** "acdb "
**Constraints:**
* `1 <= s.length <=... | What if we sort the intervals? Considering the sorted intervals, how can we solve the problem with dynamic programming? Let's consider a DP(pos, limit) where pos represents the position of the current interval we are gonna take the decision and limit is the current covered area from [0 - limit]. This DP returns the mi... |
Python 3 || 11 lines, w/explanation || T/M: 98% / 81% | video-stitching | 0 | 1 | Here\'s the plan:\n- We sort `clip` by increasing `start` and then by decreasing `end` for those clips with same `start`.\n- We initiate `t` to keep track of the`end`of the most recent clip we use. If and when `t` equals or exceeds `time`, we return the number of clips. If we run out of clips before that happens, then ... | 7 | You are given a series of video clips from a sporting event that lasted `time` seconds. These video clips can be overlapping with each other and have varying lengths.
Each video clip is described by an array `clips` where `clips[i] = [starti, endi]` indicates that the ith clip started at `starti` and ended at `endi`.
... | null |
Python 3 || 11 lines, w/explanation || T/M: 98% / 81% | video-stitching | 0 | 1 | Here\'s the plan:\n- We sort `clip` by increasing `start` and then by decreasing `end` for those clips with same `start`.\n- We initiate `t` to keep track of the`end`of the most recent clip we use. If and when `t` equals or exceeds `time`, we return the number of clips. If we run out of clips before that happens, then ... | 7 | Given a string `s`, return _the_ _lexicographically smallest_ _subsequence_ _of_ `s` _that contains all the distinct characters of_ `s` _exactly once_.
**Example 1:**
**Input:** s = "bcabc "
**Output:** "abc "
**Example 2:**
**Input:** s = "cbacdcbc "
**Output:** "acdb "
**Constraints:**
* `1 <= s.length <=... | What if we sort the intervals? Considering the sorted intervals, how can we solve the problem with dynamic programming? Let's consider a DP(pos, limit) where pos represents the position of the current interval we are gonna take the decision and limit is the current covered area from [0 - limit]. This DP returns the mi... |
py3 dp | video-stitching | 0 | 1 | # Code\n```\nclass Solution:\n def videoStitching(self, clips: List[List[int]], time: int) -> int:\n clips.sort()\n n = len(clips)\n @cache\n def dp(pos,limit):\n if limit >= time:\n return 0\n if pos == n:\n return float(\'inf\') \n ... | 0 | You are given a series of video clips from a sporting event that lasted `time` seconds. These video clips can be overlapping with each other and have varying lengths.
Each video clip is described by an array `clips` where `clips[i] = [starti, endi]` indicates that the ith clip started at `starti` and ended at `endi`.
... | null |
py3 dp | video-stitching | 0 | 1 | # Code\n```\nclass Solution:\n def videoStitching(self, clips: List[List[int]], time: int) -> int:\n clips.sort()\n n = len(clips)\n @cache\n def dp(pos,limit):\n if limit >= time:\n return 0\n if pos == n:\n return float(\'inf\') \n ... | 0 | Given a string `s`, return _the_ _lexicographically smallest_ _subsequence_ _of_ `s` _that contains all the distinct characters of_ `s` _exactly once_.
**Example 1:**
**Input:** s = "bcabc "
**Output:** "abc "
**Example 2:**
**Input:** s = "cbacdcbc "
**Output:** "acdb "
**Constraints:**
* `1 <= s.length <=... | What if we sort the intervals? Considering the sorted intervals, how can we solve the problem with dynamic programming? Let's consider a DP(pos, limit) where pos represents the position of the current interval we are gonna take the decision and limit is the current covered area from [0 - limit]. This DP returns the mi... |
Python Recurrent Solution Without Sorting or DP | video-stitching | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nFrom initial 0 point, find the clip that includes the zero point with largest clip ending value. During the iteration, collect all the clips whose beginning point is large than the zero point. \n\nThen, update the zero point to the larges... | 0 | You are given a series of video clips from a sporting event that lasted `time` seconds. These video clips can be overlapping with each other and have varying lengths.
Each video clip is described by an array `clips` where `clips[i] = [starti, endi]` indicates that the ith clip started at `starti` and ended at `endi`.
... | null |
Python Recurrent Solution Without Sorting or DP | video-stitching | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nFrom initial 0 point, find the clip that includes the zero point with largest clip ending value. During the iteration, collect all the clips whose beginning point is large than the zero point. \n\nThen, update the zero point to the larges... | 0 | Given a string `s`, return _the_ _lexicographically smallest_ _subsequence_ _of_ `s` _that contains all the distinct characters of_ `s` _exactly once_.
**Example 1:**
**Input:** s = "bcabc "
**Output:** "abc "
**Example 2:**
**Input:** s = "cbacdcbc "
**Output:** "acdb "
**Constraints:**
* `1 <= s.length <=... | What if we sort the intervals? Considering the sorted intervals, how can we solve the problem with dynamic programming? Let's consider a DP(pos, limit) where pos represents the position of the current interval we are gonna take the decision and limit is the current covered area from [0 - limit]. This DP returns the mi... |
Sorting - O(nlogn) | video-stitching | 0 | 1 | # Complexity\n```\n- Time complexity: O(nlogn)\n- Space complexity: O(1)\n```\n# Code\n```\nclass Solution:\n def videoStitching(self, A: List[List[int]], N: int) -> int:\n A, H, p, mxe, R = sorted(A, key=lambda x: (x[0], -x[1])), [], 0, -1, 0\n for s, e in A:\n if p < s:\n if... | 0 | You are given a series of video clips from a sporting event that lasted `time` seconds. These video clips can be overlapping with each other and have varying lengths.
Each video clip is described by an array `clips` where `clips[i] = [starti, endi]` indicates that the ith clip started at `starti` and ended at `endi`.
... | null |
Sorting - O(nlogn) | video-stitching | 0 | 1 | # Complexity\n```\n- Time complexity: O(nlogn)\n- Space complexity: O(1)\n```\n# Code\n```\nclass Solution:\n def videoStitching(self, A: List[List[int]], N: int) -> int:\n A, H, p, mxe, R = sorted(A, key=lambda x: (x[0], -x[1])), [], 0, -1, 0\n for s, e in A:\n if p < s:\n if... | 0 | Given a string `s`, return _the_ _lexicographically smallest_ _subsequence_ _of_ `s` _that contains all the distinct characters of_ `s` _exactly once_.
**Example 1:**
**Input:** s = "bcabc "
**Output:** "abc "
**Example 2:**
**Input:** s = "cbacdcbc "
**Output:** "acdb "
**Constraints:**
* `1 <= s.length <=... | What if we sort the intervals? Considering the sorted intervals, how can we solve the problem with dynamic programming? Let's consider a DP(pos, limit) where pos represents the position of the current interval we are gonna take the decision and limit is the current covered area from [0 - limit]. This DP returns the mi... |
sort clip[0] in ascending when clip[0] same then clip[1] in descending order, then stack to check | video-stitching | 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 series of video clips from a sporting event that lasted `time` seconds. These video clips can be overlapping with each other and have varying lengths.
Each video clip is described by an array `clips` where `clips[i] = [starti, endi]` indicates that the ith clip started at `starti` and ended at `endi`.
... | null |
sort clip[0] in ascending when clip[0] same then clip[1] in descending order, then stack to check | video-stitching | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 0 | Given a string `s`, return _the_ _lexicographically smallest_ _subsequence_ _of_ `s` _that contains all the distinct characters of_ `s` _exactly once_.
**Example 1:**
**Input:** s = "bcabc "
**Output:** "abc "
**Example 2:**
**Input:** s = "cbacdcbc "
**Output:** "acdb "
**Constraints:**
* `1 <= s.length <=... | What if we sort the intervals? Considering the sorted intervals, how can we solve the problem with dynamic programming? Let's consider a DP(pos, limit) where pos represents the position of the current interval we are gonna take the decision and limit is the current covered area from [0 - limit]. This DP returns the mi... |
Python O(n log n) sorting + two pointer method | video-stitching | 0 | 1 | # Approach\n<!-- Describe your approach to solving the problem. -->\n1. Sort the clips array according to ascending start time. Also, append a sentinel to the end of the array. It can be anything, but make sure its `start time > time`.\n2. Set two pointers: `start = 0`, `end = -1`.\n3. Iterate over the clips.\n + If ... | 0 | You are given a series of video clips from a sporting event that lasted `time` seconds. These video clips can be overlapping with each other and have varying lengths.
Each video clip is described by an array `clips` where `clips[i] = [starti, endi]` indicates that the ith clip started at `starti` and ended at `endi`.
... | null |
Python O(n log n) sorting + two pointer method | video-stitching | 0 | 1 | # Approach\n<!-- Describe your approach to solving the problem. -->\n1. Sort the clips array according to ascending start time. Also, append a sentinel to the end of the array. It can be anything, but make sure its `start time > time`.\n2. Set two pointers: `start = 0`, `end = -1`.\n3. Iterate over the clips.\n + If ... | 0 | Given a string `s`, return _the_ _lexicographically smallest_ _subsequence_ _of_ `s` _that contains all the distinct characters of_ `s` _exactly once_.
**Example 1:**
**Input:** s = "bcabc "
**Output:** "abc "
**Example 2:**
**Input:** s = "cbacdcbc "
**Output:** "acdb "
**Constraints:**
* `1 <= s.length <=... | What if we sort the intervals? Considering the sorted intervals, how can we solve the problem with dynamic programming? Let's consider a DP(pos, limit) where pos represents the position of the current interval we are gonna take the decision and limit is the current covered area from [0 - limit]. This DP returns the mi... |
Time:O(n); space: O(1) | video-stitching | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nMaybe the code can be optimised.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add ... | 0 | You are given a series of video clips from a sporting event that lasted `time` seconds. These video clips can be overlapping with each other and have varying lengths.
Each video clip is described by an array `clips` where `clips[i] = [starti, endi]` indicates that the ith clip started at `starti` and ended at `endi`.
... | null |
Time:O(n); space: O(1) | video-stitching | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nMaybe the code can be optimised.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add ... | 0 | Given a string `s`, return _the_ _lexicographically smallest_ _subsequence_ _of_ `s` _that contains all the distinct characters of_ `s` _exactly once_.
**Example 1:**
**Input:** s = "bcabc "
**Output:** "abc "
**Example 2:**
**Input:** s = "cbacdcbc "
**Output:** "acdb "
**Constraints:**
* `1 <= s.length <=... | What if we sort the intervals? Considering the sorted intervals, how can we solve the problem with dynamic programming? Let's consider a DP(pos, limit) where pos represents the position of the current interval we are gonna take the decision and limit is the current covered area from [0 - limit]. This DP returns the mi... |
Python One-Liner | Beats 97% | divisor-game | 0 | 1 | # Complexity\n- Time complexity:\nO(1)\n\n- Space complexity:\nO(1)\n\n# Code\n```\nclass Solution:\n def divisorGame(self, n: int) -> bool:\n return not n % 2\n``` | 1 | Alice and Bob take turns playing a game, with Alice starting first.
Initially, there is a number `n` on the chalkboard. On each player's turn, that player makes a move consisting of:
* Choosing any `x` with `0 < x < n` and `n % x == 0`.
* Replacing the number `n` on the chalkboard with `n - x`.
Also, if a player... | null |
Python One-Liner | Beats 97% | divisor-game | 0 | 1 | # Complexity\n- Time complexity:\nO(1)\n\n- Space complexity:\nO(1)\n\n# Code\n```\nclass Solution:\n def divisorGame(self, n: int) -> bool:\n return not n % 2\n``` | 1 | Given a list of the scores of different students, `items`, where `items[i] = [IDi, scorei]` represents one score from a student with `IDi`, calculate each student's **top five average**.
Return _the answer as an array of pairs_ `result`_, where_ `result[j] = [IDj, topFiveAveragej]` _represents the student with_ `IDj` ... | If the current number is even, we can always subtract a 1 to make it odd. If the current number is odd, we must subtract an odd number to make it even. |
Very Easy Python Solution | divisor-game | 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 | Alice and Bob take turns playing a game, with Alice starting first.
Initially, there is a number `n` on the chalkboard. On each player's turn, that player makes a move consisting of:
* Choosing any `x` with `0 < x < n` and `n % x == 0`.
* Replacing the number `n` on the chalkboard with `n - x`.
Also, if a player... | null |
Very Easy Python Solution | divisor-game | 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 | Given a list of the scores of different students, `items`, where `items[i] = [IDi, scorei]` represents one score from a student with `IDi`, calculate each student's **top five average**.
Return _the answer as an array of pairs_ `result`_, where_ `result[j] = [IDj, topFiveAveragej]` _represents the student with_ `IDj` ... | If the current number is even, we can always subtract a 1 to make it odd. If the current number is odd, we must subtract an odd number to make it even. |
Solution in Python 3 (With Detailed Proof) | divisor-game | 0 | 1 | The proof of why this works can be done formally using Mathematical Induction, specifically using <a href="https://en.wikipedia.org/wiki/Mathematical_induction#Complete_(strong)_induction">Strong Mathematical Induction</a>. However an informal proof will also suffice. Note that it is not enough to show that a player wh... | 177 | Alice and Bob take turns playing a game, with Alice starting first.
Initially, there is a number `n` on the chalkboard. On each player's turn, that player makes a move consisting of:
* Choosing any `x` with `0 < x < n` and `n % x == 0`.
* Replacing the number `n` on the chalkboard with `n - x`.
Also, if a player... | null |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.