question_slug stringlengths 3 77 | title stringlengths 1 183 | slug stringlengths 12 45 | summary stringlengths 1 160 ⌀ | author stringlengths 2 30 | certification stringclasses 2
values | created_at stringdate 2013-10-25 17:32:12 2025-04-12 09:38:24 | updated_at stringdate 2013-10-25 17:32:12 2025-04-12 09:38:24 | hit_count int64 0 10.6M | has_video bool 2
classes | content stringlengths 4 576k | upvotes int64 0 11.5k | downvotes int64 0 358 | tags stringlengths 2 193 | comments int64 0 2.56k |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
count-alternating-subarrays | [O(n)] Simple and clean, sliding window | on-simple-and-clean-sliding-window-by-fr-0rbv | Loop through and consider number of subarrays that end at j.\nSimple sliding window of the current alternating block.\nint j - end of alternating block\nint i - | frvnk | NORMAL | 2024-03-31T07:11:15.690603+00:00 | 2024-03-31T07:11:15.690639+00:00 | 61 | false | Loop through and consider number of subarrays that end at `j`.\nSimple sliding window of the current alternating block.\n`int j` - end of alternating block\n`int i` - minimum first index of current alternating block\n`int res` - total count of alternating subarrays\n\nAll subarrays $[i,j] , [i+1,j], \\ldots[j,j]$ are v... | 1 | 0 | ['C++'] | 1 |
count-alternating-subarrays | ✅ C++ Solution ✅ || Sliding window || Optimal | c-solution-sliding-window-optimal-by-ans-9wap | Approach\n Describe your approach to solving the problem. \n\nUses Sliding window\n\nDry run this example for better understanding : [1,0,1,0,0,1]\n\n# Complexi | anshumaan1024 | NORMAL | 2024-03-31T05:52:28.808089+00:00 | 2024-03-31T12:18:15.424457+00:00 | 91 | false | # Approach\n<!-- Describe your approach to solving the problem. -->\n\n**Uses Sliding window**\n\n*Dry run this example for better understanding* : [1,0,1,0,0,1]\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 your space complexit... | 1 | 0 | ['Sliding Window', 'C++', 'Java'] | 0 |
count-alternating-subarrays | Easy Java Solution || Beats 100% | easy-java-solution-beats-100-by-ravikuma-z14c | 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 | ravikumar50 | NORMAL | 2024-03-31T05:30:56.096531+00:00 | 2024-03-31T05:30:56.096549+00:00 | 10 | false | # 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 | 0 | ['Java'] | 0 |
count-alternating-subarrays | Java | Standard sliding window | time: O(n) | space: O(1) | java-standard-sliding-window-time-on-spa-1gcq | # Intuition \n\n\n\n\n\n# Complexity\n- Time complexity: O(n)\n\n\n- Space complexity: O(1)\n\n\n# Code\n\nclass Solution {\n public long countAlternatingS | shashankbhat | NORMAL | 2024-03-31T04:32:52.802912+00:00 | 2024-03-31T04:32:52.802934+00:00 | 44 | false | <!-- # 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(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add your space compl... | 1 | 0 | ['Two Pointers', 'Sliding Window', 'Java'] | 0 |
count-alternating-subarrays | ✅ Java || Time O(n) || Space O(1) || Sliding Window || Beginner Friendly Explanation ✅ | java-time-on-space-o1-sliding-window-beg-aemo | \n\n# Intuition\nThe problem involves counting the number of alternating subarrays in an array. An alternating subarray is defined as a contiguous subarray wher | 0xsonu | NORMAL | 2024-03-31T04:21:02.419807+00:00 | 2024-03-31T04:22:20.695355+00:00 | 47 | false | \n\n# Intuition\nThe problem involves counting the number of alternating subarrays in an array. An alternating subarray is defined as a contiguous subarray where all elements are either strictly increasing ... | 1 | 0 | ['Array', 'Greedy', 'Sliding Window', 'Java'] | 0 |
count-alternating-subarrays | Javascript - Easy Solution | javascript-easy-solution-by-vigneshkvm-j3gp | 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 | Vigneshkvm | NORMAL | 2024-03-31T04:11:15.639180+00:00 | 2024-03-31T04:11:15.639202+00:00 | 47 | false | # 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 | 0 | ['JavaScript'] | 0 |
count-alternating-subarrays | Rust/Python two pointers solution with explanation | rustpython-two-pointers-solution-with-ex-33ly | Intuition\n\nStandard two pointers solution. Have some value which tracks the previous number you have seen. Now move right pointer and check if the value you s | salvadordali | NORMAL | 2024-03-31T04:09:31.593537+00:00 | 2024-03-31T04:09:31.593562+00:00 | 71 | false | # Intuition\n\nStandard two pointers solution. Have some value which tracks the previous number you have seen. Now move right pointer and check if the value you see at this pointer is different from the previous seen. \n\nIf they are the same, you can\'t expand the interval and should update left pointer to right point... | 1 | 0 | ['Python', 'Rust'] | 0 |
count-alternating-subarrays | Optimised Solution | optimised-solution-by-sdkv-u7pz | \n# Complexity\n- Time complexity:\nO(N)\n\n- Space complexity:\nO(1)\n\n# Code\n\nclass Solution {\npublic:\n long long countAlternatingSubarrays(vector<int | sdkv | NORMAL | 2024-03-31T04:06:01.400049+00:00 | 2024-03-31T04:06:01.400079+00:00 | 0 | false | \n# Complexity\n- Time complexity:\nO(N)\n\n- Space complexity:\nO(1)\n\n# Code\n```\nclass Solution {\npublic:\n long long countAlternatingSubarrays(vector<int>& nums) {\n long long c=0,s=1,i=1; \n while(i<nums.size())\n {\n if(nums[i]!=nums[i-1]) \n {\n s++... | 1 | 0 | ['C++'] | 0 |
count-alternating-subarrays | 💡0101... & 1010.... | 0101-1010-by-jainwinn-rzji | Approach\nFormed two arrays of size n of 0,1,0,1\u2026(say arr1) and 1,0,1,0\u2026.(say arr2).\nNow iterating i(0 to n), find the maximum subarray common betwee | JainWinn | NORMAL | 2024-03-31T04:05:15.029480+00:00 | 2024-03-31T04:05:15.029502+00:00 | 44 | false | # Approach\nFormed two arrays of size n of 0,1,0,1\u2026(say arr1) and 1,0,1,0\u2026.(say arr2).\nNow iterating i(0 to n), find the maximum subarray common between given array nums and arr1 and set i to end of this subarray. Keep adding len*(len+1)/2 for every such subarray length.\nSimilarly do this with arr2 and nums... | 1 | 0 | ['C++'] | 0 |
count-alternating-subarrays | Java/Python Clean Solution | javapython-clean-solution-by-shree_govin-xwsz | 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 | Shree_Govind_Jee | NORMAL | 2024-03-31T04:04:50.881823+00:00 | 2024-03-31T04:04:50.881846+00:00 | 316 | false | # 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 public long countAlternatingSubarrays(int[] nums) {\n long count =0;\n int left = 0;\... | 1 | 0 | ['Array', 'Two Pointers', 'Python', 'Java', 'Python3'] | 0 |
count-alternating-subarrays | Sliding (Destructive) Window | sliding-destructive-window-by-rajesh_sv-aiwi | Intuition\nWindow is broken when adjacent nums are not alternating. So set left of window to right.\n\n# Code\n\nclass Solution:\n def countAlternatingSubarr | rajesh_sv | NORMAL | 2024-03-31T04:01:27.219755+00:00 | 2024-03-31T04:01:27.219788+00:00 | 16 | false | # Intuition\nWindow is broken when adjacent nums are not alternating. So set left of window to right.\n\n# Code\n```\nclass Solution:\n def countAlternatingSubarrays(self, nums: List[int]) -> int:\n # Sliding (Destructive) Window\n # Time Complexity: O(n)\n # Space Complexity: O(n)\n ans,... | 1 | 0 | ['Python3'] | 0 |
count-alternating-subarrays | LEETCODE CODESTORYWITHMIK SOLUTION | leetcode-codestorywithmik-solution-by-an-sng1 | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | anythingFORSQL | NORMAL | 2025-04-09T09:43:15.642066+00:00 | 2025-04-09T09:43:15.642066+00:00 | 2 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
`... | 0 | 0 | ['C++'] | 0 |
count-alternating-subarrays | Counting pattern | counting-pattern-by-boiiboii-4i4f | IntuitionApproach
Increase and reset to be changed when the condition is met.
Complexity
Time complexity:
O(n)
Space complexity:
O(1)Code | boiiboii | NORMAL | 2025-03-01T05:28:15.241401+00:00 | 2025-03-01T05:28:15.241401+00:00 | 2 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
- Increase and reset to be changed when the condition is met.
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
O(n)
- Space complexi... | 0 | 0 | ['C++'] | 0 |
count-alternating-subarrays | 0ms Beats100.00% slide window | 0ms-beats10000-slide-window-by-dinhson-n-iu42 | IntuitionApproachComplexity
Time complexity:
O(n)
Space complexity:
Code | sondinh1701_ | NORMAL | 2025-02-17T04:15:47.215911+00:00 | 2025-02-17T04:15:47.215911+00:00 | 3 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
$$O(n)$$
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
... | 0 | 0 | ['C++'] | 0 |
count-alternating-subarrays | Best approach for beginners using Java | best-approach-for-beginners-using-java-b-2vl7 | IntuitionThe problem requires counting all subarrays where adjacent elements alternate in value. A straightforward way to approach this is to traverse the array | ashu_okk | NORMAL | 2025-02-11T13:03:31.353966+00:00 | 2025-02-11T13:03:31.353966+00:00 | 2 | false | # Intuition
The problem requires counting all subarrays where adjacent elements alternate in value. A straightforward way to approach this is to traverse the array and track contiguous alternating sequences.
# Approach
- Initialize `count` with `n` since each element itself is an alternating subarray.
- Use a variable... | 0 | 0 | ['Java'] | 0 |
count-alternating-subarrays | Explanation in English and Russian | explanation-in-english-and-russian-by-de-siye | ExplanationIn this problem, a pattern can be observed:
If the array is fully alternating and has a length of 1, it has only 1 alternating subarray.
If the lengt | saparov | NORMAL | 2025-02-05T14:17:07.568260+00:00 | 2025-02-05T14:17:07.568260+00:00 | 2 | false | # Explanation
In this problem, a pattern can be observed:
- If the array is fully alternating and has a length of 1, it has only 1 alternating subarray.
- If the length of the array is 2, the number of such subarrays is 3.
- If the length is 3 — 6 subarrays.
- If the length is 4 — 10 subarrays, and so on.
To find the... | 0 | 0 | ['Java'] | 0 |
count-alternating-subarrays | O(1) space and O(n) time - DP Approach Java | o1-space-and-on-time-dp-approach-java-by-roj5 | IntuitionApproachDp approach using two variablesComplexity
Time complexity: O(n)
Space complexity: O(1)
Code | dhivya6613 | NORMAL | 2025-02-03T13:31:34.991535+00:00 | 2025-02-03T13:31:34.991535+00:00 | 2 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
Dp approach using two variables
# Complexity
- Time complexity: O(n)
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity: O(1)
<!-- Add your space c... | 0 | 0 | ['Dynamic Programming', 'Java'] | 0 |
count-alternating-subarrays | Intuition | intuition-by-fustigate-9c0z | Try working out a couple of custom examples on paper first.To start, consider 0101. Brute force it. How many alternating subarrays are there? Well, we can split | Fustigate | NORMAL | 2025-01-22T23:57:28.255150+00:00 | 2025-01-22T23:57:28.255150+00:00 | 5 | false | Try working out a couple of custom examples on paper first.
To start, consider 0101. Brute force it. How many alternating subarrays are there? Well, we can split it into different groups of length 1, length 2, length 3, and length 4. Respectively, 4, 3, 2, 1 of each. Therefore the result will be 4 + 3 + 2 + 1. So, we ... | 0 | 0 | ['Greedy', 'Python3'] | 0 |
count-alternating-subarrays | Easy to understand: O(n) two pointer & cool math trick approach EXPLAINED | easy-to-understand-on-two-pointer-cool-m-6leh | IntuitionAt first, I utilized brute force to solve this problem, where I went through each of the subarrays and checked if they were valid, and if they were, I | rohanmahajan03 | NORMAL | 2025-01-19T13:12:16.398642+00:00 | 2025-01-19T13:12:16.398642+00:00 | 5 | false | # Intuition
At first, I utilized brute force to solve this problem, where I went through each of the subarrays and checked if they were valid, and if they were, I added them to my "res" variable, which represents result and is what is ultimately returned. However, while this approach worked in principle, it exceeded th... | 0 | 0 | ['Python3'] | 0 |
count-alternating-subarrays | Video Explanation Solution easy to understand | Programming with Pirai | Half Moon Coder. | video-explanation-solution-easy-to-under-s37p | Video : Code | Piraisudan_02 | NORMAL | 2025-01-05T07:42:13.793531+00:00 | 2025-01-05T07:42:13.793531+00:00 | 5 | false | # Video : https://youtu.be/3Kb-DYfwinY
# Code
```python3 []
class Solution:
def countAlternatingSubarrays(self, nums: List[int]) -> int:
res=c=1
for i in range(1,len(nums)):
if nums[i]!=nums[i-1]:
c+=1
else:
c=1
res+=c
re... | 0 | 0 | ['Array', 'Math', 'Python3'] | 0 |
count-alternating-subarrays | Easy two line solution | easy-two-line-solution-by-nishantsharma0-p2uu | Intuitionif the current bit is alternate then it can contribute in each subarray so add the length of the current subarray.ApproachComplexity
Time complexity: O | nishantsharma0611 | NORMAL | 2024-12-29T05:22:58.318871+00:00 | 2024-12-29T05:22:58.318871+00:00 | 3 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
if the current bit is alternate then it can contribute in each subarray so add the length of the current subarray.
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity: O(n)
<!-- Add your time c... | 0 | 0 | ['C++'] | 0 |
count-alternating-subarrays | very easy beginner friendly solution using common sense | very-easy-beginner-friendly-solution-usi-b0h7 | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | tanish67 | NORMAL | 2024-12-24T14:45:22.648713+00:00 | 2024-12-24T14:45:22.648713+00:00 | 2 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
`... | 0 | 0 | ['Java'] | 0 |
count-alternating-subarrays | O(n) java | on-java-by-vamseedhar8680-qnwy | IntuitionSo for each index if the prev char matches current char subarray count of that element is i+1. if it doesnt match subarray count of cur element is set | Vamseedhar8680 | NORMAL | 2024-12-24T11:37:41.525007+00:00 | 2024-12-24T11:37:41.525007+00:00 | 0 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
So for each index if the prev char matches current char subarray count of that element is i+1. if it doesnt match subarray count of cur element is set to be 1 as it forms new subarray.
# Approach
<!-- Describe your approach to solving the ... | 0 | 0 | ['Array', 'Math', 'Java'] | 0 |
count-alternating-subarrays | O(n) java | on-java-by-vamseedhar8680-2jpq | IntuitionSo for each index if the prev char matches current char subarray count of that element is i+1. if it doesnt match subarray count of cur element is set | Vamseedhar8680 | NORMAL | 2024-12-24T11:37:37.951320+00:00 | 2024-12-24T11:37:37.951320+00:00 | 2 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
So for each index if the prev char matches current char subarray count of that element is i+1. if it doesnt match subarray count of cur element is set to be 1 as it forms new subarray.
# Approach
<!-- Describe your approach to solving the ... | 0 | 0 | ['Array', 'Math', 'Java'] | 0 |
count-alternating-subarrays | Easy Python Solution | easy-python-solution-by-sb012-gbvo | Code | sb012 | NORMAL | 2024-12-18T05:15:37.088982+00:00 | 2024-12-18T05:18:03.452954+00:00 | 5 | false | # Code\n```python3 []\nclass Solution:\n def countAlternatingSubarrays(self, nums: List[int]) -> int:\n left = right = 0\n answer = 0\n\n while right < len(nums):\n answer += right - left + 1\n right += 1\n\n if right < len(nums) and nums[right] == nums[right - 1... | 0 | 0 | ['Python3'] | 0 |
count-alternating-subarrays | easy solution using java check it out || <<AWSZOABI>> | easy-solution-using-java-check-it-out-aw-ya7r | 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 | AWSZ | NORMAL | 2024-11-20T23:54:41.968227+00:00 | 2024-11-20T23:54:41.968250+00:00 | 0 | false | # 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 | 0 | ['Java'] | 0 |
count-alternating-subarrays | 3101. Count Alternating Subarrays | 3101-count-alternating-subarrays-by-kuma-4gcb | 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 | KumarDev2003 | NORMAL | 2024-11-20T19:25:42.645760+00:00 | 2024-11-20T19:25:42.645793+00:00 | 0 | false | # 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 | 0 | ['C++'] | 0 |
count-alternating-subarrays | Beats 92.68% Python. | beats-9268-python-by-anthonybaston101-lje9 | Intuition\n Describe your first thoughts on how to solve this problem. \n\nImagine creating a boolean array of length n - 1, where the $i^{th}$ element is False | anthonybaston101 | NORMAL | 2024-11-20T15:45:40.288742+00:00 | 2024-11-20T15:45:40.288845+00:00 | 3 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\nImagine creating a boolean array of length n - 1, where the $i^{th}$ element is `False` if `nums[i] != nums[i + 1]` and otherwise `True`. \n\nWe can map any subarray of nums to this new boolean array. If such a subarray (when mapped) co... | 0 | 0 | ['Python3'] | 0 |
count-alternating-subarrays | 3101. Count Alternating Subarrays | 3101-count-alternating-subarrays-by-pgmr-c8el | 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 | pgmreddy | NORMAL | 2024-11-03T08:05:50.944401+00:00 | 2024-11-03T08:05:50.944421+00:00 | 6 | false | # 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 | 0 | ['JavaScript'] | 0 |
count-alternating-subarrays | [Java] ✅ 3MS ✅ 100% ✅ SLIDING WINDOW ✅ FASTEST ✅ BEST | java-3ms-100-sliding-window-fastest-best-gjot | Approach\n1. Expand a window (left, right) while char[right] != char[right + 1]\n2. Inside this valid window you have n * (n+1) /2 substrings. (1 + right - left | StefanelStan | NORMAL | 2024-11-01T01:33:15.659083+00:00 | 2024-11-01T01:33:15.659110+00:00 | 10 | false | # Approach\n1. Expand a window (left, right) while char[right] != char[right + 1]\n2. Inside this valid window you have n * (n+1) /2 substrings. (1 + right - left)\n3. Adjust left and right to right +1 (window starts at next position where right stopped)\n\n# Complexity\n- Time complexity:$$O(n)$$\n<!-- Add your time c... | 0 | 0 | ['Sliding Window', 'Java'] | 0 |
count-alternating-subarrays | Python: one for() loop | python-one-for-loop-by-alexc2024-d5ez | \n# Complexity\nBeats 100% (time)\n\n\n\n# Code\npython []\nclass Solution(object):\n\n def countAlternatingSubarrays(self, nums):\n """\n :typ | AlexC2024 | NORMAL | 2024-10-24T17:10:44.887606+00:00 | 2024-10-24T17:10:44.887640+00:00 | 2 | false | \n# Complexity\nBeats 100% (time)\n\n\n\n# Code\n```python []\nclass Solution(object):\n\n def countAlternatingSubarrays(self, nums):\n """\n :type nums: List[int]\n :rtype: int\n """\n count = 0\n alt_length = 1\n for i in range(1, len(nums)):\n if nums[i]... | 0 | 0 | ['Python'] | 0 |
count-alternating-subarrays | Python3 solution with two pointers | python3-solution-with-two-pointers-by-yu-w11o | 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 | yukikitayama | NORMAL | 2024-10-21T12:40:37.504520+00:00 | 2024-10-21T12:40:37.504545+00:00 | 2 | false | # 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 | 0 | ['Python3'] | 0 |
count-alternating-subarrays | JAVA easiest O(N) solution - sliding window approach | java-easiest-on-solution-sliding-window-gsi40 | Approach\nJust apply the sliding window approach, change the initial pointer to new when a repeated digit is found. Focus on the fact that it is a binary array. | blisss | NORMAL | 2024-10-10T23:02:17.761077+00:00 | 2024-10-10T23:02:17.761111+00:00 | 0 | false | # Approach\nJust apply the sliding window approach, change the initial pointer to new when a repeated digit is found. Focus on the fact that it is a binary array. \nUse mathematical formula to calculate number of possible subsets.\n# Complexity\n- Time complexity: $$O(n)$$ \n\n# Code\n```java []\nclass Solution {\n ... | 0 | 0 | ['Java'] | 0 |
count-alternating-subarrays | Add the arithmetic sum of the length of each alternating array | add-the-arithmetic-sum-of-the-length-of-4ckq5 | Approach\nThe number of subarrays of any given array can be found by calculating the arithmethic sum of the length of that array (0 + 1 + 2 + 3 ... + n - 1 + n) | bldrnnr0x7ca | NORMAL | 2024-10-10T18:10:14.166895+00:00 | 2024-10-10T18:10:14.166919+00:00 | 0 | false | # Approach\nThe number of subarrays of any given array can be found by calculating the arithmethic sum of the length of that array (0 + 1 + 2 + 3 ... + n - 1 + n), where n is the length of the subarray of alternating numbers.\n\nE.g. the number of subarrays of an array of length 4 = 4 + 3 + 2 + 1 = 10.\n\nSimply calcul... | 0 | 0 | ['Python3'] | 0 |
count-alternating-subarrays | Brute Completion Challenge #4 (no analysis) | brute-completion-challenge-4-no-analysis-meuq | Code\nruby []\n# @param {Integer[]} nums\n# @return {Integer}\ndef count_alternating_subarrays(nums)\n # every length 1 subarray is alternating:\n l = num | ifiht | NORMAL | 2024-10-05T20:44:53.321025+00:00 | 2024-10-05T20:44:53.321063+00:00 | 0 | false | # Code\n```ruby []\n# @param {Integer[]} nums\n# @return {Integer}\ndef count_alternating_subarrays(nums)\n # every length 1 subarray is alternating:\n l = nums.length\n # all length = 1 subarrays are valid\n altsubs = l\n # start with a length = 2 subarray\n ic = 1\n is = 0\n # there is no curr... | 0 | 0 | ['Ruby'] | 0 |
count-alternating-subarrays | Best Easy Soln | best-easy-soln-by-_rahul123-806c | 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 | _Rahul123 | NORMAL | 2024-09-19T05:33:23.231609+00:00 | 2024-09-19T05:33:23.231646+00:00 | 1 | false | # 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(n)\n\n\n- Space complexity: O(1)\n\n\n# Code\n```cpp []\nclass Solution {\npublic:\n long long countAlternatingSubarrays(vector... | 0 | 0 | ['C++'] | 0 |
count-alternating-subarrays | C++ Solution || Easy to Understand | c-solution-easy-to-understand-by-pardhav-6gfg | Code\ncpp []\nclass Solution {\npublic:\n long long countAlternatingSubarrays(vector<int>& nums) {\n if (nums.size() == 1) return 1;\n long lon | Pardhav_081911 | NORMAL | 2024-09-12T18:18:03.114615+00:00 | 2024-09-12T18:18:03.114636+00:00 | 1 | false | # Code\n```cpp []\nclass Solution {\npublic:\n long long countAlternatingSubarrays(vector<int>& nums) {\n if (nums.size() == 1) return 1;\n long long count = nums.size();\n long long len =0;\n for (long long i = 1; i < nums.size(); i++) {\n if (nums[i] != nums[i - 1]) {\n ... | 0 | 0 | ['C++'] | 0 |
count-alternating-subarrays | Easy C++ Solution | easy-c-solution-by-022_ankit-loku | ```\nlong long countAlternatingSubarrays(vector& nums) {\n long long ans=0;\n int n=nums.size();\n int i=0,j=0;\n while(j0&&nums[j]! | 022_ankit | NORMAL | 2024-09-01T14:14:15.355172+00:00 | 2024-09-01T14:14:15.355209+00:00 | 0 | false | ```\nlong long countAlternatingSubarrays(vector<int>& nums) {\n long long ans=0;\n int n=nums.size();\n int i=0,j=0;\n while(j<n)\n {\n if(i==j||(j>0&&nums[j]!=nums[j-1]))\n {\n ans+=(j-i+1);\n j++;\n }\n else \... | 0 | 0 | [] | 0 |
count-alternating-subarrays | [Accepted] Swift | accepted-swift-by-vasilisiniak-uodx | \nclass Solution {\n func countAlternatingSubarrays(_ nums: [Int]) -> Int {\n\n var dp = Array(repeating: 1, count: nums.count)\n\n for i in 1. | vasilisiniak | NORMAL | 2024-08-31T21:27:13.130639+00:00 | 2024-08-31T21:27:13.130664+00:00 | 4 | false | ```\nclass Solution {\n func countAlternatingSubarrays(_ nums: [Int]) -> Int {\n\n var dp = Array(repeating: 1, count: nums.count)\n\n for i in 1..<nums.count\n where nums[i] != nums[i - 1] {\n dp[i] += dp[i - 1]\n }\n \n return dp.reduce(0, +)\n }\... | 0 | 0 | ['Swift'] | 0 |
count-alternating-subarrays | O(N) | on-by-p_patel_12-pxwf | 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 | P_patel_12 | NORMAL | 2024-08-31T12:55:40.187789+00:00 | 2024-08-31T12:55:40.187873+00:00 | 0 | false | # 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 | 0 | ['C++'] | 0 |
count-alternating-subarrays | Scala two pointer stuff with recursion | scala-two-pointer-stuff-with-recursion-b-kl8p | 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 | MaxPsm | NORMAL | 2024-08-28T16:55:38.943665+00:00 | 2024-08-28T16:55:38.943702+00:00 | 0 | false | # 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 | 0 | ['Scala'] | 0 |
count-alternating-subarrays | Very Easy Java solution 🔥 Beats 97 % of Java Users . | very-easy-java-solution-beats-97-of-java-zsxh | 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 | zzzz9 | NORMAL | 2024-08-26T23:49:32.743235+00:00 | 2024-08-26T23:49:32.743254+00:00 | 3 | false | # 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 | 0 | ['Java'] | 0 |
count-alternating-subarrays | Recursion, without memoization Beats 6.15% | recursion-without-memoization-beats-615-d9j0i | Approach\nI started from Top down DP, but it tuns out solution without memoization accepted.\nwe\'re not actually counting subarrays, we can instead use the ar | remedydev | NORMAL | 2024-08-22T08:13:38.946887+00:00 | 2024-08-22T08:13:38.946915+00:00 | 4 | false | # Approach\nI started from Top down DP, but it tuns out solution without memoization accepted.\nwe\'re not actually counting subarrays, we can instead use the arithmetic progression formula 1+2+3+4+\u2026, which gives us the number of subarrays within the start and end indexes. Please refer to the comments in the code... | 0 | 0 | ['JavaScript'] | 0 |
count-alternating-subarrays | NNN solution with O(n) | nnn-solution-with-on-by-hokhacnhat-72ri | 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 | hokhacnhat | NORMAL | 2024-08-21T12:55:17.494827+00:00 | 2024-08-21T12:55:17.494862+00:00 | 0 | false | # 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 | 0 | ['Java'] | 0 |
count-alternating-subarrays | Easy CPP Solution | easy-cpp-solution-by-clary_shadowhunters-v81d | \n\n# Code\ncpp []\nclass Solution {\npublic:\n long long countAlternatingSubarrays(vector<int>& nums) \n {\n long long ans=1;\n long lo | Clary_ShadowHunters | NORMAL | 2024-08-20T11:32:18.556150+00:00 | 2024-08-20T11:32:18.556180+00:00 | 0 | false | \n\n# Code\n```cpp []\nclass Solution {\npublic:\n long long countAlternatingSubarrays(vector<int>& nums) \n {\n long long ans=1;\n long long j=0;\n for (long long i=1;i<nums.size();i++)\n {\n if (nums[i]==nums[i-1]) j=i;\n ans+=(i-j+1);\n }\n ... | 0 | 0 | ['C++'] | 0 |
distribute-candies | Python, Straightforward with Explanation | python-straightforward-with-explanation-0quw1 | There are len(set(candies)) unique candies, and the sister picks only len(candies) / 2 of them, so she can't have more than this amount.\n\nFor example, if ther | awice | NORMAL | 2017-05-07T03:08:19.236000+00:00 | 2018-10-22T14:57:33.713195+00:00 | 15,101 | false | There are ```len(set(candies))``` unique candies, and the sister picks only ```len(candies) / 2``` of them, so she can't have more than this amount.\n\nFor example, if there are 5 unique candies, then if she is picking 4 candies, she will take 4 unique ones. If she is picking 7 candies, then she will only take 5 uniqu... | 128 | 1 | [] | 24 |
distribute-candies | C++ 1-liner | c-1-liner-by-votrubac-hqgj | \nint distributeCandies(vector<int>& c) {\n return min(unordered_set<int>(begin(c), end(c)).size(), c.size() / 2);\n}\n | votrubac | NORMAL | 2017-05-07T06:12:53.451000+00:00 | 2018-08-22T06:08:35.854166+00:00 | 5,869 | false | ```\nint distributeCandies(vector<int>& c) {\n return min(unordered_set<int>(begin(c), end(c)).size(), c.size() / 2);\n}\n``` | 77 | 6 | [] | 12 |
distribute-candies | Java Solution, 3 lines, HashSet | java-solution-3-lines-hashset-by-shawnga-uc0a | Thanks @wmcalyj , modified to use HashSet.\n\npublic class Solution {\n public int distributeCandies(int[] candies) {\n Set<Integer> kinds = new HashS | shawngao | NORMAL | 2017-05-07T03:06:23.108000+00:00 | 2018-08-15T07:32:04.362135+00:00 | 19,955 | false | Thanks @wmcalyj , modified to use HashSet.\n```\npublic class Solution {\n public int distributeCandies(int[] candies) {\n Set<Integer> kinds = new HashSet<>();\n for (int candy : candies) kinds.add(candy);\n return kinds.size() >= candies.length / 2 ? candies.length / 2 : kinds.size();\n }\n... | 65 | 2 | [] | 16 |
distribute-candies | C++, bitset, beats 99.60% | c-bitset-beats-9960-by-zestypanda-4az5 | The idea is to use biset as hash table instead of unordered_set.\n\nint distributeCandies(vector<int>& candies) {\n bitset<200001> hash;\n int cou | zestypanda | NORMAL | 2017-05-11T23:08:48.849000+00:00 | 2017-05-11T23:08:48.849000+00:00 | 6,863 | false | The idea is to use biset as hash table instead of unordered_set.\n```\nint distributeCandies(vector<int>& candies) {\n bitset<200001> hash;\n int count = 0;\n for (int i : candies) {\n if (!hash.test(i+100000)) {\n count++;\n hash.set(i+100000);\n }... | 41 | 0 | [] | 8 |
distribute-candies | 1-line JavaScript O(n) solution using Set | 1-line-javascript-on-solution-using-set-i32gu | \nvar distributeCandies = function(candies) {\n return Math.min(new Set(candies).size, candies.length / 2);\n};\n | loctn | NORMAL | 2017-05-07T03:41:50.429000+00:00 | 2017-05-07T03:41:50.429000+00:00 | 2,970 | false | ```\nvar distributeCandies = function(candies) {\n return Math.min(new Set(candies).size, candies.length / 2);\n};\n``` | 33 | 1 | ['JavaScript'] | 2 |
distribute-candies | [C++] Clean Code - 2 Solutions: Set and Sort | c-clean-code-2-solutions-set-and-sort-by-ko2c | Set - O(N) time, O(N) space\nWe can use a set to count all unique kinds of candies, but even all candies are unique, the sister cannot get more than half.\n(Eve | alexander | NORMAL | 2017-05-07T03:04:45.684000+00:00 | 2018-10-02T04:06:17.748514+00:00 | 7,075 | false | **Set - O(N) time, O(N) space**\nWe can use a set to count all unique kinds of candies, but even all candies are unique, the sister cannot get more than half.\n(Even though in reality my GF would always get more than half.)\n```\nclass Solution {\npublic:\n int distributeCandies(vector<int>& candies) {\n unor... | 29 | 1 | [] | 6 |
distribute-candies | [Java] 3 codes. Beats 100% | java-3-codes-beats-100-by-shk10-iuh5 | Solution is to choose as many unique candy types as we can without exceeding the hard limit of n / 2 so the problem reduces to counting how many distinct candy | shk10 | NORMAL | 2021-03-01T09:08:39.606126+00:00 | 2021-03-01T09:08:39.606164+00:00 | 2,802 | false | Solution is to choose as many unique candy types as we can without exceeding the hard limit of n / 2 so the problem reduces to counting how many distinct candy types are there.\n\n**Approach 1: HashSet**\nMost obvious and versatile choice for our use case is to use a HashSet.\n\n```\n// 33 ms. 62%\npublic int distribut... | 26 | 1 | ['Java'] | 3 |
distribute-candies | [Python] Oneliner, explained | python-oneliner-explained-by-dbabichev-4dny | Alice needs to eat exactly n//2 candies and the question is how many types she can eat. There are two restrictions we have here:\n\n1. len(Counter(candies)) is | dbabichev | NORMAL | 2021-03-01T08:31:27.925328+00:00 | 2021-03-01T08:31:27.925369+00:00 | 1,242 | false | Alice needs to eat exactly `n//2` candies and the question is how many types she can eat. There are two restrictions we have here:\n\n1. `len(Counter(candies))` is how many candies type we have at all, and we can not eat more than this number types of candies.\n2. `len(candies)//2` is exaclty how many candies Alice mus... | 18 | 5 | [] | 3 |
distribute-candies | C++ TWO-LINES-ONLY! SUPER Simple Solution | c-two-lines-only-super-simple-solution-b-jl8p | \nclass Solution {\npublic:\n int distributeCandies(vector<int>& candies) {\n int types_num = set<int>(candies.begin(), candies.end()).size();\n | yehudisk | NORMAL | 2021-03-01T08:22:09.166821+00:00 | 2021-03-01T08:22:09.168044+00:00 | 1,430 | false | ```\nclass Solution {\npublic:\n int distributeCandies(vector<int>& candies) {\n int types_num = set<int>(candies.begin(), candies.end()).size();\n return types_num > candies.size()/2 ? candies.size()/2 : types_num;\n }\n};\n```\n**LIKE IT? PLEASE UPVOTE...** | 15 | 7 | ['C'] | 1 |
distribute-candies | Python | Easy Solution✅ | python-easy-solution-by-gmanayath-b7x3 | \ndef distributeCandies(self, candyType: List[int]) -> int:\n # half length of candyType list\n candy_len = int(len(candyType)/2)\n # no of | gmanayath | NORMAL | 2022-08-09T14:36:20.943802+00:00 | 2022-12-22T16:51:14.269675+00:00 | 1,458 | false | ```\ndef distributeCandies(self, candyType: List[int]) -> int:\n # half length of candyType list\n candy_len = int(len(candyType)/2)\n # no of of unique candies \n unique_candy_len = len(set(candyType))\n return min(candy_len,unique_candy_len)\n``` | 10 | 0 | ['Python', 'Python3'] | 1 |
distribute-candies | [Java] 1-Liner using HashSet | java-1-liner-using-hashset-by-i18n-vu1d | \nclass Solution {\n public int distributeCandies(int[] candyType) {\n return Math.min(candyType.length / 2, Arrays.stream(candyType).boxed().collect( | i18n | NORMAL | 2021-03-01T12:55:09.205962+00:00 | 2021-03-01T12:55:09.206006+00:00 | 203 | false | ```\nclass Solution {\n public int distributeCandies(int[] candyType) {\n return Math.min(candyType.length / 2, Arrays.stream(candyType).boxed().collect(Collectors.toSet()).size());\n }\n}\n```\n\n`TC - O(n)`\n | 8 | 5 | [] | 0 |
distribute-candies | [C++/Java/Python] 1 Liner | cjavapython-1-liner-by-dnuang-4zdf | She cannot get more than half even if the all the candies are different.\n\nC++\n\nint distributeCandies(vector<int>& candies) {\n return min(candies.size() | dnuang | NORMAL | 2018-03-16T05:04:33.179007+00:00 | 2018-03-16T05:04:33.179007+00:00 | 722 | false | She **cannot get more than half** even if the all the candies are different.\n\nC++\n```\nint distributeCandies(vector<int>& candies) {\n return min(candies.size() / 2, unordered_set<int>(candies.begin(), candies.end()).size()); \n}\n```\n\nJava\n```\npublic int distributeCandies(int[] candies) {\n return Math.mi... | 8 | 0 | [] | 2 |
distribute-candies | 575: Time 92.8%, Solution with step by step explanation | 575-time-928-solution-with-step-by-step-otamc | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n1. Initialize a set to store unique candy types.\n2. Traverse through the | Marlen09 | NORMAL | 2023-03-15T05:34:11.523074+00:00 | 2023-03-15T05:34:11.523113+00:00 | 1,409 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n1. Initialize a set to store unique candy types.\n2. Traverse through the input array and add each candy type to the set.\n3. Find the length of the input array and divide it by 2 to get the maximum number of candies Alice c... | 7 | 0 | ['Array', 'Hash Table', 'Python', 'Python3'] | 0 |
distribute-candies | ✅ Easiest || 💯 Beats || ⭐ Java || ✨ Sweet Strategy | easiest-beats-java-sweet-strategy-by-muk-3m31 | \n\n# Intuition\n Describe your first thoughts on how to solve this problem. \nThe problem is asking to maximize the number of different candy types Alice can e | mukund_rakholiya | NORMAL | 2024-09-20T14:31:53.572594+00:00 | 2024-09-20T14:31:53.572632+00:00 | 1,434 | false | ```\n```\n# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n**The problem is asking to maximize the number of different candy types Alice can eat, while still following the doctor\'s rule of only eating half of the candies. This suggests that we need to track the number of unique candy t... | 6 | 0 | ['Array', 'Hash Table', 'Java'] | 3 |
distribute-candies | Easy to solve without set & beginner friendly. | easy-to-solve-without-set-beginner-frien-fgxe | Intuition\n Describe your first thoughts on how to solve this problem. \nThe problem is about distributing candies to ensure the maximum number of unique candy | ShivaanjayNarula | NORMAL | 2024-06-30T00:35:02.898471+00:00 | 2024-06-30T00:35:02.898494+00:00 | 598 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe problem is about distributing candies to ensure the maximum number of unique candy types one person can receive, given that there are n candies and the maximum each person can get is n/2 candies.\n# Approach\n<!-- Describe your approa... | 6 | 0 | ['Array', 'Hash Table', 'C++'] | 1 |
distribute-candies | 🔥🔥🔥🔥🔥 Beat 99% 🔥🔥🔥🔥🔥 EASY 🔥🔥🔥🔥🔥🔥 | beat-99-easy-by-abdallaellaithy-vk28 | \n\n\n# Code\n\nclass Solution(object):\n def distributeCandies(self, candyType):\n """\n :type candyType: List[int]\n :rtype: int\n | abdallaellaithy | NORMAL | 2024-02-29T10:47:27.295081+00:00 | 2024-03-16T15:09:27.522728+00:00 | 907 | false | \n\n\n# Code\n```\nclass Solution(object):\n def distributeCandies(self, candyType):\n """\n :type candyType: List[int]\n :rtype: int\n """\n ret... | 6 | 0 | ['Python', 'Python3'] | 1 |
distribute-candies | Easy unordered_set solution | | O(n) time complexity | easy-unordered_set-solution-on-time-comp-qw17 | \n# Approach\n Describe your approach to solving the problem. \nStore elements of given vector in an unordered_set. Since the unordered_set stores only unique e | suhani_29 | NORMAL | 2023-04-27T07:24:53.766708+00:00 | 2023-05-09T13:09:30.515841+00:00 | 911 | false | \n# Approach\n<!-- Describe your approach to solving the problem. -->\nStore elements of given vector in an unordered_set. Since the unordered_set stores only unique elements the occurence of each element will be 1 only.\nNow we know she can eat only n/2 candies of different types so if the number of distinct elements ... | 6 | 0 | ['C++'] | 1 |
distribute-candies | HashSet easy solution | hashset-easy-solution-by-priyankan_23-1vkf | \nclass Solution {\n public int distributeCandies(int[] candyType) {\n HashSet<Integer> set=new HashSet<>();\n for(int num : candyType )set.add | priyankan_23 | NORMAL | 2022-09-13T18:30:41.045978+00:00 | 2022-09-13T18:30:41.046023+00:00 | 794 | false | ```\nclass Solution {\n public int distributeCandies(int[] candyType) {\n HashSet<Integer> set=new HashSet<>();\n for(int num : candyType )set.add(num);\n return set.size()>=(candyType.length/2)?candyType.length/2:set.size();\n }\n}\n``` | 6 | 0 | ['Java'] | 0 |
distribute-candies | JS, Python, Java, C++ | Set Solution w/ Explanation | js-python-java-c-set-solution-w-explanat-xmpl | (Note: This is part of a series of Leetcode solution explanations. If you like this solution or find it useful, please upvote this post.)\n\n---\n\n#### Idea:\n | sgallivan | NORMAL | 2021-03-01T09:01:24.202814+00:00 | 2021-03-01T09:01:24.202856+00:00 | 529 | false | *(Note: This is part of a series of Leetcode solution explanations. If you like this solution or find it useful,* ***please upvote*** *this post.)*\n\n---\n\n#### ***Idea:***\n\nIn order to solve this problem, we need to identify how many unique types of candy there are. The easiest method to find unique values is with... | 6 | 3 | ['C', 'Python', 'Java', 'JavaScript'] | 0 |
distribute-candies | Python One-Liner Simple Solution | python-one-liner-simple-solution-by-yehu-vov2 | \nclass Solution:\n def distributeCandies(self, candies: List[int]) -> int:\n return min(len(candyType)//2, len(set(candyType)))\n\nLike it? please up | yehudisk | NORMAL | 2021-03-01T08:23:34.581722+00:00 | 2021-03-01T12:07:25.704766+00:00 | 475 | false | ```\nclass Solution:\n def distributeCandies(self, candies: List[int]) -> int:\n return min(len(candyType)//2, len(set(candyType)))\n```\n**Like it? please upvote...** | 6 | 0 | ['Python'] | 0 |
distribute-candies | C++ solution 98% faster time and 96% lesser space Distribute Candies | c-solution-98-faster-time-and-96-lesser-8yxbo | ```\nint distributeCandies(vector& candyType) {\n bitset<200001> bit(0);//200001 covers the range (10^-5 , 10^5)\n int n = candyType.size();\n | grey__c__ | NORMAL | 2021-01-31T18:06:52.275286+00:00 | 2021-01-31T18:06:52.275311+00:00 | 522 | false | ```\nint distributeCandies(vector<int>& candyType) {\n bitset<200001> bit(0);//200001 covers the range (10^-5 , 10^5)\n int n = candyType.size();\n for(int i=0;i<n;++i)bit.set(candyType[i]+100000);\n n/=2;\n int count = bit.count();\n return min(n,count);\n } | 6 | 0 | [] | 3 |
distribute-candies | C++ 2-line super-simple solution | c-2-line-super-simple-solution-by-yehudi-w5u9 | \nclass Solution {\npublic:\n int distributeCandies(vector<int>& candies) {\n int types_num = set<int>(candies.begin(), candies.end()).size();\n | yehudisk | NORMAL | 2020-08-18T22:13:16.646686+00:00 | 2020-08-18T22:13:16.646721+00:00 | 743 | false | ```\nclass Solution {\npublic:\n int distributeCandies(vector<int>& candies) {\n int types_num = set<int>(candies.begin(), candies.end()).size();\n return types_num > candies.size()/2 ? candies.size()/2 : types_num;\n }\n};\n``` | 6 | 0 | ['C', 'C++'] | 0 |
distribute-candies | JAVA Easy 2 Solutions 🔥100% Faster Code 🔥Beginner Friendly🔥 | java-easy-2-solutions-100-faster-code-be-axng | Please UPVOTE if helps!\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 your space comple | diyordev | NORMAL | 2023-12-06T10:22:55.534373+00:00 | 2023-12-06T10:22:55.534409+00:00 | 702 | false | # Please UPVOTE if helps!\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 your space complexity here, e.g. $$O(n)$$ -->\n\n# First Solution\n```\nclass Solution {\n public int distributeCandies(int[] candyType) {\n b... | 5 | 0 | ['Java'] | 1 |
distribute-candies | 3 Line Java Solution | 3-line-java-solution-by-im_bug-jaiy | \n public int distributeCandies(int[] candyType) {\n int n = candyType.length;\n Set set = new HashSet();\n for(int candy : candyType)\n | im_BUG | NORMAL | 2022-10-10T05:02:41.751310+00:00 | 2022-10-10T05:02:41.751343+00:00 | 817 | false | \n public int distributeCandies(int[] candyType) {\n int n = candyType.length;\n Set<Integer> set = new HashSet();\n for(int candy : candyType)\n set.add(candy);\n return Math.min(set.size(), n/2);\n }\n\t\t //plz !!! upvote | 5 | 0 | ['Ordered Set', 'Java'] | 1 |
distribute-candies | C++ Easy Solution | c-easy-solution-by-naman_151-9bbo | Hope this helps : )\n\nclass Solution {\npublic:\n int distributeCandies(vector<int>& candyType) {\n sort(candyType.begin(),candyType.end());\n | Naman_151 | NORMAL | 2022-06-30T18:30:24.858225+00:00 | 2022-06-30T18:30:24.858272+00:00 | 366 | false | Hope this helps : )\n```\nclass Solution {\npublic:\n int distributeCandies(vector<int>& candyType) {\n sort(candyType.begin(),candyType.end());\n int count = 1;\n for(int i = 0;i<candyType.size();i++){\n for(int j = i+1;j<candyType.size();j++){\n if(candyType[i]==candy... | 5 | 0 | ['C'] | 0 |
distribute-candies | Python 1-line | python-1-line-by-emoson-hcz8 | class Solution(object):\n\n def distributeCandies(self, candies):\n \treturn min(len(candies) / 2,len(set(candies))) | emoson | NORMAL | 2017-05-07T03:25:18.977000+00:00 | 2017-05-07T03:25:18.977000+00:00 | 1,392 | false | class Solution(object):\n\n def distributeCandies(self, candies):\n \treturn min(len(candies) / 2,len(set(candies))) | 5 | 0 | [] | 0 |
distribute-candies | Java solution beats 99.07% | java-solution-beats-9907-by-vegito2002-0fiw | Based on Bucket Sort:\n\n public int distributeCandies(int[] candies) {\n int[] b = new int[200001];\n int nonEmptyBucketNo = 0;\n for ( | vegito2002 | NORMAL | 2017-06-16T03:11:59.566000+00:00 | 2017-06-16T03:11:59.566000+00:00 | 1,340 | false | Based on Bucket Sort:\n<pre><code>\n public int distributeCandies(int[] candies) {\n int[] b = new int[200001];\n int nonEmptyBucketNo = 0;\n for (int i : candies) if (b[i + 100000]++ == 0) nonEmptyBucketNo++;\n return nonEmptyBucketNo <= candies.length / 2 ? nonEmptyBucketNo : candies.le... | 5 | 2 | [] | 1 |
distribute-candies | simple cpp solution | simple-cpp-solution-by-prithviraj26-9vdi | 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 | prithviraj26 | NORMAL | 2023-02-21T16:43:38.126969+00:00 | 2023-02-21T16:43:38.127011+00:00 | 556 | false | # 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)$$ --... | 4 | 0 | ['C++'] | 0 |
distribute-candies | Java One Liner Solution | java-one-liner-solution-by-janhvi__28-12g5 | 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 | Janhvi__28 | NORMAL | 2022-12-08T19:02:41.647176+00:00 | 2022-12-08T19:02:41.647216+00:00 | 1,160 | false | # 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 public int distributeCandies(int[] candyType) {\n Set<Integer> s = new HashSet<>();\n for (in... | 4 | 0 | ['Java'] | 0 |
distribute-candies | Rust solution | rust-solution-by-wddwycc-we40 | rust\nuse std::collections::HashSet;\n\nimpl Solution {\n pub fn distribute_candies(candy_type: Vec<i32>) -> i32 {\n let len = candy_type.len();\n | wddwycc | NORMAL | 2021-03-01T12:43:06.240652+00:00 | 2021-03-01T12:43:06.240691+00:00 | 89 | false | ```rust\nuse std::collections::HashSet;\n\nimpl Solution {\n pub fn distribute_candies(candy_type: Vec<i32>) -> i32 {\n let len = candy_type.len();\n let hashset: HashSet<i32> = candy_type.into_iter().collect();\n std::cmp::min(len / 2, hashset.len()) as i32\n }\n}\n``` | 4 | 1 | ['Rust'] | 1 |
distribute-candies | Python. One-liner Easy-understanding solution. | python-one-liner-easy-understanding-solu-i5bs | ```\nclass Solution:\n def distributeCandies(self, candyType: List[int]) -> int:\n return min(len(candyType) //2, len(set(candyType))) | m-d-f | NORMAL | 2021-03-01T11:40:50.277928+00:00 | 2021-03-01T11:40:50.277981+00:00 | 308 | false | ```\nclass Solution:\n def distributeCandies(self, candyType: List[int]) -> int:\n return min(len(candyType) //2, len(set(candyType))) | 4 | 2 | ['Python', 'Python3'] | 0 |
distribute-candies | Distribute Candies | JS, Python, Java, C++ | Set Solution w/ Explanation | distribute-candies-js-python-java-c-set-1zy5e | (Note: This is part of a series of Leetcode solution explanations. If you like this solution or find it useful, please upvote this post.)\n\n---\n\n#### Idea:\n | sgallivan | NORMAL | 2021-03-01T09:02:18.097443+00:00 | 2021-03-01T09:02:18.097477+00:00 | 189 | false | *(Note: This is part of a series of Leetcode solution explanations. If you like this solution or find it useful,* ***please upvote*** *this post.)*\n\n---\n\n#### ***Idea:***\n\nIn order to solve this problem, we need to identify how many unique types of candy there are. The easiest method to find unique values is with... | 4 | 1 | [] | 1 |
distribute-candies | Python one-liner simplest solution | python-one-liner-simplest-solution-by-ye-eu6z | \nclass Solution:\n def distributeCandies(self, candies: List[int]) -> int:\n return len(candies)//2 if len(set(candies)) > len(candies)//2 else len(s | yehudisk | NORMAL | 2020-08-19T12:46:03.771504+00:00 | 2020-08-19T12:46:03.771532+00:00 | 265 | false | ```\nclass Solution:\n def distributeCandies(self, candies: List[int]) -> int:\n return len(candies)//2 if len(set(candies)) > len(candies)//2 else len(set(candies))\n``` | 4 | 0 | ['Python3'] | 0 |
distribute-candies | 100% | 100% | Java | 4 Solution | Optimisations | 100-100-java-4-solution-optimisations-by-wx1c | Using Hash technique\n37 ms, faster than 83.75%\n\n\n\n/**\n * Important observation is that, if there are n types of candies then sister is more likely to have | nits2010 | NORMAL | 2019-08-24T14:12:31.132306+00:00 | 2019-08-24T14:12:31.132341+00:00 | 300 | false | Using Hash technique\n37 ms, faster than 83.75%\n\n```\n\n/**\n * Important observation is that, if there are n types of candies then sister is more likely to have n types of candies\n * 1. if; distribution of candies > types of candies -> sister will have all kind of candies for sure\n * 2. else distribution of candie... | 4 | 0 | [] | 0 |
distribute-candies | One line Python | one-line-python-by-yindaiying-8462 | \nclass Solution(object):\n def distributeCandies(self, candies):\n return min(len(candies)//2, len(set(candies)))\n | yindaiying | NORMAL | 2019-07-16T08:36:31.737930+00:00 | 2019-07-16T08:36:31.737962+00:00 | 380 | false | ```\nclass Solution(object):\n def distributeCandies(self, candies):\n return min(len(candies)//2, len(set(candies)))\n``` | 4 | 1 | [] | 0 |
distribute-candies | Java hashset solution | java-hashset-solution-by-earlme-r7ea | public int distributeCandies(int[] candies) {\n Set<Integer> set = new HashSet<>();\n for(Integer candie : candies) {\n set.add(candie) | earlme | NORMAL | 2017-05-07T03:03:17.812000+00:00 | 2017-05-07T03:03:17.812000+00:00 | 1,678 | false | public int distributeCandies(int[] candies) {\n Set<Integer> set = new HashSet<>();\n for(Integer candie : candies) {\n set.add(candie);\n if(set.size() == candies.length/2) return set.size();\n }\n return Math.min(set.size(), candies.length/2);\n } | 4 | 2 | [] | 2 |
distribute-candies | Java 8 one line solution O(n) | java-8-one-line-solution-on-by-lxyjscz-09h6 | ```\npublic class Solution {\n public int distributeCandies(int[] candies) {\n return Math.min(candies.length / 2, IntStream.of(candies).boxed().colle | lxyjscz | NORMAL | 2017-05-07T19:14:54.373000+00:00 | 2017-05-07T19:14:54.373000+00:00 | 2,743 | false | ```\npublic class Solution {\n public int distributeCandies(int[] candies) {\n return Math.min(candies.length / 2, IntStream.of(candies).boxed().collect(Collectors.toSet()).size());\n }\n}\n```` | 4 | 1 | [] | 1 |
distribute-candies | 1-liner Java and Python | 1-liner-java-and-python-by-jianchao-li-sttl | Given n (even) candies, the sister can at most get n / 2 of them (distributed evenly). And if there are k kinds, k is also the upper bound of the number of kind | jianchao-li | NORMAL | 2017-11-22T14:07:04.698000+00:00 | 2017-11-22T14:07:04.698000+00:00 | 577 | false | Given `n` (even) candies, the sister can at most get `n / 2` of them (distributed evenly). And if there are `k` kinds, `k` is also the upper bound of the number of kinds the sister can get.\n\n`n / 2` is simply `candies.length / 2`. To compute `k`, a traditional way is to use a hash map to count occurrences. And a shor... | 4 | 0 | [] | 2 |
distribute-candies | C++✅ || Beats 65%💯|| 6 Lines Code💀💯|| EasyPizyy🔥💯 | c-beats-65-6-lines-code-easypizyy-by-yas-64mj | 🍬 IntuitionThe goal is to maximize the number of unique candy types the sister can eat while ensuring she only eats half of the total candies. 🎯🛠️ Approach
🏷️ U | yashm01 | NORMAL | 2025-02-15T14:43:15.078082+00:00 | 2025-02-15T14:43:15.078082+00:00 | 197 | false | 
# 🍬 Intuition
The goal is to **maximize the number of unique candy types** the sister can eat while ensuring she only eats **half** of the total candies. 🎯
# 🛠️ Approach
1... | 3 | 0 | ['Array', 'Hash Table', 'C++'] | 0 |
distribute-candies | simple and easy C++ solution 😍❤️🔥 | simple-and-easy-c-solution-by-shishirrsi-kbqg | if it\'s help, please up \u2B06 vote! \u2764\uFE0F\n\n\n# Code\n\nclass Solution {\npublic:\n int distributeCandies(vector<int>& nums) \n {\n set<i | shishirRsiam | NORMAL | 2024-05-20T18:27:18.892979+00:00 | 2024-05-20T18:27:18.893007+00:00 | 499 | false | # if it\'s help, please up \u2B06 vote! \u2764\uFE0F\n\n\n# Code\n```\nclass Solution {\npublic:\n int distributeCandies(vector<int>& nums) \n {\n set<int>st;\n for(int val:nums) st.insert(val);\n return min(nums.size()/2, st.size());\n }\n};\n``` | 3 | 0 | ['Array', 'Math', 'C++'] | 3 |
distribute-candies | Simple O(n) solution | simple-on-solution-by-sharmanishchay-iouq | Intuition\n Describe your first thoughts on how to solve this problem. \n- HashSet Usage: By utilizing a HashSet, the code efficiently keeps track of the unique | sharmanishchay | NORMAL | 2024-02-14T13:05:20.970146+00:00 | 2024-02-14T13:05:20.970174+00:00 | 57 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n- HashSet Usage: By utilizing a HashSet, the code efficiently keeps track of the unique types of candies. A HashSet ensures that only unique elements are stored, which is perfect for this scenario as we are interested in counting the diff... | 3 | 0 | ['Hash Table', 'Java'] | 0 |
distribute-candies | Easy Solution in C++, Time complexity: O(N) | easy-solution-in-c-time-complexity-on-by-mkxx | Complexity\n- Time complexity:\nO(N)\n\n- Space complexity:\nO(N)\n\n# Code\n\nclass Solution {\npublic:\n int distributeCandies(vector<int>& candyType) \n | ashiquranik | NORMAL | 2023-08-27T10:20:14.440556+00:00 | 2023-08-27T10:54:20.770902+00:00 | 280 | false | # Complexity\n- Time complexity:\nO(N)\n\n- Space complexity:\nO(N)\n\n# Code\n```\nclass Solution {\npublic:\n int distributeCandies(vector<int>& candyType) \n {\n map<int,int>m;\n for(int i=0;i<candyType.size();i++)\n {\n m[candyType[i]]++;\n }\n int eat = candyType... | 3 | 0 | ['C++'] | 0 |
distribute-candies | C# one line | c-one-line-by-maxim_kurbanov-simb | Code\n\npublic class Solution \n{\n public int DistributeCandies(int[] candyType) \n {\n return Math.Min(candyType.ToHashSet().Count, candyType.Len | Maxim_Kurbanov | NORMAL | 2023-05-17T18:50:52.529609+00:00 | 2023-05-17T18:50:52.529644+00:00 | 72 | false | # Code\n```\npublic class Solution \n{\n public int DistributeCandies(int[] candyType) \n {\n return Math.Min(candyType.ToHashSet().Count, candyType.Length / 2);\n }\n}\n``` | 3 | 0 | ['C#'] | 0 |
distribute-candies | ✔Beats 100% TC || Simple if else || Easily Understandable Python Solution | beats-100-tc-simple-if-else-easily-under-12zc | Approach\n - Converts the array candyType to a set which gonna contain only discrete values\n - if eat <= len(dis_candyType) it means there are enough options a | Gourav_Sinha | NORMAL | 2023-04-28T15:02:56.605288+00:00 | 2023-04-28T15:14:19.800946+00:00 | 832 | false | # Approach\n - Converts the array ```candyType``` to a set which gonna contain only discrete values\n - if ```eat <= len(dis_candyType)``` it means there are enough options available (i.e. Here every candy Alice eats is of different type)\n - elif ```eat > len(dis_candyType)``` not enough options available \n (i.e. Her... | 3 | 0 | ['Python', 'Python3'] | 0 |
distribute-candies | Python 3-lines ✅✅✅ || Faster than 98.93% || Simple + Explained | python-3-lines-faster-than-9893-simple-e-1wzp | Note: In the tags, I put Ordered Set there but the set doesn\'t actually have any order.\n## Please \uD83D\uDC4D\uD83C\uDFFB\uD83D\uDC4D\uD83C\uDFFB\uD83D\uDC4D | a-fr0stbite | NORMAL | 2022-12-25T00:57:46.175171+00:00 | 2022-12-25T01:04:57.568674+00:00 | 890 | false | **Note:** In the tags, I put Ordered Set there but the set doesn\'t actually have any order.\n## Please \uD83D\uDC4D\uD83C\uDFFB\uD83D\uDC4D\uD83C\uDFFB\uD83D\uDC4D\uD83C\uDFFB\uD83D\uDC4D\uD83C\uDFFB\uD83D\uDC4D\uD83C\uDFFB\uD83D\uDC4D\uD83C\uDFFB if u like!!\n# Code\n```\nclass Solution:\n def distributeCandies(se... | 3 | 0 | ['Array', 'Ordered Set', 'Python', 'Python3'] | 0 |
distribute-candies | Java Solution using HashMap | java-solution-using-hashmap-by-akash_200-4stk | If the solution is helpful please upvote this.\n\n\nclass Solution {\n public int distributeCandies(int[] candyType) {\n \n HashMap<Integer, In | Akash_2000 | NORMAL | 2022-10-17T16:53:45.295280+00:00 | 2022-10-17T16:53:45.295323+00:00 | 692 | false | If the solution is helpful please upvote this.\n\n```\nclass Solution {\n public int distributeCandies(int[] candyType) {\n \n HashMap<Integer, Integer> map = new HashMap<>();\n \n for(int i = 0; i<candyType.length; i++)\n {\n map.put(candyType[i], map.getOrDefault(candy... | 3 | 0 | ['Java'] | 0 |
distribute-candies | Java easy solution | java-easy-solution-by-anchaljain_04-rflg | \tclass Solution {\n\t\tpublic int distributeCandies(int[] candyType) {\n\t\t\tHashSeths=new HashSet<>();\n\t\t\tfor(int i:candyType)\n\t\t\t\ths.add(i);\n\t\t\ | anchaljain_04 | NORMAL | 2022-10-06T12:48:22.938671+00:00 | 2022-10-06T12:48:22.938740+00:00 | 343 | false | \tclass Solution {\n\t\tpublic int distributeCandies(int[] candyType) {\n\t\t\tHashSet<Integer>hs=new HashSet<>();\n\t\t\tfor(int i:candyType)\n\t\t\t\ths.add(i);\n\t\t\tint r=candyType.length/2;\n\t\t\tif(hs.size()<r)\n\t\t\t return hs.size();\n\t\t\telse\n\t\t\t\treturn r;\n\t\t}\n\t} | 3 | 0 | [] | 0 |
distribute-candies | C++ BEGINNERS FRNDLY SOLn | c-beginners-frndly-soln-by-geek_monk-d90a | \nclass Solution {\npublic:\n int distributeCandies(vector<int>& a) {\n unordered_set<int> s; // declaration of set\n for(int i=0;i<a.si | geek_monk | NORMAL | 2022-04-14T07:24:09.801672+00:00 | 2022-04-14T07:24:09.801703+00:00 | 146 | false | ```\nclass Solution {\npublic:\n int distributeCandies(vector<int>& a) {\n unordered_set<int> s; // declaration of set\n for(int i=0;i<a.size();i++)\n s.insert(a[i]); // insertion in set\n \n int x=min(s.size(),a.size()/2); // finding minimum ... | 3 | 0 | ['Ordered Set'] | 0 |
distribute-candies | Simple C++ Solution || Runtime faster than 79.79% || Memory Usage less than 62.37% | simple-c-solution-runtime-faster-than-79-zjmw | \nclass Solution {\npublic:\n int distributeCandies(vector<int>& candyType) {\n unordered_set<int> s;\n int n = candyType.size();\n for( | Arbind007 | NORMAL | 2021-11-27T11:43:50.509270+00:00 | 2021-11-27T11:43:57.105205+00:00 | 677 | false | ```\nclass Solution {\npublic:\n int distributeCandies(vector<int>& candyType) {\n unordered_set<int> s;\n int n = candyType.size();\n for(int i=0;i<n;i++){\n s.insert(candyType[i]);\n }\n if(n/2 < s.size()){\n return n/2;\n }\n return s.size();\... | 3 | 0 | ['C', 'Ordered Set', 'C++'] | 0 |
distribute-candies | JavaScript One-Liner | javascript-one-liner-by-control_the_narr-5ka2 | javascript\nvar distributeCandies = function(candyType) {\n return Math.min(candyType.length/2, new Set(candyType).size)\n};\n | control_the_narrative | NORMAL | 2021-03-01T13:36:36.686247+00:00 | 2021-03-01T13:36:36.686285+00:00 | 294 | false | ```javascript\nvar distributeCandies = function(candyType) {\n return Math.min(candyType.length/2, new Set(candyType).size)\n};\n``` | 3 | 0 | ['JavaScript'] | 1 |
distribute-candies | JS One-liner Easy-understanding solution | js-one-liner-easy-understanding-solution-17e3 | ```\nvar distributeCandies = function(candyType) {\n return Math.min(candyType.length / 2, new Set(candyType).size);\n}; | m-d-f | NORMAL | 2021-03-01T11:59:06.268569+00:00 | 2021-03-01T11:59:06.268611+00:00 | 150 | false | ```\nvar distributeCandies = function(candyType) {\n return Math.min(candyType.length / 2, new Set(candyType).size);\n}; | 3 | 1 | ['JavaScript'] | 0 |
distribute-candies | [Python 3] Easy, fast, no Set(), O(n) | python-3-easy-fast-no-set-on-by-dpustova-20ki | To eat the maximum number of different types, Alice needs to eat the minimum number of every type. In other words she eats all types (by one candy) or a half of | dpustovarov | NORMAL | 2021-03-01T10:15:11.223687+00:00 | 2021-03-01T10:22:35.152334+00:00 | 172 | false | - To eat the maximum number of different types, Alice needs to eat the minimum number of every type. In other words she eats all types (by one candy) or a half of total number of candies. \n- Use set to control uniqueness. Set syntax `{*...}` is faster than set function `set(...)`.\n- Time complexity is `O(n)`. Space ... | 3 | 1 | ['Ordered Set', 'Python'] | 0 |
distribute-candies | Distribute Candies | C++ using set | distribute-candies-c-using-set-by-sekhar-l4pe | Find unique candies by using a set\n2. Return min of (unique candies(size of set) and half the no of candies)\n\nclass Solution {\npublic:\n int distributeCa | sekhar179 | NORMAL | 2021-03-01T09:17:44.468738+00:00 | 2021-03-01T09:17:44.468801+00:00 | 178 | false | 1. Find unique candies by using a set\n2. Return min of (unique candies(size of set) and half the no of candies)\n```\nclass Solution {\npublic:\n int distributeCandies(vector<int>& candies) {\n set<int> st;\n for (auto candie: candies)\n st.insert(candie);\n return min(st.size(), can... | 3 | 1 | ['C'] | 0 |
distribute-candies | python 3 || one liner | python-3-one-liner-by-adarshbiradar-95e7 | ```\nclass Solution:\n def distributeCandies(self, candies: List[int]) -> int:\n return min(len(set(candies)),len(candies)//2) | adarshbiradar | NORMAL | 2020-07-20T09:23:02.604654+00:00 | 2020-07-20T09:24:19.127524+00:00 | 205 | false | ```\nclass Solution:\n def distributeCandies(self, candies: List[int]) -> int:\n return min(len(set(candies)),len(candies)//2) | 3 | 1 | ['Ordered Set', 'Python3'] | 0 |
distribute-candies | ⭐️ [ Javascript / Python3 / C++ ] 🎯 1-Liners | javascript-python3-c-1-liners-by-clayton-9u9g | Synopsis:\n\nSimply return the minimum of unique candies and half the length of A. This conclusion was derived from the following 2 use cases:\n\n Case 1: if l | claytonjwong | NORMAL | 2020-06-03T23:46:32.321703+00:00 | 2020-10-05T14:17:11.933160+00:00 | 110 | false | **Synopsis:**\n\nSimply return the minimum of unique candies and half the length of `A`. This conclusion was derived from the following 2 use cases:\n\n* **Case 1:** if less than half of the candies are unique, then give all those unique candies to the sister\n* **Case 2:** if more than half of the candies are unique,... | 3 | 0 | [] | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.