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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
number-of-arithmetic-triplets | ✅ A generic Dynamic Programming (A[i] - diff) || [Intuition Updated] | a-generic-dynamic-programming-ai-diff-in-y2fl | This Approach even works if the array is unsorted or elements are negative or diff is negative\n\nSimilar to 300. Longest Increasing Subsequence.\nWe simply sav | xxvvpp | NORMAL | 2022-08-07T04:15:10.106293+00:00 | 2022-08-07T09:09:42.671871+00:00 | 2,919 | false | **This Approach even works if the array is unsorted or elements are negative or diff is negative**\n\n**Similar to [300. Longest Increasing Subsequence](https://leetcode.com/problems/longest-increasing-subsequence/).**\nWe simply save the value for every we have seen till now in a array and our count will be `cnt[A[i]]... | 23 | 2 | ['Dynamic Programming', 'C'] | 1 |
number-of-arithmetic-triplets | BRUTE FORCE 3 LOOP's && Optimized O(N) | brute-force-3-loops-optimized-on-by-up15-as5k | Contest Submission\n\nclass Solution {\npublic:\n int arithmeticTriplets(vector<int>& nums, int diff) {\n int ans=0;\n for(int i=0;i<nums.size( | up1512001 | NORMAL | 2022-08-07T04:02:53.017214+00:00 | 2022-08-08T13:06:29.695911+00:00 | 3,699 | false | **Contest Submission**\n```\nclass Solution {\npublic:\n int arithmeticTriplets(vector<int>& nums, int diff) {\n int ans=0;\n for(int i=0;i<nums.size();i++){\n for(int j=i+1;j<nums.size();j++){\n for(int k=j+1;k<nums.size();k++){\n if((nums[j]-nums[i])==diff... | 20 | 0 | ['C', 'C++'] | 1 |
number-of-arithmetic-triplets | Java / C++ Brute Force to Set | java-c-brute-force-to-set-by-fllght-mwgi | The brute force method is pretty fast here, but using a set is preferable\n\n### Java Brute Force\njava\npublic int arithmeticTriplets(int[] nums, int diff) {\n | FLlGHT | NORMAL | 2022-08-07T06:07:06.808460+00:00 | 2022-08-07T07:27:36.949896+00:00 | 1,809 | false | The brute force method is pretty fast here, but using a set is preferable\n\n### Java Brute Force\n```java\npublic int arithmeticTriplets(int[] nums, int diff) {\n int count = 0;\n\n for (int i = 0; i < nums.length - 2; i++) {\n for (int j = i + 1; j < nums.length - 1; j++) {\n f... | 16 | 0 | ['C', 'Ordered Set', 'Java'] | 3 |
number-of-arithmetic-triplets | easy hashmap solution and got 54ms ✅ | easy-hashmap-solution-and-got-54ms-by-mj-xnn4 | \nvar arithmeticTriplets = function(nums, diff) {\n \n let hash = new Map();\n let count = 0;\n\n for(let i=0; i<nums.length; i++){\n let tem | MJWHY | NORMAL | 2022-08-18T00:11:46.230923+00:00 | 2022-08-18T17:17:04.109785+00:00 | 1,179 | false | ```\nvar arithmeticTriplets = function(nums, diff) {\n \n let hash = new Map();\n let count = 0;\n\n for(let i=0; i<nums.length; i++){\n let temp = nums[i] - diff;\n \n if(hash.has(temp) && hash.has(temp - diff)){\n count++;\n }\n hash.set(nums[i] , "Hard choice... | 14 | 0 | ['JavaScript'] | 2 |
number-of-arithmetic-triplets | ✔ C++ using Map with Explanation || Very Easy and Simple to understand Solution | c-using-map-with-explanation-very-easy-a-4x19 | Up Vote if you like the solution\n# Check for the nums[i] -diff and nums[i] - 2*diff, if these are present in the map or not. If present count a triplet. Then | kreakEmp | NORMAL | 2022-08-07T04:01:32.339003+00:00 | 2022-08-07T05:18:24.991141+00:00 | 2,122 | false | <b> Up Vote if you like the solution\n# Check for the nums[i] -diff and nums[i] - 2*diff, if these are present in the map or not. If present count a triplet. Then strore the current number in map for future use.\n```\nclass Solution {\npublic:\n int arithmeticTriplets(vector<int>& nums, int diff) {\n unordere... | 14 | 0 | [] | 0 |
number-of-arithmetic-triplets | Python | Easy Solution✅ | python-easy-solution-by-gmanayath-777z | \ndef arithmeticTriplets(self, nums: List[int], diff: int) -> int:\n ans = 0\n for i in range(len(nums)): # nums = [0,1,4,6,7,10], diff = 3\n | gmanayath | NORMAL | 2022-08-12T15:45:44.309663+00:00 | 2022-12-22T16:50:28.013817+00:00 | 1,712 | false | ```\ndef arithmeticTriplets(self, nums: List[int], diff: int) -> int:\n ans = 0\n for i in range(len(nums)): # nums = [0,1,4,6,7,10], diff = 3\n j = nums[i] - diff # 4 - 3 = 1 (when i ==2)\n k = diff + nums[i] # 3 + 4 = 7 (when i ==2)\n if j in nums and k in nums: # 1 ... | 13 | 0 | ['Python', 'Python3'] | 4 |
number-of-arithmetic-triplets | ✅Easy Java solution||Straight Forward||Beginner Friendly🔥 | easy-java-solutionstraight-forwardbeginn-qfyc | If you really found my solution helpful please upvote it, as it motivates me to post such kind of codes and help the coding community, if you have some queries | deepVashisth | NORMAL | 2022-09-30T19:21:27.691409+00:00 | 2022-09-30T19:21:27.691448+00:00 | 1,081 | false | **If you really found my solution helpful please upvote it, as it motivates me to post such kind of codes and help the coding community, if you have some queries or some improvements please feel free to comment and share your views.**\n```\nclass Solution {\n public int arithmeticTriplets(int[] nums, int diff) {\n ... | 11 | 0 | ['Java'] | 2 |
number-of-arithmetic-triplets | ( Beats 99%)3 Java Solution | Binary Search | Map | 3 Pointers | beats-993-java-solution-binary-search-ma-z9ot | 3 Different JAVA Solutions \n\nSolution Using Binary Search (Time Complexity : O(nlog(n)) , Space Complexity : O(1))\n\nclass Solution {\n public static bool | Aman__Bhardwaj | NORMAL | 2022-09-08T17:19:27.645130+00:00 | 2022-09-08T17:19:27.645171+00:00 | 740 | false | # 3 Different JAVA Solutions \n\n**Solution Using Binary Search (Time Complexity : O(nlog(n)) , Space Complexity : O(1))**\n```\nclass Solution {\n public static boolean BinarySearch(int[] arr, int key){\n int low = 0 , high = arr.length-1;\n while(low <= high){\n int mid = low + (high-low)/... | 10 | 0 | ['Binary Tree', 'Java'] | 1 |
number-of-arithmetic-triplets | ✅ Easy Python Solution||Binary Search Solution | easy-python-solutionbinary-search-soluti-zrt1 | Intution:-\n PLEASE UPVOTE\uD83D\uDC4D\uD83D\uDC4D IF YOU LIKE THE SOLUTION\n## Binary Search\nUse binary search to find out if nums[i]+diff and nums[i]+2diff i | amandgp | NORMAL | 2023-03-26T13:41:24.646179+00:00 | 2023-03-26T13:41:24.646222+00:00 | 506 | false | # Intution:-\n **PLEASE UPVOTE\uD83D\uDC4D\uD83D\uDC4D IF YOU LIKE THE SOLUTION**\n## Binary Search\nUse binary search to find out if nums[i]+diff and nums[i]+2*diff is present in array or not if both are present in array increment the count by 1 if any one of them is not present in array continue:\n<!-- Describe your ... | 8 | 0 | ['Array', 'Two Pointers', 'Binary Search', 'Enumeration', 'Python3'] | 0 |
number-of-arithmetic-triplets | C++|| Multiple Approach || Bruteforce to optimized || Easy Explanation | c-multiple-approach-bruteforce-to-optimi-hg87 | \n\t// Brute force \n\t// we will check condition for k only if nums[j]-nums[i]==diff\n\n\tclass Solution {\n\tpublic:\n\t\tint arithmeticTriplets(vector& nums, | anubhavsingh11 | NORMAL | 2022-08-09T19:47:57.117384+00:00 | 2023-01-16T05:38:00.637389+00:00 | 969 | false | \n\t// Brute force \n\t// we will check condition for k only if nums[j]-nums[i]==diff\n\n\tclass Solution {\n\tpublic:\n\t\tint arithmeticTriplets(vector<int>& nums, int diff) {\n\t\t\tint ans=0;\n\t\t\tfor(int i=0;i<nums.size()-2;i++)\n\t\t\t{\n\t\t\t\tfor(int j=i+1;j<nums.size()-1;j++)\n\t\t\t\t{\n\t\t\t\t\tif(nums[j... | 8 | 0 | ['C', 'Ordered Set'] | 2 |
number-of-arithmetic-triplets | Python easy understand solution O(n) space, O(n) time | python-easy-understand-solution-on-space-dzdk | Use a set to memorize each interger is exist or not. \npython\nclass Solution:\n def arithmeticTriplets(self, nums: List[int], diff: int) -> int:\n s | amikai | NORMAL | 2022-08-07T13:49:28.493723+00:00 | 2022-08-07T14:45:40.890742+00:00 | 1,517 | false | Use a set to memorize each interger is exist or not. \n```python\nclass Solution:\n def arithmeticTriplets(self, nums: List[int], diff: int) -> int:\n s = set(nums)\n count = 0\n for num in nums:\n if (num + diff) in s and (num + diff + diff) in s:\n count += 1\n ... | 8 | 0 | ['Ordered Set', 'Python', 'Python3'] | 5 |
number-of-arithmetic-triplets | Java Easy solution using HashMap | java-easy-solution-using-hashmap-by-basi-kc53 | For each element check element + diff && element + 2 * diff exist in map.\n```\npublic int arithmeticTriplets(int[] nums, int diff) {\n HashMap map = new | basitimam | NORMAL | 2022-08-07T04:01:23.409876+00:00 | 2022-08-07T04:08:56.653024+00:00 | 963 | false | For each element check element + diff && element + 2 * diff exist in map.\n```\npublic int arithmeticTriplets(int[] nums, int diff) {\n HashMap<Integer, Integer> map = new HashMap<>();\n for(int i : nums){\n map.put(i, map.getOrDefault(i, 0) + 1);\n }\n int count = 0;\n for... | 7 | 0 | ['Java'] | 3 |
number-of-arithmetic-triplets | Two (Three) Pointers. Beates 100 % | two-three-pointers-beates-100-by-sberik-gq2s | Approach\nThe main idea of the code is to use three pointers to search for arithmetic triplets in thenumsarray, where the difference between adjacent elements i | SBerik | NORMAL | 2023-10-31T04:53:08.569549+00:00 | 2023-10-31T05:03:58.697126+00:00 | 185 | false | # Approach\nThe main idea of the code is to use three pointers to search for arithmetic triplets in the`nums`array, where the difference between adjacent elements is equal to the given `diff`. The pointers `i`, `j`, and `k` move through the array.\n\n# Complexity\n- Time complexity: $$O(N)$$\n\n- Space complexity: $$O(... | 6 | 0 | ['Two Pointers', 'Java'] | 0 |
number-of-arithmetic-triplets | C++ || Unordered-map || Easy-to-Understand || no of arithmetic tripplet. | c-unordered-map-easy-to-understand-no-of-yuil | # Intuition \n\n\n\n\n\n\n\n\n\n\n\n\n# Code\n\nclass Solution {\npublic:\n int arithmeticTriplets(vector<int>& nums, int diff) {\n int n=nums.size( | m_isha_125 | NORMAL | 2022-11-10T20:55:26.502303+00:00 | 2022-11-10T20:55:26.502344+00:00 | 567 | 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... | 6 | 0 | ['Hash Table', 'C++'] | 0 |
number-of-arithmetic-triplets | Python O(n) Two Pointers Approach | python-on-two-pointers-approach-by-brent-e45q | We can take advantage of the fact that the array is already sorted to find arithmetic triples quickly.\nThe big idea is that if either nums[j] - nums[i] or nums | brent_pappas | NORMAL | 2022-10-08T15:05:42.229714+00:00 | 2022-10-08T15:05:42.229746+00:00 | 661 | false | We can take advantage of the fact that the array is already sorted to find arithmetic triples quickly.\nThe big idea is that if either `nums[j] - nums[i]` or `nums[k] - nums[j]` is not equal to diff, we increment the appropriate index.\n\n```\nclass Solution:\n def arithmeticTriplets(self, nums: List[int], diff: int... | 6 | 0 | ['Two Pointers', 'Python'] | 1 |
number-of-arithmetic-triplets | python 95% fast and 97% memory | python-95-fast-and-97-memory-by-tul-jo37 | \nclass Solution:\n def arithmeticTriplets(self, nums: List[int], diff: int) -> int:\n dic = {} # store nums[i]\n quest = {} # store require nu | TUL | NORMAL | 2022-08-29T04:52:21.911732+00:00 | 2022-08-29T04:52:21.911789+00:00 | 899 | false | ```\nclass Solution:\n def arithmeticTriplets(self, nums: List[int], diff: int) -> int:\n dic = {} # store nums[i]\n quest = {} # store require number you possible find after nums[i]\n count = 0 # count answer\n for i in nums:\n dic[i] = True \n if i in quest: count ... | 6 | 0 | ['Hash Table', 'Python', 'Python3'] | 1 |
number-of-arithmetic-triplets | ✅SIMPLE AND EASY C++ SOLUTION USING HASHMAP | simple-and-easy-c-solution-using-hashmap-uq8n | Time Complexity: O(n)\n\nCode:\n\nclass Solution {\npublic:\n int arithmeticTriplets(vector<int>& nums, int diff) {\n int count=0;\n unordered_ | ke4e | NORMAL | 2022-08-21T07:08:20.426713+00:00 | 2022-08-21T07:08:20.426759+00:00 | 458 | false | Time Complexity: O(n)\n\nCode:\n```\nclass Solution {\npublic:\n int arithmeticTriplets(vector<int>& nums, int diff) {\n int count=0;\n unordered_map<int, bool> data;\n for (int num:nums)\n data[num]=true;\n \n for (int num: nums)\n if (data[num-diff] && data[... | 6 | 0 | ['C'] | 0 |
number-of-arithmetic-triplets | Common Difference A.P||C++ | common-difference-apc-by-priyanshu3237-obvv | class Solution {\npublic:\n int arithmeticTriplets(vector& nums, int diff) {\n int ans = 0;\n for(int j = 1;j=0 && k<nums.size()){\n | priyanshu3237 | NORMAL | 2022-08-07T04:06:04.059362+00:00 | 2022-08-07T06:49:19.591583+00:00 | 526 | false | class Solution {\npublic:\n int arithmeticTriplets(vector<int>& nums, int diff) {\n int ans = 0;\n for(int j = 1;j<nums.size()-1;j++){\n int i = j-1, k = j+1;\n \n while(i>=0 && k<nums.size()){\n \n if(nums[j]-nums[i] == diff && nums[k]-nu... | 6 | 0 | [] | 2 |
number-of-arithmetic-triplets | JAVA || 10000% beats ❤️ || 3 Solution || HashSet || ArrayList || ❤️ | java-10000-beats-3-solution-hashset-arra-06tc | 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 | saurabh_kumar1 | NORMAL | 2023-08-30T16:22:01.360415+00:00 | 2023-08-30T16:22:01.360434+00:00 | 653 | 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:0(N)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:0(1)\n<!-- Add your space complexity here, e.g. $$O... | 5 | 0 | ['Array', 'Hash Table', 'C++', 'Java'] | 1 |
number-of-arithmetic-triplets | my_arithmeticTriplets | my_arithmetictriplets-by-rinatmambetov-4ww3 | # Intuition \n\n\n\n\n\n\n\n\n\n\n\n# Code\n\n/**\n * @param {number[]} nums\n * @param {number} diff\n * @return {number}\n */\nvar arithmeticTriplets = func | RinatMambetov | NORMAL | 2023-05-14T14:23:07.857122+00:00 | 2023-05-14T14:23:07.857163+00:00 | 881 | 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 spa... | 5 | 0 | ['JavaScript'] | 0 |
number-of-arithmetic-triplets | Two simple and fast Map and Array based solutions | two-simple-and-fast-map-and-array-based-wy2n2 | Approach\nEach number can have only one potenial triplet and the numbers should go in sequential order. So we just need to check that. If array we can check for | balfin | NORMAL | 2023-02-11T09:50:15.872915+00:00 | 2023-02-12T05:26:56.603744+00:00 | 804 | false | # Approach\nEach number can have only one potenial triplet and the numbers should go in sequential order. So we just need to check that. If array we can check forward values, if map we need to fill it with data and check backwards. Map solution is a bit slower per leetcode tests, looks like map.has is not that optimize... | 5 | 0 | ['JavaScript'] | 0 |
number-of-arithmetic-triplets | using binary_search | using-binary_search-by-bhupendraj9-9zev | \nclass Solution {\npublic:\n int arithmeticTriplets(vector<int>& nums, int diff) {\n int count=0;\n for(int i=0;i<nums.size();i++)\n {\n | bhupendraj9 | NORMAL | 2022-11-08T09:14:00.153022+00:00 | 2023-11-01T12:20:05.427694+00:00 | 438 | false | ```\nclass Solution {\npublic:\n int arithmeticTriplets(vector<int>& nums, int diff) {\n int count=0;\n for(int i=0;i<nums.size();i++)\n {\n if(binary_search(nums.begin(),nums.end(),nums[i]+diff) && binary_search(nums.begin(),nums.end(),nums[i]+2*diff))\n count++;\n ... | 5 | 0 | ['Binary Search', 'C++'] | 3 |
number-of-arithmetic-triplets | Swift One-Liner | Also: Optimized Alternates | swift-one-liner-also-optimized-alternate-weos | One-Liner (accepted answer)\n\nclass Solution {\n func arithmeticTriplets(_ nums: [Int], _ diff: Int) -> Int {\n nums.filter { nums.contains($0+diff) | UpvoteThisPls | NORMAL | 2022-08-08T23:19:36.474617+00:00 | 2022-08-08T23:19:36.474660+00:00 | 102 | false | **One-Liner (accepted answer)**\n```\nclass Solution {\n func arithmeticTriplets(_ nums: [Int], _ diff: Int) -> Int {\n nums.filter { nums.contains($0+diff) && nums.contains($0+diff*2) }.count\n }\n}\n```\n\n**Two-Liner, much faster approach (accepted answer)**\n```\nclass Solution {\n func arithmeticTr... | 5 | 0 | [] | 1 |
number-of-arithmetic-triplets | Python easy solution for beginners using slightly optimized brute force | python-easy-solution-for-beginners-using-ova9 | This solution is slightly better than pure brute force as it calls the 3rd loop only if a condition is met.\n\n```\nclass Solution:\n def arithmeticTriplets( | elefant1805 | NORMAL | 2022-08-07T07:08:51.665627+00:00 | 2022-08-07T07:13:07.895189+00:00 | 438 | false | ##### This solution is slightly better than pure brute force as it calls the 3rd loop only if a condition is met.\n\n```\nclass Solution:\n def arithmeticTriplets(self, nums: List[int], diff: int) -> int:\n res = 0\n for i in range(len(nums)):\n for j in range(i+1, len(nums)):\n ... | 5 | 0 | ['Python', 'Python3'] | 0 |
number-of-arithmetic-triplets | C++ ✅ using SET O(n2) ✅ ✅ | c-using-set-on2-by-pratapsingha264-vob1 | class Solution {\npublic:\n int arithmeticTriplets(vector& nums, int diff) \n {\n int count=0;\n int n= nums.size();\n set s;\n | Pratapsingha264 | NORMAL | 2022-08-07T04:17:52.085132+00:00 | 2022-08-07T04:20:56.378463+00:00 | 586 | false | class Solution {\npublic:\n int arithmeticTriplets(vector<int>& nums, int diff) \n {\n int count=0;\n int n= nums.size();\n set<int> s;\n \n \n for(int i=0;i<n;i++)\n {\n s.insert(nums[i]);\n for(int j=i+1;j<n;j++)\n {\n ... | 5 | 1 | ['C', 'Ordered Set'] | 0 |
number-of-arithmetic-triplets | SIMPLE SET COMMENTED C++ SOLUTION WITH EXPLANATION | simple-set-commented-c-solution-with-exp-wd9i | 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 | Jeffrin2005 | NORMAL | 2024-07-18T12:39:01.981499+00:00 | 2024-07-18T12:39:01.981523+00:00 | 107 | 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(n)\n<!-- Add your space complexity here, e.g. $$O... | 4 | 0 | ['C++'] | 0 |
number-of-arithmetic-triplets | Easiest way | easiest-way-by-nurzhansultanov-1wg5 | \n\nclass Solution(object):\n def arithmeticTriplets(self, nums, diff):\n result = []\n for i in range(len(nums)-1, 1, -1):\n for j | NurzhanSultanov | NORMAL | 2024-01-30T14:55:26.936789+00:00 | 2024-01-30T14:55:26.936824+00:00 | 174 | false | \n```\nclass Solution(object):\n def arithmeticTriplets(self, nums, diff):\n result = []\n for i in range(len(nums)-1, 1, -1):\n for j in range(i-1, 0, -1):\n for k in range(j-1, -1, -1):\n if nums[i] - nums[j] == nums[j] - nums[k] == diff:\n ... | 4 | 0 | ['Python'] | 1 |
number-of-arithmetic-triplets | TypeScript/JavaScript O(n) Solution | typescriptjavascript-on-solution-by-hals-xjn3 | \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 | halshar | NORMAL | 2023-09-22T18:48:12.736640+00:00 | 2023-09-26T14:38:33.860133+00:00 | 312 | false | \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```\nfunction arithmeticTriplets(nums: number[], diff: number): number {\n const hash = new Set<number>();\n let ans = 0;\n\n // what we ... | 4 | 0 | ['TypeScript', 'JavaScript'] | 1 |
number-of-arithmetic-triplets | 📍||USING SET ||2 Liner ||🔥🔥🔥🔥|| OPTIMISED SOLUTION | using-set-2-liner-optimised-solution-by-jr0bn | 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 | Sautramani | NORMAL | 2023-08-20T05:54:31.523936+00:00 | 2023-08-20T05:57:32.374694+00:00 | 802 | 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)$$ -->\nO(N)\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n... | 4 | 0 | ['Array', 'Ordered Set', 'Python', 'C++', 'Java'] | 1 |
number-of-arithmetic-triplets | Go. Two pointers. Time complexity O(n) and Space complexity O(1) | go-two-pointers-time-complexity-on-and-s-trtu | Intuition\n\n##### Analyzing the problem, the following points can be emphasized:\n1. We are given an array of integers sorted in ascending order.\n1. We need t | sergei-m | NORMAL | 2023-08-01T15:54:07.222484+00:00 | 2023-08-05T23:22:40.020599+00:00 | 264 | false | # Intuition\n\n##### Analyzing the problem, the following points can be emphasized:\n1. We are given an array of integers sorted in ascending order.\n1. We need to find pairs of values that will match the condition `y - x = diff && z - y = diff`.\n1. This means that there is no need to look for a pair `z - y = diff` if... | 4 | 0 | ['Array', 'Two Pointers', 'Go'] | 0 |
number-of-arithmetic-triplets | FASTEST solution with JAVA(1ms) | fastest-solution-with-java1ms-by-amin_az-ygj2 | Code\n\nclass Solution {\n public int arithmeticTriplets(int[] nums, int diff) {\n int count = 0; \n Set<Integer> list = new HashSet<>();\n | amin_aziz | NORMAL | 2023-04-12T09:05:48.679776+00:00 | 2023-04-12T18:07:18.237541+00:00 | 1,893 | false | # Code\n```\nclass Solution {\n public int arithmeticTriplets(int[] nums, int diff) {\n int count = 0; \n Set<Integer> list = new HashSet<>();\n for(int a : nums){\n if(list.contains(a-diff) && list.contains(a-diff*2)) count++;\n list.add(a);\n }\n return coun... | 4 | 0 | ['Java'] | 3 |
number-of-arithmetic-triplets | C++ easy solution with loops. | c-easy-solution-with-loops-by-aloneguy-e06b | \n# Complexity\n- Time complexity: 6 ms.Beats 65.9% solutions.\n Add your time complexity here, e.g. O(n) \n\n- Space complexity:8.6 Mb.Beats 88.98% solutions.\ | aloneguy | NORMAL | 2023-03-23T07:03:21.747706+00:00 | 2023-03-23T07:03:21.747748+00:00 | 454 | false | \n# Complexity\n- Time complexity: 6 ms.Beats 65.9% solutions.\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:8.6 Mb.Beats 88.98% solutions.\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n int arithmeticTriplets(vector<int>& nums, int ... | 4 | 0 | ['C++'] | 0 |
number-of-arithmetic-triplets | C# easy solution. | c-easy-solution-by-aloneguy-vux7 | \n# Complexity\n- Time complexity: 89 ms.Beats 66.24% of other solutions.\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: 38.1 Mb.Beats 85.99 | aloneguy | NORMAL | 2023-03-23T06:57:44.832885+00:00 | 2023-03-23T06:57:44.832925+00:00 | 373 | false | \n# Complexity\n- Time complexity: 89 ms.Beats 66.24% of other solutions.\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: 38.1 Mb.Beats 85.99% of others.\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\npublic class Solution {\n public int count=0;\n public int... | 4 | 0 | ['Math', 'C#'] | 0 |
number-of-arithmetic-triplets | java solution using HashSet !! | java-solution-using-hashset-by-aanshi_07-kg9o | \n# Code\n\nclass Solution {\n public int arithmeticTriplets(int[] nums, int diff) {\n Set<Integer> set = new HashSet<>();\n for(int n: nums){ | aanshi_07 | NORMAL | 2022-12-10T10:14:36.778815+00:00 | 2022-12-10T10:18:10.855162+00:00 | 797 | false | \n# Code\n```\nclass Solution {\n public int arithmeticTriplets(int[] nums, int diff) {\n Set<Integer> set = new HashSet<>();\n for(int n: nums){\n set.add(n);\n }\n int count =0;\n for(int n:nums){\n if(set.contains(n+diff) && set.contains(n+(2*diff)))\n ... | 4 | 0 | ['Hash Table', 'Java'] | 3 |
number-of-arithmetic-triplets | 100% Faster || TypeScript || Easy to understand | 100-faster-typescript-easy-to-understand-4btn | Let me know in comments if you have any doubts. I will be happy to answer.\nPlease upvote if you found the solution useful.\n\n\nconst arithmeticTriplets = (num | viniciusteixeiradias | NORMAL | 2022-11-14T02:36:28.105429+00:00 | 2022-11-16T01:48:43.163198+00:00 | 106 | false | Let me know in comments if you have any doubts. I will be happy to answer.\nPlease upvote if you found the solution useful.\n\n```\nconst arithmeticTriplets = (nums: number[], diff: number): number => {\n let sum = 0;\n let hash = new Set();\n \n for(let i = 0; i < nums.length; i++) {\n if (hash.has(... | 4 | 0 | ['TypeScript'] | 0 |
number-of-arithmetic-triplets | C++ Naive Approach Solution | c-naive-approach-solution-by-king_of_kin-ugy0 | int arithmeticTriplets(vector& nums, int diff) {\n\n int ans = 0 ;\n for(int i = 0 ; i < nums.size()-2 ; i++)\n {\n for(int j = | King_of_Kings101 | NORMAL | 2022-09-23T07:03:31.293751+00:00 | 2022-09-23T07:06:36.055976+00:00 | 623 | false | int arithmeticTriplets(vector<int>& nums, int diff) {\n\n int ans = 0 ;\n for(int i = 0 ; i < nums.size()-2 ; i++)\n {\n for(int j = i+1 ; j < nums.size()-1 ; j++)\n {\n if(nums[i]+diff==nums[j])\n {\n for(int k = j +1; k < nums.si... | 4 | 0 | ['Array', 'C', 'C++'] | 0 |
number-of-arithmetic-triplets | C Sharp Solution | c-sharp-solution-by-fadydev123-3n1c | \nint count = 0;\nHashSet<int> hash_num = new HashSet<int>();\nforeach(int num in nums)\n{\n\tif(hash_num.Contains(num - diff) && hash_num.Contains(num - 2 * di | fadydev123 | NORMAL | 2022-09-11T07:08:23.635368+00:00 | 2022-09-11T07:08:39.984015+00:00 | 271 | false | ```\nint count = 0;\nHashSet<int> hash_num = new HashSet<int>();\nforeach(int num in nums)\n{\n\tif(hash_num.Contains(num - diff) && hash_num.Contains(num - 2 * diff))\n\t\tcount++;\n\thash_num.Add(num); \n}\nreturn count;\n\n``` | 4 | 0 | ['C#'] | 0 |
number-of-arithmetic-triplets | JavaScript | Hashmap solution | O(n) | javascript-hashmap-solution-on-by-zhe1ka-megg | ```\nfunction arithmeticTriplets(nums: number[], diff: number): number {\n let sum = 0;\n let hash = new Set();\n \n for (let numIndex = 0; numIndex | Zhe1ka | NORMAL | 2022-08-29T06:34:27.142829+00:00 | 2022-08-29T06:34:27.142854+00:00 | 533 | false | ```\nfunction arithmeticTriplets(nums: number[], diff: number): number {\n let sum = 0;\n let hash = new Set();\n \n for (let numIndex = 0; numIndex < nums.length; numIndex++) {\n const currentNum = nums[numIndex];\n \n if (hash.has(currentNum - diff) && hash.has(currentNum - diff - dif... | 4 | 0 | ['TypeScript', 'JavaScript'] | 0 |
number-of-arithmetic-triplets | Three Pointers, one pass O(n) time and O(1) space | three-pointers-one-pass-on-time-and-o1-s-osqq | Intuition"Strictly increasing" is the key.Complexity
Time complexity:O(n)
Space complexity:O(1)
Code | SoulMan | NORMAL | 2025-02-09T08:55:22.860188+00:00 | 2025-02-19T09:10:59.236542+00:00 | 227 | false | # Intuition
"Strictly increasing" is the key.
<!-- Describe your first thoughts on how to solve this problem. -->
# Complexity
- Time complexity: $$O(n)$$
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity: $$O(1)$$
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
```cpp []
class S... | 3 | 0 | ['C++', 'Java'] | 0 |
number-of-arithmetic-triplets | 💢☠💫Easiest👾Faster✅💯 Lesser🧠 🎯 C++✅Python3🐍✅Java✅C✅Python🐍✅C#✅💥🔥💫Explained☠💥🔥 Beats 💯 | easiestfaster-lesser-cpython3javacpython-vnsh | Intuition\n\n\nThese are the almost same questions which are similar to this one which are as follows :-\n\n---\nQ - 1460 --> https://leetcode.com/problems/make | Edwards310 | NORMAL | 2024-07-26T13:19:02.822977+00:00 | 2024-07-26T14:15:15.201707+00:00 | 357 | false | # Intuition\n\n\nThese are the almost same questions which ar... | 3 | 0 | ['Array', 'Hash Table', 'Two Pointers', 'C', 'Enumeration', 'Python', 'C++', 'Java', 'Python3', 'C#'] | 0 |
number-of-arithmetic-triplets | Easy to understand - Java | easy-to-understand-java-by-ungureanu_ovi-o5g5 | Upvote if you like the solution\n\n# Intuition\n\nThe problem requires finding unique arithmetic triplets in an array, where the difference between consecutive | Ungureanu_Ovidiu | NORMAL | 2024-07-02T10:09:52.126395+00:00 | 2024-07-02T10:09:52.126431+00:00 | 142 | false | ##### Upvote if you like the solution\n\n# Intuition\n\nThe problem requires finding unique arithmetic triplets in an array, where the difference between consecutive elements in the triplet is a given value `diff`.\n\n## Approach\n\n1. **Set for Lookup**:\n - Use a `HashSet` called `presentNums` to store all the inte... | 3 | 0 | ['Java'] | 0 |
number-of-arithmetic-triplets | Easy solution java | easy-solution-java-by-abhinav29code-zoz2 | \n\n# Code\n\nclass Solution {\n public int arithmeticTriplets(int[] nums, int diff) {\n if(nums.length < 3) return 0;\n\n int count = 0;\n | abhinav29code | NORMAL | 2023-12-26T04:22:39.315944+00:00 | 2023-12-26T04:22:39.315983+00:00 | 364 | false | \n\n# Code\n```\nclass Solution {\n public int arithmeticTriplets(int[] nums, int diff) {\n if(nums.length < 3) return 0;\n\n int count = 0;\n HashSet<Integer> set = new HashSet<>();\n for(int num : nums) {\n if(set.contains(num - diff) && set.contains(num - diff*2)) {\n ... | 3 | 0 | ['Java'] | 0 |
number-of-arithmetic-triplets | Easy to understand for beginner using "HashMap" | easy-to-understand-for-beginner-using-ha-2u6h | Approach\n\nfirst of all you should be aware about hashmap and its functions.\nOne such function which I have used is "containsKey" it return true if a key is p | Priyansh_max | NORMAL | 2023-12-17T15:44:08.631449+00:00 | 2023-12-17T15:44:08.631470+00:00 | 387 | false | # Approach\n\nfirst of all you should be aware about hashmap and its functions.\nOne such function which I have used is "containsKey" it return true if a key is present in the hashmap that you have inputed.\n\n1 --> creating a hashmap\n2 --> create a <key , value> pair \n\n3 --> check if "diff + current index is presen... | 3 | 0 | ['Java'] | 2 |
number-of-arithmetic-triplets | Better than nested loops. | better-than-nested-loops-by-drugged_monk-c7i3 | Intuition\nProblem should be solved in one loop.\n\n# Approach\nFirst I convert array nums to HashSet. Then I traverse array nums to find every triplet nums[i], | Drugged_Monkey | NORMAL | 2023-12-01T20:20:53.173227+00:00 | 2024-06-08T15:09:40.389792+00:00 | 102 | false | # Intuition\nProblem should be solved in one loop.\n\n# Approach\nFirst I convert array `nums` to `HashSet`. Then I traverse array `nums` to find every triplet `nums[i]`, `nums[i] - diff` and `nums[i] + diff`. That\'s it.\n\n# Complexity\n- Time complexity:\n$$O(n)$$. Despite `HashSet.Contains()` implementation isn\'t ... | 3 | 0 | ['C#'] | 2 |
number-of-arithmetic-triplets | ✅Iteratively||🔥Simple Solution 🔥|| JAVA || C++|| Python || 🚀Clean Codes🚀 ||Easy to Understand✅✅ | iterativelysimple-solution-java-c-python-xpng | \n# Approach\n Describe your approach to solving the problem. \nHere\'s a breakdown of the code:\n\n1. int ans = 0;: This initializes a variable ans to store th | preans1412 | NORMAL | 2023-08-11T16:47:23.178415+00:00 | 2023-08-11T16:47:23.178434+00:00 | 497 | false | \n# Approach\n<!-- Describe your approach to solving the problem. -->\nHere\'s a breakdown of the code:\n\n1. int ans = 0;: This initializes a variable ans to store the count of arithmetic triplets found in the vector.\n\n2. The code uses three nested for loops to iterate through all possible combinations of three indi... | 3 | 0 | ['Array', 'Python', 'C++', 'Java', 'Python3'] | 1 |
number-of-arithmetic-triplets | Easy C++ Solution | easy-c-solution-by-adityagarg217-wmqq | class Solution {\npublic:\n\n int arithmeticTriplets(vector& nums, int diff) {\n int ans = 0 ;\n \n for(int i=0 ;i<nums.size()-2 ;i++){\n | adityagarg217 | NORMAL | 2023-06-04T10:39:36.839663+00:00 | 2023-06-05T11:49:43.064449+00:00 | 1,475 | false | class Solution {\npublic:\n\n int arithmeticTriplets(vector<int>& nums, int diff) {\n int ans = 0 ;\n \n for(int i=0 ;i<nums.size()-2 ;i++){\n int count = 0 ;\n for(int j=i+1 ; j<nums.size() ;j++){\n \n if(nums[j]-nums[i]==diff || nums[j]-nums[i... | 3 | 0 | ['Array', 'C'] | 0 |
number-of-arithmetic-triplets | [Java] Easy set solution 100% O(n) | java-easy-set-solution-100-on-by-ytchoua-mu5m | java\nclass Solution {\n public int arithmeticTriplets(int[] nums, int diff) {\n Set<Integer> set = new HashSet<>();\n int i = 0, k = 1, result | YTchouar | NORMAL | 2023-04-01T07:04:11.285197+00:00 | 2023-04-01T07:04:25.892014+00:00 | 2,685 | false | ```java\nclass Solution {\n public int arithmeticTriplets(int[] nums, int diff) {\n Set<Integer> set = new HashSet<>();\n int i = 0, k = 1, result = 0;\n\n for(int num : nums)\n set.add(num);\n\n while(k < nums.length) {\n if(nums[k] - nums[i] == 2 * diff && set.cont... | 3 | 0 | ['Java'] | 3 |
number-of-arithmetic-triplets | single pass | single-pass-by-rajsiddi-r2ed | \n\nclass Solution {\npublic:\n int arithmeticTriplets(vector<int>& nums, int diff) {\n int trip = 0;\n for(int i=0;i<nums.size();i++){\n | rajsiddi | NORMAL | 2023-03-05T09:35:59.011537+00:00 | 2023-03-05T09:44:41.552036+00:00 | 1,060 | false | \n```\nclass Solution {\npublic:\n int arithmeticTriplets(vector<int>& nums, int diff) {\n int trip = 0;\n for(int i=0;i<nums.size();i++){\n int find = nums[i]+diff;\n if(count(nums.begin(),nums.end(),find)>0){\n int find2 = find+diff;\n if(count(nums.begin(),num... | 3 | 0 | ['C++'] | 1 |
number-of-arithmetic-triplets | Runtime 52 ms Beats 57.18% Memory 13.9 MB Beats 55.96%, beginner easy to understand | runtime-52-ms-beats-5718-memory-139-mb-b-xzlv | 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 | NEWYORK2009 | NORMAL | 2023-02-09T17:48:08.180089+00:00 | 2023-02-09T17:48:08.180144+00:00 | 697 | 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)$$ --... | 3 | 0 | ['Python3'] | 1 |
number-of-arithmetic-triplets | Beats 97.36% || Number of Arithmetic Triplets | beats-9736-number-of-arithmetic-triplets-9x8p | 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 | himshrivas | NORMAL | 2023-01-29T17:23:05.418261+00:00 | 2023-01-29T17:23:05.418307+00:00 | 1,779 | 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)$$ --... | 3 | 0 | ['Python3'] | 4 |
number-of-arithmetic-triplets | O(N) Set + reduce solution | on-set-reduce-solution-by-ods967-xhzm | Code\n\n/**\n * @param {number[]} nums\n * @param {number} diff\n * @return {number}\n */\nvar arithmeticTriplets = function(nums, diff) {\n const set = new | ods967 | NORMAL | 2023-01-05T06:52:29.348880+00:00 | 2023-01-05T06:52:29.348926+00:00 | 417 | false | # Code\n```\n/**\n * @param {number[]} nums\n * @param {number} diff\n * @return {number}\n */\nvar arithmeticTriplets = function(nums, diff) {\n const set = new Set();\n\n return nums.reduce((acc, num) => {\n set.add(num);\n\n if (set.has(num - diff) && set.has(num - 2 * diff)) {\n retur... | 3 | 0 | ['JavaScript'] | 0 |
number-of-arithmetic-triplets | 3 loops || JAVA || Easy to understand | 3-loops-java-easy-to-understand-by-im_ob-0iqq | Intuition\n\nDon\'t forget to upvote if you found it useful\n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time complexity:\ | im_obid | NORMAL | 2022-11-21T08:58:00.843601+00:00 | 2022-11-21T08:58:00.843633+00:00 | 1,012 | false | # Intuition\n\nDon\'t forget to upvote if you found it 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:\nO(n^3)\n\n# Code\n```\nclass Solution {\n public int arithmeticTriple... | 3 | 0 | ['Java'] | 0 |
number-of-arithmetic-triplets | O(n) Solution | Java | on-solution-java-by-pawan300-7681 | ```\n public int arithmeticTriplets(int[] nums, int diff) {\n int n = nums.length;\n int res =0;\n boolean arr[] = new boolean[nums[n-1]+di | pawan300 | NORMAL | 2022-09-30T18:09:30.960908+00:00 | 2022-09-30T18:09:30.960941+00:00 | 369 | false | ```\n public int arithmeticTriplets(int[] nums, int diff) {\n int n = nums.length;\n int res =0;\n boolean arr[] = new boolean[nums[n-1]+diff+1];\n for(int num:nums){\n arr[num]= true;\n }\n for(int i=0;i<n-2;i++){\n int val = nums[i];\n int val... | 3 | 0 | ['Java'] | 0 |
number-of-arithmetic-triplets | First SC - O(1) Solution | TC - O(n) | CPP, C, JAVA | first-sc-o1-solution-tc-on-cpp-c-java-by-plt8 | Please upvote If you like\n\nCPP\n\n\tunsigned short int count = 0,\n\ti = 0,\n\tj = i + 1,\n\tk = j + 1;\n\twhile (i < nums.size() && j < nums.size() && k < nu | rushil12 | NORMAL | 2022-09-13T03:41:59.724695+00:00 | 2022-09-15T03:59:31.908930+00:00 | 112 | false | **Please upvote If you like**\n\n**CPP**\n\n\tunsigned short int count = 0,\n\ti = 0,\n\tj = i + 1,\n\tk = j + 1;\n\twhile (i < nums.size() && j < nums.size() && k < nums.size()) {\n\n\t\tif (nums[j] - nums[i] == diff && nums[k] - nums[j] == diff) {\n\t\t\tcount++;\n\t\t\ti++;\n\t\t\tj++;\n\t\t\tk++;\n\t\t\tcontinue;\n... | 3 | 0 | [] | 0 |
number-of-arithmetic-triplets | [Java] Most easiest solution with explanation. | java-most-easiest-solution-with-explanat-trle | //This is a two pointer simple approach. Take a variable count to keep a count of the triplets.\n//initialiaze i=0; and then take a while loop which will run ti | vishady7 | NORMAL | 2022-08-20T19:53:29.879137+00:00 | 2022-08-20T19:53:29.879169+00:00 | 520 | false | //This is a two pointer simple approach. Take a variable count to keep a count of the triplets.\n//initialiaze i=0; and then take a while loop which will run till i is less than nums.length-2.\n//inside this while loop take two variable j = i+1 and k = j+1;\n\n\nclass Solution {\n public int arithmeticTriplets(int[]... | 3 | 0 | ['Two Pointers', 'Java'] | 0 |
number-of-arithmetic-triplets | ✅✅Faster || Easy To Understand || C++ Code | faster-easy-to-understand-c-code-by-__kr-qbb3 | Using Unordered Set\n\n Time Complexity :- O(N)\n\n Space Complexity :- O(N)\n\n\nclass Solution {\npublic:\n int arithmeticTriplets(vector<int>& nums, int d | __KR_SHANU_IITG | NORMAL | 2022-08-17T07:10:16.977521+00:00 | 2022-08-17T07:10:16.977552+00:00 | 399 | false | * ***Using Unordered Set***\n\n* ***Time Complexity :- O(N)***\n\n* ***Space Complexity :- O(N)***\n\n```\nclass Solution {\npublic:\n int arithmeticTriplets(vector<int>& nums, int diff) {\n \n int n = nums.size();\n \n // insert all the elements into the set\n \n unordered_... | 3 | 0 | ['C', 'C++'] | 1 |
number-of-arithmetic-triplets | C++ 0ms Faster than 100% | c-0ms-faster-than-100-by-husain_267-6i8r | class Solution {\npublic:\n int arithmeticTriplets(vector& nums, int diff) {\n int cnt = 0;\n unordered_setset;\n for(int i=0;i<nums.siz | husain_267 | NORMAL | 2022-08-13T10:28:36.635983+00:00 | 2022-08-13T10:28:36.636025+00:00 | 241 | false | class Solution {\npublic:\n int arithmeticTriplets(vector<int>& nums, int diff) {\n int cnt = 0;\n unordered_set<int>set;\n for(int i=0;i<nums.size();i++){\n set.insert(nums[i]);\n }\n for(int i=0;i<nums.size();i++){\n if(set.find(nums[i]+diff)!=set.end() && s... | 3 | 0 | ['C', 'Ordered Set'] | 0 |
number-of-arithmetic-triplets | Python Elegant & Short | Two solutions | O(n) and O(n*log(n)) | Binary search | python-elegant-short-two-solutions-on-an-1ekf | \tclass Solution:\n\t\t"""\n\t\tTime: O(n*log(n))\n\t\tMemory: O(1)\n\t\t"""\n\n\t\tdef arithmeticTriplets(self, nums: List[int], diff: int) -> int:\n\t\t\tco | Kyrylo-Ktl | NORMAL | 2022-08-12T10:27:36.955680+00:00 | 2022-08-12T10:35:41.767537+00:00 | 381 | false | \tclass Solution:\n\t\t"""\n\t\tTime: O(n*log(n))\n\t\tMemory: O(1)\n\t\t"""\n\n\t\tdef arithmeticTriplets(self, nums: List[int], diff: int) -> int:\n\t\t\tcount = 0\n\t\t\tleft, right = 0, len(nums) - 1\n\n\t\t\tfor j, num in enumerate(nums):\n\t\t\t\tif self.binary_search(nums, num - diff, left, j - 1) != -1 and \\... | 3 | 0 | ['Binary Tree', 'Python', 'Python3'] | 1 |
number-of-arithmetic-triplets | O(n^3) Solution for Beginners | on3-solution-for-beginners-by-ssbaviskar-ufvb | \n\nlet arr = []\n for (let i=0;i<=nums.length-3;i++){\n for(let j=i+1;j<=nums.length-2;j++){\n for(let k = j+1;k<=nums.length-1;k++){\n | SSBaviskar | NORMAL | 2022-08-09T13:38:29.314767+00:00 | 2022-09-25T18:03:59.899868+00:00 | 289 | false | ```\n\nlet arr = []\n for (let i=0;i<=nums.length-3;i++){\n for(let j=i+1;j<=nums.length-2;j++){\n for(let k = j+1;k<=nums.length-1;k++){\n if(nums[j]-nums[i]==diff && nums[k]-nums[j]==diff){\n arr.push([nums[i],nums[j],nums[k]]);\n }\n }\... | 3 | 0 | ['JavaScript'] | 1 |
number-of-arithmetic-triplets | C++ Simple 2 pointer approach | c-simple-2-pointer-approach-by-hi2406-hnef | \nclass Solution {\npublic:\n int arithmeticTriplets(vector<int>& nums, int diff) {\n int count=0;\n for(int i=0;i<nums.size()-2;i++){\n int sta | hi2406 | NORMAL | 2022-08-07T21:14:47.401703+00:00 | 2022-08-07T21:14:47.401732+00:00 | 381 | false | ```\nclass Solution {\npublic:\n int arithmeticTriplets(vector<int>& nums, int diff) {\n int count=0;\n for(int i=0;i<nums.size()-2;i++){\n int start = i+1,end = nums.size()-1;\n while(start < end){\n if(nums[start]-nums[i] == diff && nums[end]-nums[start] == diff){\n co... | 3 | 0 | ['Two Pointers', 'C'] | 0 |
number-of-arithmetic-triplets | C# Hashset | c-hashset-by-zloytvoy-595a | \tpublic int ArithmeticTriplets(int[] nums, int diff) \n\t\t{\n\t\t\tvar hashset = new HashSet();\n\t\t\tfor(int i = 0; i < nums.Length; ++i)\n\t\t\t{\n\t\t\t\t | zloytvoy | NORMAL | 2022-08-07T20:27:41.355796+00:00 | 2022-08-07T20:27:41.355829+00:00 | 57 | false | \tpublic int ArithmeticTriplets(int[] nums, int diff) \n\t\t{\n\t\t\tvar hashset = new HashSet<int>();\n\t\t\tfor(int i = 0; i < nums.Length; ++i)\n\t\t\t{\n\t\t\t\thashset.Add(nums[i]); \n\t\t\t}\n\n\t\t\tint result = 0;\n\t\t\tfor(int i = 0; i < nums.Length; ++i)\n\t\t\t{\n\t\t\t\tif(hashset.Contains(nums[i] + dif... | 3 | 0 | [] | 0 |
number-of-arithmetic-triplets | C++ | O(n) | Map | Easy to understand | Commented & Readable | c-on-map-easy-to-understand-commented-re-p89e | \nclass Solution {\npublic:\n int arithmeticTriplets(vector<int>& nums, int diff) {\n unordered_map<int, int> mp;\n int ans = 0;\n \n// | shreyanshxyz | NORMAL | 2022-08-07T19:24:29.844077+00:00 | 2022-08-07T19:24:29.844117+00:00 | 60 | false | ```\nclass Solution {\npublic:\n int arithmeticTriplets(vector<int>& nums, int diff) {\n unordered_map<int, int> mp;\n int ans = 0;\n \n// we check in the map if the number with the current number\'s difference & its 2x difference exists or not, if it does not, we simply push the current number ... | 3 | 0 | ['C'] | 0 |
number-of-arithmetic-triplets | C++ solution || Using unordered map || 💯Faster | c-solution-using-unordered-map-faster-by-7qxt | \n int cnt = 0;\n unordered_map<int,bool> mp;\n for(int i=0;i<nums.size();i++)\n mp[nums[i]] = true;\n for(int i=0;i<nums.size( | Amanmalviya | NORMAL | 2022-08-07T11:14:36.337316+00:00 | 2022-08-07T11:14:36.337356+00:00 | 402 | false | ```\n int cnt = 0;\n unordered_map<int,bool> mp;\n for(int i=0;i<nums.size();i++)\n mp[nums[i]] = true;\n for(int i=0;i<nums.size();i++)\n {\n if(mp[nums[i]-diff] && mp[nums[i]+diff])\n cnt++;\n } \n return cnt;\n``` | 3 | 0 | ['C++'] | 0 |
number-of-arithmetic-triplets | Latest Solution || Detailed Explanation || 2 Approaches | latest-solution-detailed-explanation-2-a-eoio | BIG IDEA: SAY YOU ARE GIVEN SINGLE NUMBER 6 AND DIFF = 3 , WHAT OTHER TWO NUMBERS DO YOU NEED TO SATISY CONDITIONS GIVEN IN THE PROBLEM? YOU NEED 6- DIFF AND 6 | progressivefailure | NORMAL | 2022-08-07T07:36:50.976604+00:00 | 2022-08-07T07:36:50.976640+00:00 | 188 | false | # BIG IDEA: SAY YOU ARE GIVEN SINGLE NUMBER 6 AND DIFF = 3 , WHAT OTHER TWO NUMBERS DO YOU NEED TO SATISY CONDITIONS GIVEN IN THE PROBLEM? YOU NEED 6- DIFF AND 6 + DIFF. SO WE ARE SIMPLY DOING THAT, THE THING IS YOU ONLY NEED TO IDENTIFY THIS AND THEN THE QUESTION IS A CAKEWALK.\n# FIRST APPROACH \n# NOTE: AS IT IS GIV... | 3 | 0 | ['Binary Tree', 'Python'] | 1 |
number-of-arithmetic-triplets | JAVA | easy to understand | for loop | java-easy-to-understand-for-loop-by-pazu-413s | Assume all number can be the first number of triplet\n2. if map[num - diff] == 1, it means that num is the second number of triplet\n\tor map[num - diff] == 2, | PazuC | NORMAL | 2022-08-07T04:13:40.750241+00:00 | 2022-08-07T04:19:50.375160+00:00 | 706 | false | 1. Assume all number can be the first number of triplet\n2. if map[num - diff] == 1, it means that num is the second number of triplet\n\tor map[num - diff] == 2, it means that num is the third number of triplet\n\t...\n3. so, just need to count how many map[num] >= 3 (inside a triplet)\n\nin case 1, 2 triplets are [1,... | 3 | 0 | ['Java'] | 1 |
number-of-arithmetic-triplets | ✅Easy C++ || Looop || Basic Approach || No extra space needed! | easy-c-looop-basic-approach-no-extra-spa-jwac | ```\nclass Solution {\npublic:\n int arithmeticTriplets(vector& nums, int diff) {\n int n = nums.size();\n int c=0;\n for(int i=0;i<n-2; | gittyAditya | NORMAL | 2022-08-07T04:08:17.716726+00:00 | 2022-08-07T04:08:17.716753+00:00 | 153 | false | ```\nclass Solution {\npublic:\n int arithmeticTriplets(vector<int>& nums, int diff) {\n int n = nums.size();\n int c=0;\n for(int i=0;i<n-2;++i)\n for(int j=i+1;j<n-1;++j)\n for(int k=j+1;k<n;++k)\n if(nums[j]-nums[i] == diff && nums[k]-nums[j] == di... | 3 | 0 | ['C'] | 0 |
number-of-arithmetic-triplets | Python Solution | python-solution-by-swanand_joshi-flt9 | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | Swanand_Joshi | NORMAL | 2025-02-21T18:32:09.251736+00:00 | 2025-02-21T18:32:09.251736+00:00 | 61 | 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
`... | 2 | 0 | ['Python3'] | 0 |
number-of-arithmetic-triplets | Number of Arithmetic Triplets || Python || Easy Solution | number-of-arithmetic-triplets-python-eas-db42 | Step-by-Step Explanation1. Initialize a Counter
Start with triplet_count set to 0. This variable will store the number of valid arithmetic triplets.
2. Iterate | aishvgandhi | NORMAL | 2025-01-23T06:14:17.230517+00:00 | 2025-01-23T06:14:17.230517+00:00 | 113 | false | # Step-by-Step Explanation
## 1. **Initialize a Counter**
```python
triplet_count = 0
```
- Start with `triplet_count` set to 0. This variable will store the number of valid arithmetic triplets.
## 2. **Iterate Over `nums` Using a Set**
```python
for i in set(nums):
```
- Convert `nums` into a ... | 2 | 0 | ['Array', 'Two Pointers', 'Python3'] | 1 |
number-of-arithmetic-triplets | SIMPLE BRUTEFORCE C++ SOLUTION | simple-bruteforce-c-solution-by-jeffrin2-5ce3 | 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 | Jeffrin2005 | NORMAL | 2024-07-18T12:39:56.990900+00:00 | 2024-07-18T12:39:56.990932+00:00 | 150 | 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^3)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:o(1)\n<!-- Add your space complexity here, e.g. $... | 2 | 0 | ['C++'] | 0 |
number-of-arithmetic-triplets | ⭐Creative solution using HashMap (w/ detailed explanation) | creative-solution-using-hashmap-w-detail-2lse | Observation:\n\nIn an arithmetic sequence of length n, there are n - 3 + 1 arithmetic triplets. For example, the sequence [2, 4, 6, 8] contains 2 arithmetic tri | Nature711 | NORMAL | 2024-05-25T07:56:33.402993+00:00 | 2024-05-25T07:56:33.403013+00:00 | 124 | false | **Observation**:\n\nIn an arithmetic sequence of length `n`, there are `n - 3 + 1` arithmetic triplets. For example, the sequence `[2, 4, 6, 8]` contains 2 arithmetic triplets: `[2, 4, 6]` and `[4, 6, 8]`.\n\nGiven that the input array is sorted, we can scan from the start to find all possible "longest" arithmetic sequ... | 2 | 0 | ['Java'] | 1 |
number-of-arithmetic-triplets | Efficient O(n) Solution for Counting Arithmetic Triplets in TypeScript | JavaScript | efficient-on-solution-for-counting-arith-e5jb | Intuition\n Describe your first thoughts on how to solve this problem. \n\n1. Create a Counter Hash:\nInitialize a hash to keep track of the number of arithmeti | sameeneeti | NORMAL | 2023-09-22T18:54:43.905645+00:00 | 2023-09-26T14:40:47.650834+00:00 | 314 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n1. Create a Counter Hash:\nInitialize a hash to keep track of the number of arithmetic triplets found so far.\n\n2. Iterate Through the Array:\nIterate through the array nums. For each element nums[j], calculate the potential previous e... | 2 | 0 | ['TypeScript', 'JavaScript'] | 0 |
number-of-arithmetic-triplets | [C++] check out this simple constant space solution. | c-check-out-this-simple-constant-space-s-3d8a | Code - 1 (Using Binary Search)\n- Time Complexity : O(nlogn)\n- Space Complexity : O(1)\n\n\nclass Solution {\npublic:\n int bs (vector<int> &nums, int &key, | vanshdhawan60 | NORMAL | 2023-09-07T22:43:47.953613+00:00 | 2023-09-07T22:43:47.953629+00:00 | 485 | false | # Code - 1 (Using Binary Search)\n- **Time Complexity :** $$O(n*logn)$$\n- **Space Complexity :** $$O(1)$$\n\n```\nclass Solution {\npublic:\n int bs (vector<int> &nums, int &key, int start, int end) {\n int low = start, high = end;\n while (low <= high) {\n int mid = low+(high-low)/2;\n ... | 2 | 0 | ['C++'] | 0 |
number-of-arithmetic-triplets | Binary Search approach in C++ | binary-search-approach-in-c-by-hustling_-5yww | Intuition\n Describe your first thoughts on how to solve this problem. \nIntution is all about arithmatic mean concept . We should check wheather nums[i]+diff & | Hustling_lad | NORMAL | 2023-07-23T07:53:56.210954+00:00 | 2023-07-23T07:53:56.210987+00:00 | 293 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nIntution is all about arithmatic mean concept . We should check wheather nums[i]+diff & nums[i]+2*diff is present in the vector or not.If true then increase count then return count\n\n# Approach\n<!-- Describe your approach to solving the... | 2 | 0 | ['C++'] | 0 |
number-of-arithmetic-triplets | Easy-Simple Java Solution in O(n^2) | easy-simple-java-solution-in-on2-by-tauq-dju4 | \n# Approach\n Describe your approach to solving the problem. \nWe have to find a triplet of (i, j, k) such that \ni<j=2 we add 1 to ans and at last return it.\ | tauqueeralam42 | NORMAL | 2023-07-02T09:58:16.819238+00:00 | 2023-07-02T09:58:16.819264+00:00 | 492 | false | \n# Approach\n<!-- Describe your approach to solving the problem. -->\nWe have to find a triplet of (i, j, k) such that \ni<j<k , \nnums[j] - nums[i] == diff, and \nnums[k] - nums[j] == diff\n\nin other word we can also say nums[k]-nums[i]== 2*diff. To reduce the time complexity I use only 2 loop remove the loop for k ... | 2 | 0 | ['Array', 'Java'] | 0 |
number-of-arithmetic-triplets | Simple-Easy Brute Force Approach | simple-easy-brute-force-approach-by-tauq-f8hy | \n\n# Approach\n Describe your approach to solving the problem. \nHere I use simple brute force approach. Use 3 for loop iterarte i, j, k one by one and search | tauqueeralam42 | NORMAL | 2023-07-02T09:36:23.699190+00:00 | 2023-07-02T09:36:23.699218+00:00 | 694 | false | \n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nHere I use simple brute force approach. Use 3 for loop iterarte i, j, k one by one and search a combinantion of i, j, k which can satisfied these given conditions and count that combinations.\n\n# Complexity\n- Time complexity: O(n^3)\n<!-- Add yo... | 2 | 0 | ['Array', 'Java'] | 0 |
number-of-arithmetic-triplets | Faster than 100%✅✅ || C++ || Very easy-logic with explanation | faster-than-100-c-very-easy-logic-with-e-oklg | Proof :please upvote if you liked my solution\n\n\nLogic: \nIf you have attempted 2sum leetcode question this code will be quite easy for you.The simple logic b | 40metersdeep | NORMAL | 2023-05-29T17:44:39.908014+00:00 | 2023-05-29T17:52:01.092773+00:00 | 437 | false | **Proof :**_please upvote if you liked my solution_\n\n\n**Logic:** \nIf you have attempted 2sum leetcode question this code will be quite easy for you.The simple logic behind the code is that there for every e... | 2 | 0 | ['C'] | 0 |
number-of-arithmetic-triplets | Fastest at 1ms | fastest-at-1ms-by-mohammad__irfan-5rqu | 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 | mohammad__irfan | NORMAL | 2023-05-02T11:33:19.669124+00:00 | 2023-05-02T11:33:19.669166+00:00 | 1,134 | 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)$$ --... | 2 | 0 | ['Java'] | 3 |
number-of-arithmetic-triplets | JAVA | 1ms | O(N^2) | java-1ms-on2-by-firdavs06-ivdd | 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 | Firdavs06 | NORMAL | 2023-02-27T07:19:04.038382+00:00 | 2023-02-27T07:19:04.038426+00:00 | 826 | 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)$$ --... | 2 | 0 | ['Java'] | 0 |
number-of-arithmetic-triplets | pointer manipulation in C | pointer-manipulation-in-c-by-fantsai8686-hhdp | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \nex:\n[0,1,4,6,7,10]\ntr | fantsai8686 | NORMAL | 2023-02-21T11:27:39.885087+00:00 | 2023-03-29T08:21:09.288216+00:00 | 468 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nex:\n[0,1,4,6,7,10]\ntraversing nums in for loop from index1= 0~numsSize-3 (0,1,4,6).\n\nThere is a while loop in each for loop starting from index2= 1~numsSize-1 to c... | 2 | 0 | ['C'] | 0 |
number-of-arithmetic-triplets | Solution in python easy to understand | solution-in-python-easy-to-understand-by-3prr | Input: nums = [0,1,4,6,7,10], diff = 3\nOutput: 2\nExplanation:\n(1, 2, 4) is an arithmetic triplet because both 7 - 4 == 3 and 4 - 1 == 3.\n(2, 4, 5) is an ari | mittalaparna | NORMAL | 2023-01-31T19:45:13.189850+00:00 | 2023-01-31T19:45:13.189887+00:00 | 83 | false | Input: nums = [0,1,4,6,7,10], diff = 3\nOutput: 2\nExplanation:\n(1, 2, 4) is an arithmetic triplet because both 7 - 4 == 3 and 4 - 1 == 3.\n(2, 4, 5) is an arithmetic triplet because both 10 - 7 == 3 and 7 - 4 == 3.\n\nCode explaination:\n((nums[i] + diff) in arr) and ((nums[i] + 2 * diff) in arr)\n = 1 + 3 i... | 2 | 0 | ['Hash Table', 'Python3'] | 0 |
number-of-arithmetic-triplets | Hashset n-diff and n-2*diff | hashset-n-diff-and-n-2diff-by-mohan_66-a6xg | 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 | Mohan_66 | NORMAL | 2023-01-28T05:26:46.572858+00:00 | 2023-01-28T05:26:46.572903+00:00 | 318 | 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)$$ --... | 2 | 0 | ['Python3'] | 0 |
number-of-arithmetic-triplets | Binary Search || by searching || without any space🔥 | binary-search-by-searching-without-any-s-8l31 | INTUTION: \n\n1. search no+diff and no+2diff by the help of lower bound. \n1. if both numbers present in array then just count++\n2. same thing is done for each | suyashdewangan9 | NORMAL | 2022-10-18T16:40:41.814627+00:00 | 2022-10-18T16:51:54.188030+00:00 | 195 | false | ##### INTUTION: \n\n1. search no+diff and no+2diff by the help of lower bound. \n1. if both numbers present in array then just count++\n2. same thing is done for each element of nums\n\n```\nclass Solution {\npublic:\n int arithmeticTriplets(vector<int>& nums, int diff) {\n int count=0;\n for(int i=0;i... | 2 | 0 | ['Binary Search', 'C'] | 0 |
number-of-arithmetic-triplets | 100% faster || c++ || simple | 100-faster-c-simple-by-recursive_coder-xvhd | \n\nclass Solution {\npublic:\n int arithmeticTriplets(vector<int>& nums, int diff) {\n \n vector<int> hash(305,0); // for storing cnt of each | recursive_coder | NORMAL | 2022-10-08T07:03:09.372355+00:00 | 2022-10-08T07:03:48.649782+00:00 | 908 | false | \n```\nclass Solution {\npublic:\n int arithmeticTriplets(vector<int>& nums, int diff) {\n \n vector<int> hash(305,0); // for storing cnt of each element in the array\n for(int i = 0 ; i... | 2 | 0 | ['C'] | 0 |
number-of-arithmetic-triplets | Python O(n log n) time, O(1) space solution with comments | python-on-log-n-time-o1-space-solution-w-36fh | Here is my optimized code that has:\nTime: O(n log n)\nSpace: O(1)\n\npython\n def arithmeticTriplets(self, nums: List[int], diff: int) -> int:\n n = | trpaslik | NORMAL | 2022-09-16T10:53:06.383950+00:00 | 2022-09-16T10:53:40.646376+00:00 | 279 | false | Here is my optimized code that has:\nTime: O(n log n)\nSpace: O(1)\n\n```python\n def arithmeticTriplets(self, nums: List[int], diff: int) -> int:\n n = len(nums)\n ans = 0\n for i in range(n-2):\n num0 = nums[i] # current num\n num1 = num0 + diff # expected nums[j]\n ... | 2 | 0 | ['Python'] | 1 |
number-of-arithmetic-triplets | SIMPLE JAVA CODE | simple-java-code-by-priyankan_23-8gp2 | \nclass Solution {\n public int arithmeticTriplets(int[] nums, int diff) {\n int count=0;\n for(int i=0;i<nums.length-2;i++){\n int | priyankan_23 | NORMAL | 2022-09-11T14:05:06.728079+00:00 | 2022-09-11T14:05:06.728114+00:00 | 188 | false | ```\nclass Solution {\n public int arithmeticTriplets(int[] nums, int diff) {\n int count=0;\n for(int i=0;i<nums.length-2;i++){\n int j=i+1,check=0;\n while(j<nums.length){\n if(nums[j]-nums[i]==diff){\n check=1;\n break;\n ... | 2 | 0 | [] | 0 |
number-of-arithmetic-triplets | Python | Linear | Fast | Explained with Comments | python-linear-fast-explained-with-commen-p3t9 | \nclass Solution:\n def arithmeticTriplets(self, nums: List[int], diff: int) -> int:\n \n # a variable to store number of triplets\n # i | rohitsh26 | NORMAL | 2022-09-08T04:06:30.264182+00:00 | 2022-09-08T04:23:09.232989+00:00 | 160 | false | ```\nclass Solution:\n def arithmeticTriplets(self, nums: List[int], diff: int) -> int:\n \n # a variable to store number of triplets\n # initializing with 0\n counterOfUniqueArithmeticTriplet = 0\n \n # create a set of number in the nums list\n _set = set(nums)\n ... | 2 | 0 | ['Python'] | 1 |
number-of-arithmetic-triplets | Brute force solution of java | brute-force-solution-of-java-by-annshu_8-vq6z | \tclass Solution {\n\t\tpublic int arithmeticTriplets(int[] nums, int diff) {\n\t\t int count = 0;\n\t\t\tfor(int i= 0; i< nums.length ; i++){\n\t\t\t\tfor( i | annshu_8410 | NORMAL | 2022-09-07T19:25:58.885742+00:00 | 2022-09-07T19:25:58.885780+00:00 | 53 | false | \tclass Solution {\n\t\tpublic int arithmeticTriplets(int[] nums, int diff) {\n\t\t int count = 0;\n\t\t\tfor(int i= 0; i< nums.length ; i++){\n\t\t\t\tfor( int j = i+1; j < nums.length ; j++){\n\t\t\t\t\tfor( int k = j+1; k < nums.length ; k++){\n\t\t\t\t\t\tif(i < j && j < k &&\n\t\t\t\t\t\t nums[j] - nums[i] == d... | 2 | 0 | ['Java'] | 0 |
number-of-arithmetic-triplets | FULLY EXPLAINED - O(n^3), O(n^2) and O(n) Solutions | fully-explained-on3-on2-and-on-solutions-3ccu | 1. O(n^3)\n\nThe straightforward way is to have three nested loops and then check the conditions. But ofcourse this won\'t be an efficient approach and will giv | itsarvindhere | NORMAL | 2022-09-07T13:13:49.275515+00:00 | 2022-09-07T13:54:05.495455+00:00 | 223 | false | ## **1. O(n^3)**\n\nThe straightforward way is to have three nested loops and then check the conditions. But ofcourse this won\'t be an efficient approach and will give TLE in case of large input. \n\n```\ndef arithmeticTriplets(self, nums: List[int], diff: int) -> int:\n count = 0;\n for i,num1 in enumer... | 2 | 0 | ['Python'] | 0 |
number-of-arithmetic-triplets | C+++ || 0ms Solution || Using Constant Space | c-0ms-solution-using-constant-space-by-k-hnzj | \nclass Solution {\npublic:\n int arithmeticTriplets(vector<int>& nums, int diff) {\n \n int count = 0;\n \n for(int i = 0 ; i<num | Khwaja_Abdul_Samad | NORMAL | 2022-09-02T13:04:59.492129+00:00 | 2022-09-02T13:04:59.492168+00:00 | 245 | false | ```\nclass Solution {\npublic:\n int arithmeticTriplets(vector<int>& nums, int diff) {\n \n int count = 0;\n \n for(int i = 0 ; i<nums.size()-2 ; i++)\n {\n int j = i+1 ;\n while(j<nums.size()-1 && nums[j]-nums[i] < diff)\n j++; \n ... | 2 | 0 | ['C'] | 1 |
number-of-arithmetic-triplets | Java | beats 69% lol | easy and simple solution | | java-beats-69-lol-easy-and-simple-soluti-vz3y | ```\nint ans = 0;\n //we take an answer that we will be returning ;\n \n for(int i = nums.length-1 ; i >=0 ; i--){//for the first element | k_io | NORMAL | 2022-08-21T09:22:54.137440+00:00 | 2022-08-21T09:22:54.137467+00:00 | 214 | false | ```\nint ans = 0;\n //we take an answer that we will be returning ;\n \n for(int i = nums.length-1 ; i >=0 ; i--){//for the first element of the triplet\n \n meow :\n for(int j = nums.length-1 ; j >=0 ; j--){//for the second element of the triplet ;\n if... | 2 | 0 | ['Array', 'Java'] | 0 |
number-of-arithmetic-triplets | Java solution | O(n) | java-solution-on-by-sourin_bruh-gt5i | \nclass Solution {\n public int arithmeticTriplets(int[] nums, int diff) {\n \n Set<Integer> set = new HashSet<>();\n \n for (int | sourin_bruh | NORMAL | 2022-08-21T08:03:11.503787+00:00 | 2022-08-21T09:36:28.388880+00:00 | 115 | false | ```\nclass Solution {\n public int arithmeticTriplets(int[] nums, int diff) {\n \n Set<Integer> set = new HashSet<>();\n \n for (int x : nums) set.add(x);\n \n int ans = 0;\n \n for (int x : nums) {\n if (set.contains(x - diff) && set.contains(x + di... | 2 | 0 | ['Java'] | 2 |
number-of-arithmetic-triplets | Java Solution | Simple solution | java-solution-simple-solution-by-shiladi-149f | class Solution {\n public int arithmeticTriplets(int[] nums, int diff) {\n Set set = new HashSet<>();\n for (int x : nums) {\n set.a | shiladityaroy | NORMAL | 2022-08-14T20:01:26.366631+00:00 | 2022-08-14T20:01:26.366660+00:00 | 293 | false | class Solution {\n public int arithmeticTriplets(int[] nums, int diff) {\n Set<Integer> set = new HashSet<>();\n for (int x : nums) {\n set.add(x);\n }\n \n int ans = 0;\n for (int x : nums) {\n if (set.contains(x - diff) && set.contains(x + diff)) {\n ... | 2 | 0 | ['Java'] | 1 |
reordered-power-of-2 | [C++/Java/Python] Straight Forward | cjavapython-straight-forward-by-lee215-5nse | counter will counter the number of digits 9876543210 in the given number.\nThen I just compare counter(N) with all counter(power of 2).\n1 <= N <= 10^9, so up t | lee215 | NORMAL | 2018-07-15T03:07:40.854887+00:00 | 2018-10-25T02:53:21.915764+00:00 | 23,923 | false | `counter` will counter the number of digits 9876543210 in the given number.\nThen I just compare `counter(N)` with all `counter(power of 2)`.\n`1 <= N <= 10^9`, so up to 8 same digits.\nIf `N > 10^9`, we can use a hash map.\n\n**C++:**\n```\n bool reorderedPowerOf2(int N) {\n long c = counter(N);\n for... | 325 | 4 | [] | 47 |
reordered-power-of-2 | Simple Java Solution Based on String Sorting | simple-java-solution-based-on-string-sor-cg66 | The idea here is similar to that of group Anagrams problem (Leetcode #49). \n\nFirst, we convert the input number (N) into a string and sort the string. Next, w | trotro | NORMAL | 2018-07-20T23:27:49.802904+00:00 | 2018-07-20T23:27:49.802904+00:00 | 5,807 | false | The idea here is similar to that of group Anagrams problem (Leetcode #49). \n\nFirst, we convert the input number (N) into a string and sort the string. Next, we get the digits that form the power of 2 (by using 1 << i and vary i), convert them into a string, and then sort them. As we convert the powers of 2 (and there... | 143 | 0 | [] | 12 |
reordered-power-of-2 | C++ Super Simple and Short Solution, 0 ms, Faster than 100% | c-super-simple-and-short-solution-0-ms-f-h8kl | \nclass Solution {\npublic:\n bool reorderedPowerOf2(int N) {\n string N_str = sorted_num(N);\n for (int i = 0; i < 32; i++)\n if (N | yehudisk | NORMAL | 2021-03-21T08:35:30.265019+00:00 | 2021-03-21T08:35:36.558397+00:00 | 7,636 | false | ```\nclass Solution {\npublic:\n bool reorderedPowerOf2(int N) {\n string N_str = sorted_num(N);\n for (int i = 0; i < 32; i++)\n if (N_str == sorted_num(1 << i)) return true;\n return false;\n }\n \n string sorted_num(int n) {\n string res = to_string(n);\n sor... | 108 | 13 | ['C'] | 12 |
reordered-power-of-2 | JS, Python, Java, C++ | Easy, Short Solution w/ Explanation | js-python-java-c-easy-short-solution-w-e-hcjo | (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-21T08:05:47.270873+00:00 | 2021-03-21T09:04:21.120695+00:00 | 3,967 | 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\nThe easiest way to check if two things are shuffled versions of each other, which is what this problem is asking us to do, is to sort them bot... | 71 | 12 | ['C', 'Python', 'Java', 'JavaScript'] | 2 |
reordered-power-of-2 | C++ || 100% fast || 0ms | c-100-fast-0ms-by-manuraj_tomar-q8im | \nbool reorderedPowerOf2(int n) {\n string s = to_string(n);\n sort(s.begin(),s.end());\n\t\t\n vector<string> power;\n for(int i=0; | Manuraj_Tomar | NORMAL | 2022-08-26T00:25:33.346170+00:00 | 2022-08-26T00:25:33.346214+00:00 | 11,209 | false | ```\nbool reorderedPowerOf2(int n) {\n string s = to_string(n);\n sort(s.begin(),s.end());\n\t\t\n vector<string> power;\n for(int i=0;i<=30;i++){\n int p = pow(2,i);\n power.push_back(to_string(p));\n }\n \n for(int i=0;i<=30;i++){\n sor... | 70 | 0 | ['C'] | 17 |
reordered-power-of-2 | Quick Math | quick-math-by-fllght-8pw1 | The main idea is what powers of 2 look like in binary form:\n\n\n\nthis will help easily iterate over all powers of two\n\nSo all we need is to convert n to sor | FLlGHT | NORMAL | 2022-08-26T03:07:13.630261+00:00 | 2023-05-12T05:19:51.907428+00:00 | 6,415 | false | The main idea is what powers of 2 look like in binary form:\n\n<img width="200" src="https://assets.leetcode.com/users/images/ae9964b4-ffbd-40a5-a934-e3dc1de49d28_1661482426.3498342.png">\n\nthis will help easily iterate over all powers of two\n\nSo all we need is to convert n to sorted digits and then compare them wit... | 59 | 0 | ['C', 'Python', 'Java'] | 14 |
reordered-power-of-2 | ✅Reordered Power of 2 | Short & Easy w/ Explanation | Beats 100% | reordered-power-of-2-short-easy-w-explan-sn76 | Solution - I (Counting Digits Frequency)\n\nA simple solution is to check if frequency of digits in N and all powers of 2 less than 10^9 are equal. In our case, | archit91 | NORMAL | 2021-03-21T09:16:40.942964+00:00 | 2021-03-21T14:52:30.030476+00:00 | 3,360 | false | ***Solution - I (Counting Digits Frequency)***\n\nA simple solution is to check if frequency of digits in N and all powers of 2 less than `10^9` are equal. In our case, we need to check for all powers of 2 from `2^0` to `2^29` and if any of them matches with digits in `N`, return true.\n\n```\n// counts frequency of ea... | 42 | 1 | ['C'] | 5 |
reordered-power-of-2 | ✅Easy Java Solution || 100% Faster 1ms 🔥🔥 || With Basic Explanation | easy-java-solution-100-faster-1ms-with-b-appb | If you really found my solution helpful please upvote it, as it motivates me to post such kind of codes and help the coding community, if you have some queries | ganajayant | NORMAL | 2022-08-26T05:22:19.464149+00:00 | 2022-08-26T06:04:02.776417+00:00 | 2,943 | false | **If you really found my solution helpful please upvote it, as it motivates me to post such kind of codes and help the coding community, if you have some queries or some improvements please feel free to comment and share your views.**\n\nbasically we are finding occurrence of each digit in n after that we are finding s... | 36 | 0 | ['Math', 'Counting', 'Java'] | 12 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.