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
sort-array-by-increasing-frequency
Simple Solution in Java
simple-solution-in-java-by-s34-v9in
Use map to store element & count/frequency\n- Use priority queue to store key-value pair is custom sorted format (as required in question)\n- Store the elements
s34
NORMAL
2021-09-07T16:14:53.894311+00:00
2021-09-07T16:14:53.894355+00:00
388
false
- Use map to store element & count/frequency\n- Use priority queue to store key-value pair is custom sorted format (as required in question)\n- Store the elements as required in array\n\n```\nclass Solution {\n public int[] frequencySort(int[] nums) {\n Map<Integer,Integer> map=new HashMap<>();\n Prior...
4
0
[]
3
sort-array-by-increasing-frequency
Java Solution Using HashMap
java-solution-using-hashmap-by-rohitm17-i0fz
\nclass Solution {\n public int[] frequencySort(int[] nums) {\n \n Map<Integer,Integer> map = new HashMap<>();\n \n int L = nums.
rohitm17
NORMAL
2021-06-17T17:41:03.004828+00:00
2021-06-17T17:41:03.004875+00:00
1,075
false
```\nclass Solution {\n public int[] frequencySort(int[] nums) {\n \n Map<Integer,Integer> map = new HashMap<>();\n \n int L = nums.length;\n\t\t\n\t\t//Store numbers with their occurences in Map\n\t\t\n for(int i=0;i<L;i++){\n if(!map.containsKey(nums[i])){\n ...
4
0
['Java']
2
sort-array-by-increasing-frequency
Python easy solution
python-easy-solution-by-nehakolambe15-qrp9
\n def frequencySort(self, nums: List[int]) -> List[int]:\n nums.sort(reverse=True)\n ans = sorted(nums, key = nums.count)\n return ans
nehakolambe15
NORMAL
2021-05-21T18:20:01.128596+00:00
2021-05-21T18:20:01.128620+00:00
334
false
\n def frequencySort(self, nums: List[int]) -> List[int]:\n nums.sort(reverse=True)\n ans = sorted(nums, key = nums.count)\n return ans
4
0
[]
0
sort-array-by-increasing-frequency
JAVA SIMPLE SOLUTION FASTER THAN 95%
java-simple-solution-faster-than-95-by-s-t4l1
JAVA CODE IS:\n# \n\nclass Solution {\n public int[] frequencySort(int[] nums) {\n Map<Integer,Integer>map=new HashMap<>();\n for(int val : nu
shivam_gupta_
NORMAL
2021-03-16T15:18:50.087132+00:00
2021-03-16T15:18:50.087195+00:00
502
false
JAVA CODE IS:\n# \n```\nclass Solution {\n public int[] frequencySort(int[] nums) {\n Map<Integer,Integer>map=new HashMap<>();\n for(int val : nums)\n map.put(val,map.getOrDefault(val,0)+1);\n PriorityQueue<int[]>pq=new PriorityQueue<>((a,b)->b[1]!=a[1] ? a[1]-b[1] : b[0]-a[0]);\n ...
4
0
[]
1
sort-array-by-increasing-frequency
Four golang solutions with explanation and images
four-golang-solutions-with-explanation-a-vq1i
The main idea of the first two solutions is to add all the numbers to a matrix of lengths [len(nums)][2] and then sort each frequency of numbers by the max freq
nathannaveen
NORMAL
2021-03-03T21:02:07.160757+00:00
2021-08-20T17:43:49.243697+00:00
246
false
The main idea of the first two solutions is to add all the numbers to a matrix of lengths `[len(nums)][2]` and then sort each frequency of numbers by the max frequency. Suppose two values have the same frequency sort them by the value in descending order. After they are sorted, add all the values back to `nums` and ret...
4
0
['Go']
0
sort-array-by-increasing-frequency
C++ sort unordered map
c-sort-unordered-map-by-orderofrootn-ergy
```\nclass Solution {\npublic:\n static bool comp(pair &a,pair &b)\n\t{\n if(a.second==b.second)\n return a.first>b.first;\n\t return a.
orderofrootn
NORMAL
2020-12-07T23:01:16.382715+00:00
2020-12-07T23:01:16.382750+00:00
936
false
```\nclass Solution {\npublic:\n static bool comp(pair<int,int> &a,pair<int,int> &b)\n\t{\n if(a.second==b.second)\n return a.first>b.first;\n\t return a.second<b.second;\n\t}\n vector<int> frequencySort(vector<int>& nums) {\n unordered_map<int,int> map{};\n for(auto n:nums)\n ...
4
1
['C', 'C++']
0
sort-array-by-increasing-frequency
Go solution using sort
go-solution-using-sort-by-sisigogo-fd8n
\nfunc frequencySort(nums []int) []int {\n freq := make(map[int]int)\n for _,v := range nums { freq[v] ++ }\n sort.Slice(nums, func (a,b int) bool {\n
sisigogo
NORMAL
2020-12-07T21:18:41.268946+00:00
2020-12-07T21:18:41.268990+00:00
213
false
```\nfunc frequencySort(nums []int) []int {\n freq := make(map[int]int)\n for _,v := range nums { freq[v] ++ }\n sort.Slice(nums, func (a,b int) bool {\n if freq[nums[a]] == freq[nums[b]] { return nums[a] > nums[b] }\n return freq[nums[a]] < freq[nums[b]]\n })\n return nums\n}\n```
4
0
['Go']
0
sort-array-by-increasing-frequency
Sort Array by Increasing Frequency 🙌📈.
sort-array-by-increasing-frequency-by-vi-76w8
Intuition\nWhen faced with the task of sorting elements based on their frequency, the first thought is to count how often each element appears. Once we know the
vivek_bhurke
NORMAL
2024-07-23T16:47:45.241233+00:00
2024-07-23T16:47:45.241267+00:00
828
false
# Intuition\nWhen faced with the task of sorting elements based on their frequency, the first thought is to count how often each element appears. Once we know the frequency, the problem becomes a matter of sorting based on these frequencies. If two elements have the same frequency, we then use their values to determine...
3
0
['Array', 'Hash Table', 'Java']
0
sort-array-by-increasing-frequency
C++||solution using heap||Easy solution
csolution-using-heapeasy-solution-by-bet-2gg8
Intuition\nAs we need to sort elements by their frequency,we can simply use priority queue to do so.\n\nBefore looking at the solution you can try solving https
betagamma
NORMAL
2024-07-23T12:19:37.867765+00:00
2024-07-23T12:19:37.867783+00:00
36
false
# Intuition\nAs we need to sort elements by their frequency,we can simply use priority queue to do so.\n\nBefore looking at the solution you can try solving https://leetcode.com/problems/sort-characters-by-frequency/ with priority queue to be more clear!!\n\n# Approach\nwe can customise cmp class to maintain max heap b...
3
0
['Hash Table', 'Heap (Priority Queue)', 'C++']
0
sort-array-by-increasing-frequency
Easy-to-follow..
easy-to-follow-by-nehasinghal032415-1vii
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
NehaSinghal032415
NORMAL
2024-07-23T09:04:01.657557+00:00
2024-07-23T09:04:01.657586+00:00
614
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(nlogn)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(2n)\n<!-- Add your space complexity here, e.g...
3
0
['Array', 'Hash Table', 'Sorting', 'Java']
0
count-almost-equal-pairs-ii
O(N^2) -> O(N * D^4) | Brute force digits diff comparison in Java (barely passes time constraints)
on2-on-d4-brute-force-digits-diff-compar-dz2v
Intuition\n Describe your first thoughts on how to solve this problem. \n\nSimilarly to 3265. Count Almost Equal Pairs I, we can check all pairs for almost-equa
sergey_chebotarev
NORMAL
2024-08-25T04:19:29.291206+00:00
2024-08-25T13:34:18.786926+00:00
2,332
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\nSimilarly to [3265. Count Almost Equal Pairs I](/problems/count-almost-equal-pairs-i/), we can check all pairs for almost-equality.\n\nTo keep equlality check fast we want to test only numbers with less than 4 different digits.\n\n**UPD...
19
0
['Java']
11
count-almost-equal-pairs-ii
Video Explanation (Optimising brute force solution using pre-computation)
video-explanation-optimising-brute-force-l2mn
Explanation\n\nClick here for the video\n\n# Code\ncpp []\nconst int N = 1e7;\nint cnt[N];\n\nclass Solution {\n \n inline int MakeNumber (vector<int>& di
codingmohan
NORMAL
2024-08-25T12:46:01.679521+00:00
2024-08-25T12:46:01.679562+00:00
781
false
# Explanation\n\n[Click here for the video](https://youtu.be/t_1vwZbUmzI)\n\n# Code\n```cpp []\nconst int N = 1e7;\nint cnt[N];\n\nclass Solution {\n \n inline int MakeNumber (vector<int>& digits) {\n int ans = 0;\n for (auto it = digits.rbegin(); it != digits.rend(); it ++)\n ans = (ans ...
18
0
['C++']
4
count-almost-equal-pairs-ii
[Python3] Brute Force
python3-brute-force-by-awice-j3ht
Let\'s write a function adj(int) -> set(int) that describes which y are possible to reach from x in at most 2 operations.\n\nNote we only need to care about swa
awice
NORMAL
2024-08-25T04:34:20.353954+00:00
2024-08-25T04:34:20.353979+00:00
693
false
Let\'s write a function `adj(int) -> set(int)` that describes which `y` are possible to reach from `x` in at most 2 operations.\n\nNote we only need to care about swaps in one direction if we sort the array.\n\n# Code\n```python3 []\nclass Solution:\n def countPairs(self, A: List[int]) -> int:\n def adj(x):\n...
14
0
['Python3']
3
count-almost-equal-pairs-ii
[Python3] find all neighbors via hashmap
python3-find-all-neighbors-via-hashmap-b-nspg
Find neighbors by one-pair swap. \nNumbers connected with two-pair swaps share neighbors. \n\n\nclass Solution:\n def countPairs(self, nums: List[int]) -> in
ye15
NORMAL
2024-08-25T04:17:34.261180+00:00
2024-08-25T04:17:34.261202+00:00
996
false
Find neighbors by one-pair swap. \nNumbers connected with two-pair swaps share neighbors. \n\n```\nclass Solution:\n def countPairs(self, nums: List[int]) -> int:\n cnt = Counter(nums)\n freq = defaultdict(list)\n for x, v in cnt.items(): \n freq[x].append((x, v))\n s = lis...
11
0
['Python3']
3
count-almost-equal-pairs-ii
Easy Brute force Solution | | C++
easy-brute-force-solution-c-by-loganblue-vie1
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
LOGANBLUE
NORMAL
2024-08-25T04:13:58.355368+00:00
2024-08-25T04:13:58.355399+00:00
2,017
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)$$ --...
10
1
['C++']
2
count-almost-equal-pairs-ii
Line by line explanation || Initial greedy + Prefix sum + All possible swaps || O(n^2) || Java
line-by-line-explanation-initial-greedy-fu2et
Go down to my code to see explanation line by line.\n\n# Approach\n- Sort the array ascending order to keep a greedy of not dealing with swapping trailing zero
Whusyki
NORMAL
2024-08-25T05:37:29.794977+00:00
2024-08-25T05:37:29.795002+00:00
526
false
# **Go down to my code to see explanation line by line.**\n\n# Approach\n- Sort the array ascending order to keep a greedy of not dealing with swapping trailing zero case.\n- During each iteration in the nums array, we build a prefix sum all elements in nums up to current element (exclusive). Then generate all possible...
9
0
['Java']
0
count-almost-equal-pairs-ii
Python 3 || 23 lines, dicts || T/S: 75% / 41%
python-3-23-lines-dicts-ts-75-41-by-spau-c033
python3 []\nclass Solution:\n def countPairs(self, nums: List[int]) -> int:\n\n def flip_ch(i: int, j: int)-> None:\n\n if num[i] == num[j]
Spaulding_
NORMAL
2024-08-25T20:06:16.227957+00:00
2024-08-28T04:22:39.814015+00:00
141
false
```python3 []\nclass Solution:\n def countPairs(self, nums: List[int]) -> int:\n\n def flip_ch(i: int, j: int)-> None:\n\n if num[i] == num[j]: return\n num[i], num[j] = num[j], num[i]\n\n s = \'\'.join(num)\n\n if next[s] < idx + 1:\n next[s] = idx ...
8
0
['Python3']
0
count-almost-equal-pairs-ii
2 Ways Detailed Description by C++ | Brute Force & Counting By Hash
2-ways-detailed-description-by-c-brute-f-ladq
Intuition\n Describe your first thoughts on how to solve this problem. \nTwo ways to slove the question.\n\n# Approach\n Describe your approach to solving the p
hsu_1997
NORMAL
2024-08-25T07:51:09.653491+00:00
2024-08-25T09:36:25.134030+00:00
511
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nTwo ways to slove the question.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. Check one by one.\n * Remove duplicates to get the smaller size of data first, any duplicates by n times we get n * (n-1) / 2 pa...
4
0
['C++']
2
count-almost-equal-pairs-ii
Java accepted, Python TLE
java-accepted-python-tle-by-chitraksh24-zv8n
Code\njava []\nclass Solution {\n public int countPairs(int[] nums) {\n int ans = 0;\n\n for (int i = 0; i < nums.length; i++) {\n f
chitraksh24
NORMAL
2024-08-25T04:24:46.816280+00:00
2024-08-25T04:24:46.816304+00:00
201
false
# Code\n```java []\nclass Solution {\n public int countPairs(int[] nums) {\n int ans = 0;\n\n for (int i = 0; i < nums.length; i++) {\n for (int j = i + 1; j < nums.length; j++) {\n String a = String.valueOf(nums[i]);\n String b = String.valueOf(nums[j]);\n\n ...
4
0
['Java', 'Python3']
3
count-almost-equal-pairs-ii
Easy Code With Explanation Javascript and TypeScript
easy-code-with-explanation-javascript-an-nqo3
Intuition\n Describe your first thoughts on how to solve this problem. \nTo solve the problem of counting pairs (i, j) in an array where the numbers are "almost
hashcoderz
NORMAL
2024-08-25T04:22:24.006665+00:00
2024-08-25T04:22:50.471850+00:00
60
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nTo solve the problem of counting pairs (i, j) in an array where the numbers are "almost equal," we need to identify pairs where one number can be converted to the other by swapping up to two pairs of digits. Given that this is a combinato...
4
0
['TypeScript']
0
count-almost-equal-pairs-ii
C++ DFS Solution
c-dfs-solution-by-kailam11223-a6j3
Approach\n Describe your approach to solving the problem. \nBasically, dfs the possible swap of each number and increase the count of each visited number. \n\n#
kailam11223
NORMAL
2024-08-25T10:28:05.456499+00:00
2024-08-25T10:28:05.456534+00:00
275
false
# Approach\n<!-- Describe your approach to solving the problem. -->\nBasically, dfs the possible swap of each number and increase the count of each visited number. \n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n$$O(7C2 * 7C2 * n)$$\n\nEach number can expand to 7C2 number(co...
3
0
['C++']
0
count-almost-equal-pairs-ii
Beats 100% users || Java || Very Easy Code
beats-100-users-java-very-easy-code-by-d-j4m8
Intuition\nThe problem is to determine how many pairs of numbers in the array can become equal by performing at most two digit swaps on one of the numbers in ea
dhruvbansal153
NORMAL
2024-08-25T04:12:17.225064+00:00
2024-08-25T04:12:17.225082+00:00
655
false
# Intuition\nThe problem is to determine how many pairs of numbers in the array can become equal by performing at most two digit swaps on one of the numbers in each pair. To solve this, we need to:\n\nIdentify Mismatches: Determine the positions where the digits of two numbers differ.\nCheck Swapping Possibilities: Dep...
3
0
['Java']
1
count-almost-equal-pairs-ii
💥💥 Beats 100% on runtime and memory [EXPLAINED]
beats-100-on-runtime-and-memory-explaine-6ea1
IntuitionIdentify pairs of numbers in the array that can be made identical by swapping digits up to twice. Since the operation allows swapping digits in each nu
r9n
NORMAL
2025-02-04T02:41:56.169210+00:00
2025-02-04T02:41:56.169210+00:00
6
false
# Intuition Identify pairs of numbers in the array that can be made identical by swapping digits up to twice. Since the operation allows swapping digits in each number, I’ll explore all possible permutations of digits in each number. If two numbers can be made the same after swaps, we count them as a valid pair. # App...
1
0
['Array', 'Hash Table', 'Math', 'String Matching', 'Combinatorics', 'Hash Function', 'Kotlin']
0
count-almost-equal-pairs-ii
Intuitive | generating atmost 2 swaps with optimised recursion
intuitive-generating-atmost-2-swaps-with-iy6o
IntuitionTry to use the generalised generate_atmost_swaps recursive function to generate almost equal numbers for a given number. Use the frequency of each numb
lokeshwar777
NORMAL
2025-01-14T11:12:52.947299+00:00
2025-01-14T11:28:21.967876+00:00
52
false
# Intuition Try to use the generalised `generate_atmost_swaps` recursive function to generate almost equal numbers for a given number. Use the frequency of each number for counting number of almost equal pairs. # Approach I've got TLE when i used the recursive function directly so i tweaked it to prevent a few redunda...
1
0
['Hash Table', 'String', 'Recursion', 'String Matching', 'Combinatorics', 'Counting', 'Ordered Set', 'C++', 'Python3']
0
count-almost-equal-pairs-ii
Easiest Solution To ever exist !!!
easiest-solution-to-ever-exist-by-shadan-u175
Intuition\n Describe your first thoughts on how to solve this problem. \nThink about forming all possiblities.\nSee We can perform atmost 2 swaps so form all po
shadan12
NORMAL
2024-08-27T06:04:19.399867+00:00
2024-08-27T06:04:19.399898+00:00
92
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThink about forming all possiblities.\nSee We can perform atmost 2 swaps so form all possible numbers which you can by performing 2 swaps ,\nUse strings to handle data easily\nand then for each possiblity check if it has already occured o...
1
0
['Array', 'Hash Table', 'Combinatorics', 'Ordered Set', 'C++']
2
count-almost-equal-pairs-ii
Python O(N*7^4) = O(2400N) by computing all possible neighbors
python-on74-o2400n-by-computing-all-poss-hkrx
For each n in nums, find all possible neighbors by doing all possible double swaps. (This is a quartic loop BUT the limit of each loop is 7, so it becomes O(24
dkravitz78
NORMAL
2024-08-25T19:51:29.221856+00:00
2024-08-25T19:53:39.704765+00:00
18
false
For each `n` in `nums`, find all possible neighbors by doing all possible double swaps. (This is a quartic loop BUT the limit of each loop is 7, so it becomes `O(2400N)` complexity since `7^4=2401`).\nKeep track of every number seen already (simple hashmap/counter).\nThen for each `n` in `nums`, put `n`, all single sw...
1
0
[]
0
count-almost-equal-pairs-ii
Easy Solution in c++
easy-solution-in-c-by-luv_mathur-npnn
\n\n# Code\ncpp []\nclass Solution {\npublic:\n \n vector<string> generateSwappedNumbers(string numstr) {\n vector<string> swappedNumbers;\n
Luv_Mathur
NORMAL
2024-08-25T13:27:03.877561+00:00
2024-08-25T13:27:03.877596+00:00
58
false
\n\n# Code\n```cpp []\nclass Solution {\npublic:\n \n vector<string> generateSwappedNumbers(string numstr) {\n vector<string> swappedNumbers;\n int n = numstr.size();\n swappedNumbers.push_back(numstr); \n \n if (n == 1) {\n return swappedNumbers;\n }\n ...
1
0
['C++']
0
count-almost-equal-pairs-ii
Very Easy Solution in c++
very-easy-solution-in-c-by-luv_mathur-qo3i
\n\n# Code\ncpp []\nclass Solution {\npublic:\n \n vector<string> generateSwappedNumbers(string numstr) {\n vector<string> swappedNumbers;\n
Luv_Mathur
NORMAL
2024-08-25T13:25:55.851962+00:00
2024-08-25T13:25:55.851987+00:00
38
false
\n\n# Code\n```cpp []\nclass Solution {\npublic:\n \n vector<string> generateSwappedNumbers(string numstr) {\n vector<string> swappedNumbers;\n int n = numstr.size();\n swappedNumbers.push_back(numstr); \n \n if (n == 1) {\n return swappedNumbers;\n }\n ...
1
0
['C++']
0
count-almost-equal-pairs-ii
Why N*N solution giving TLE explained ,How to get rid of TLE with n*n Solution.
why-nn-solution-giving-tle-explained-how-yqq1
Intuition\nHere We have to reduce the number of Operations , as much as Possible.\n Describe your first thoughts on how to solve this problem. \n\n# Approach\nH
swayam_wish
NORMAL
2024-08-25T09:59:55.118398+00:00
2024-08-25T10:07:59.900764+00:00
166
false
# Intuition\nHere We have to reduce the number of Operations , as much as Possible.\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nHere the N=5000 , Therefore if your solution is having N*N , you are considering to pass the Testcase , but the thing to be noticed is that, N*N = 2.5 *...
1
0
['C++']
0
count-almost-equal-pairs-ii
[Python3] Simple Solution | Time: O(N * maxLength^4) | Space: O(N)
python3-simple-solution-time-on-maxlengt-hhew
Intuition\n Describe your first thoughts on how to solve this problem. \nWe want to keep track of the count of numbers we\'ve already checked. For the current n
tesfaya
NORMAL
2024-08-25T06:51:28.736458+00:00
2024-08-26T04:27:08.290902+00:00
51
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWe want to keep track of the count of numbers we\'ve already checked. For the current number we are checking, we want to try every single possible swapping of digits, while ensuring we don\'t try duplicate swappings. Then we increase our ...
1
0
['Python3']
0
count-almost-equal-pairs-ii
Easy solution Java
easy-solution-java-by-jangir_yashraj-h19d
\n# Approach\ncount number of unequal pairs and reject if unequal pairs are more than 4 otherwise handle separately for 4,3 or 2 pairs.\n\n# Complexity\n- Time
jangir_yashraj
NORMAL
2024-08-25T06:49:33.543467+00:00
2024-08-25T06:49:33.543494+00:00
66
false
\n# Approach\ncount number of unequal pairs and reject if unequal pairs are more than 4 otherwise handle separately for 4,3 or 2 pairs.\n\n# Complexity\n- Time complexity:\n $$O(n^2)$$\n\n- Space complexity:\n $$O(1)$$ \n\n# Code\n```java []\nclass Solution {\n public int countPairs(int[] nums) {\n int cnt=...
1
0
['Java']
1
count-almost-equal-pairs-ii
Easy Hash map solution (search all the formations)
easy-hash-map-solution-search-all-the-fo-3uom
Intuition\nAs the maximum digits which can be there are 7 as (nums[i] < 10^7)\nthe count of maximum numbers we can form after two swaps are C(n,2) \times C(n,2
Abhishek_exe
NORMAL
2024-08-25T05:14:43.975284+00:00
2024-08-25T05:14:43.975323+00:00
348
false
# Intuition\nAs the maximum digits which can be there are $$7$$ as ($$nums[i] < 10^7$$)\nthe count of maximum numbers we can form after two swaps are $$C(n,2) \\times C(n,2)$$\nwhich will always be less than $$(21 \\times 21)$$\n\nso we can search if the formed number can be found in the array or not\n\n# Approach\n\n...
1
0
['Hash Table', 'Sorting', 'C++']
0
count-almost-equal-pairs-ii
Simple solution
simple-solution-by-4di03-nal8
\n# Code\npython3 []\ndef get_all_nums(num, swaps_left, to_be_paired, seen): # get all nums creatabel from num that are in the set of pairs that can be matched\
4di03
NORMAL
2024-08-25T04:59:35.840303+00:00
2024-08-25T04:59:35.840325+00:00
34
false
\n# Code\n```python3 []\ndef get_all_nums(num, swaps_left, to_be_paired, seen): # get all nums creatabel from num that are in the set of pairs that can be matched\n #O(N^5), N = 7\n if swaps_left == 0:\n num_int = int("".join(num))\n #print("L5", num_int)\n if num_int in to_be_paired and nu...
1
0
['Python3']
0
count-almost-equal-pairs-ii
Simple brute force
simple-brute-force-by-warlu-wm7p
Intuition\n Describe your first thoughts on how to solve this problem. \nFind all the possible numbers that can be obtained from each nums[i]\nand check with ot
WARLU
NORMAL
2024-08-25T04:07:17.875978+00:00
2024-08-25T04:07:17.876007+00:00
398
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nFind all the possible numbers that can be obtained from each nums[i]\nand check with other numbers in nums\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nConvert the nums to an hashmap\nIterate through the nums an...
1
0
['C++']
1
count-almost-equal-pairs-ii
Simple brute force, C++
simple-brute-force-c-by-jerry5841314-nym9
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
jerry5841314
NORMAL
2024-08-25T04:07:10.132381+00:00
2024-08-25T04:07:10.132415+00:00
173
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
1
['C++']
2
count-almost-equal-pairs-ii
checkPair-2 || C++.
checkpair-2-c-by-rishiinsane-a481
IntuitionWe need to count the pairs of numbers in a list that can become identical by swapping exactly two digits within the numbers, for that we need t to tran
RishiINSANE
NORMAL
2025-02-04T17:39:07.499105+00:00
2025-02-04T17:39:07.499105+00:00
6
false
# Intuition We need to count the pairs of numbers in a list that can become identical by swapping exactly two digits within the numbers, for that we need t to transform each number into a string of uniform length by padding with zeros, and then generate all possible variants of the number obtained by swapping two digit...
0
0
['C++']
0
count-almost-equal-pairs-ii
C++ brute force
c-brute-force-by-dongdang7777-dhad
IntuitionApproachComplexity Time complexity: n*digit^4 Space complexity: Code
dongdang7777
NORMAL
2024-12-25T06:45:19.944024+00:00
2024-12-25T06:45:19.944024+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: n*digit^4 - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code ```cpp [] class Solution { public: unorde...
0
0
['C++']
0
count-almost-equal-pairs-ii
Brute Force w/ optimizations
brute-force-w-optimizations-by-ivangnilo-7ofz
IntuitionThe key insight is that two numbers are "almost equal" if we can make them equal by swapping digits within one number up to 2 times. Therefore, for eac
ivangnilomedov
NORMAL
2024-12-21T16:11:51.747310+00:00
2024-12-21T16:11:51.747310+00:00
6
false
# Intuition The key insight is that two numbers are "almost equal" if we can make them equal by swapping digits within one number up to 2 times. Therefore, for each number, we need to generate all possible permutations achievable with ≤2 swaps and check if any previous numbers could match them. # Approach 1. Process n...
0
0
['C++']
0
count-almost-equal-pairs-ii
Solution
solution-by-teut-zetp
IntuitionImproved code for existing solution. Just generate all strings that can be made by swapping at most twice for each num. Count map stores the count of a
teut
NORMAL
2024-12-16T07:09:40.718201+00:00
2024-12-16T07:13:39.500390+00:00
4
false
# Intuition\nImproved code for existing solution. \nJust generate all strings that can be made by swapping at most twice for each num.\nCount map stores the count of a number.\nWe add the counts of each neighbour to total. Why?\nSo, at each step you are adding increasing the count of a num present in ""nums"" only and ...
0
0
['Python3']
0
count-almost-equal-pairs-ii
Permutation Set Intersections, Sliding Window | O(𝑛²+𝑛𝑚⁴), O(𝑛𝑚⁴) | 28.00%, 5.33%
permutation-set-intersections-sliding-wi-xamf
See brute force method used for a simpler variant of this problem in 3265. Count Almost Equal Pairs I where number of swaps is at most once.\n# Intuition\n Desc
Winoal875
NORMAL
2024-12-04T05:15:18.135475+00:00
2024-12-04T05:15:18.135503+00:00
6
false
*See brute force method used for a simpler variant of this problem in [3265. Count Almost Equal Pairs I](https://leetcode.com/problems/count-almost-equal-pairs-i/solutions/6110920/brute-force-o-o-35-77-96-50/) where number of swaps is at most once.*\n# Intuition\n<!-- Describe your first thoughts on how to solve this p...
0
0
['Sliding Window', 'Combinatorics', 'Counting', 'Python3']
0
count-almost-equal-pairs-ii
Generate swaps for each and check.
generate-swaps-for-each-and-check-by-til-rek3
Key takeaway is to sort the array in descending order because we can swap the digits of bigger number to get the smaller number but not vice versa.\n\nIn the ge
Tilak27
NORMAL
2024-11-04T19:48:26.175668+00:00
2024-11-04T19:48:26.175734+00:00
7
false
Key takeaway is to sort the array in descending order because we can swap the digits of bigger number to get the smaller number but not vice versa.\n\nIn the getswap function I have used an unordered_set because duplicate numbers can be made from 1 swap and 2 swaps. \n\nIf the current nums[i] value is present in the ma...
0
0
['Array', 'Hash Table', 'Sorting', 'C++']
0
count-almost-equal-pairs-ii
Clean Python Solution
clean-python-solution-by-ramizdundar-jh9o
Code\npython3 []\nclass Solution:\n def countPairs(self, nums: List[int]) -> int:\n pten = [1, 10, 100, 1000, 10000, 100000, 1000000]\n\n def s
ramizdundar
NORMAL
2024-10-30T19:15:44.912851+00:00
2024-10-30T19:15:44.912875+00:00
5
false
# Code\n```python3 []\nclass Solution:\n def countPairs(self, nums: List[int]) -> int:\n pten = [1, 10, 100, 1000, 10000, 100000, 1000000]\n\n def swap(num, i, j):\n numi = (num // pten[i]) % 10\n numj = (num // pten[j]) % 10\n\n num += numi * (pten[j] - pten[i])\n ...
0
0
['Python3']
0
count-almost-equal-pairs-ii
C++ Solution with Explanation and Time Optimizations
c-solution-with-explanation-and-time-opt-kapq
Approach\nSame as other solutions. Important points:\n1. Think of 0 as a valid digit. Variations of "1" should include 10,100,1000,etc.\n2. Then, you can think
lilyx998
NORMAL
2024-09-25T05:26:10.625042+00:00
2024-09-25T05:26:10.625077+00:00
15
false
# Approach\nSame as other solutions. Important points:\n1. Think of 0 as a valid digit. Variations of "1" should include 10,100,1000,etc.\n2. Then, you can think of equality as symmetric. 1=10 and 10=1.\n3. (c++) Don\'t allocate dynamically sized things in the for loops. The `allOneSwapVariations` thing in the main Jav...
0
0
['C++']
0
count-almost-equal-pairs-ii
Optimized brute-force
optimized-brute-force-by-votrubac-3z3e
We count numbers using a hash map n.\n\nBut first, we generate valid permutatins (one or two swaps) for each number, and check if we have matches in the hash ma
votrubac
NORMAL
2024-09-03T07:23:04.444872+00:00
2024-09-03T07:54:58.956381+00:00
25
false
We count numbers using a hash map `n`.\n\nBut first, we generate valid permutatins (one or two swaps) for each number, and check if we have matches in the hash map. Note that we also need to de-duplicate permutations to avoid double-counting.\n\nNow, we want to make it as fast as possible:\n> The runtime limit for C++,...
0
0
['C']
0
count-almost-equal-pairs-ii
DP with enumeration clean code
dp-with-enumeration-clean-code-by-dmitri-wd4b
\nint countPairs(vector<int>& nums) {\n const int maxDigits = size(to_string(*ranges::max_element(nums)));\n vector<string> sNums;\n for (const auto v
dmitrii_bokovikov
NORMAL
2024-09-01T14:41:37.397854+00:00
2024-09-01T14:41:52.838851+00:00
11
false
```\nint countPairs(vector<int>& nums) {\n const int maxDigits = size(to_string(*ranges::max_element(nums)));\n vector<string> sNums;\n for (const auto v : nums) {\n const auto s = to_string(v);\n sNums.push_back(string(maxDigits - size(s), \'0\') + s);\n }\n\n int ans = 0;\n unordered_m...
0
0
['C++']
0
count-almost-equal-pairs-ii
🔥🔥🔥C++ | Step-Wise Approach Explained 🔥🔥🔥 | Counting Pairs with Two Swaps
c-step-wise-approach-explained-counting-0blqa
Approach\n\n### 1. Convert Numbers to Fixed-Length Strings\nTo compare numbers of different lengths, we convert each number into a fixed-length string by prepen
sauravchaudhary717
NORMAL
2024-08-31T18:57:04.628803+00:00
2024-08-31T18:57:04.628840+00:00
13
false
## Approach\n\n### 1. Convert Numbers to Fixed-Length Strings\nTo compare numbers of different lengths, we convert each number into a fixed-length string by prepending zeros. The length of the strings is determined by the number of digits in the largest number in the array.\n\n### 2. Generate All Possible Formations\nF...
0
0
['C++']
0
count-almost-equal-pairs-ii
Rusty approach using custom Numerals struct and duplicate counting.
rusty-approach-using-custom-numerals-str-j6uh
Intuition\n"Hey, this should be easy, right?" I mean, it\'s just like part 1 but with two swaps instead of one. How hard could it be? Famous last words. Turns o
jkoudys
NORMAL
2024-08-29T14:15:02.460811+00:00
2024-08-29T14:15:02.460851+00:00
11
false
# Intuition\n"Hey, this should be easy, right?" I mean, it\'s just like part 1 but with two swaps instead of one. How hard could it be? Famous last words. Turns out, adding that second swap opens up a world of pain, and what seemed like a minor tweak quickly snowballed into a full-blown headache.\n\n# Approach\nIf I\'m...
0
0
['Rust']
0
count-almost-equal-pairs-ii
Easy Brute force Solution C++ Code
easy-brute-force-solution-c-code-by-ibra-ico8
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
Ibrahim_Hassan
NORMAL
2024-08-29T12:58:17.754580+00:00
2024-08-29T12:58:17.754616+00:00
9
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-almost-equal-pairs-ii
Super simple java O(N*d^4) solution and explain
super-simple-java-ond4-solution-and-expl-nzq8
Intuition\n Describe your first thoughts on how to solve this problem. \nThe contraints were very tight, so a simple O(N^2) implementation might not work (thoug
vivekgpt107
NORMAL
2024-08-28T14:17:17.804039+00:00
2024-08-28T14:17:17.804070+00:00
11
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe contraints were very tight, so a simple O(N^2) implementation might not work (though it had for this problem). To solve this we need to think of a way to avoid the comparision between each pair of numbers, for this we should notice wh...
0
0
['Java']
0
count-almost-equal-pairs-ii
Hash Table
hash-table-by-azizkaz-fhoi
Intuition\n Describe your first thoughts on how to solve this problem. \n1) There exist maximum $21 \cdot 21$ combinations for each number from $nums$ array.\n\
azizkaz
NORMAL
2024-08-28T07:25:38.533720+00:00
2024-08-28T07:28:52.138092+00:00
6
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n1) There exist maximum $21 \\cdot 21$ combinations for each number from $nums$ array.\n\n2) It needs to use Hash Table to count almost equal pairs\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nHash Table\n\n# Com...
0
0
['Hash Table', 'Rust']
0
count-almost-equal-pairs-ii
Brute Force Using Map
brute-force-using-map-by-avatar_027-fg72
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
Avatar_027
NORMAL
2024-08-27T20:29:19.230964+00:00
2024-08-27T20:29:19.230995+00:00
15
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-almost-equal-pairs-ii
Brute Force || Beats 92% || Easy to understand || Maths || C++
brute-force-beats-92-easy-to-understand-skivp
Complexity\n- Time complexity:O(n * 8^4)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity:O(max(nums))\n Add your space complexity here, e.g. O
dubeyad2003
NORMAL
2024-08-27T16:25:15.956231+00:00
2024-08-27T16:25:15.956272+00:00
20
false
# Complexity\n- Time complexity:$$O(n * 8^4)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:$$O(max(nums))$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```cpp []\nclass Solution {\npublic:\n int countPairs(vector<int>& nums) {\n int maxi = *max_element(n...
0
0
['C++']
0
count-almost-equal-pairs-ii
One More Easier Solution | | C++
one-more-easier-solution-c-by-loganblue-uj0s
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
LOGANBLUE
NORMAL
2024-08-27T05:01:44.793685+00:00
2024-08-27T05:01:44.793719+00:00
16
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-almost-equal-pairs-ii
Brute force beating 93.2% in time
brute-force-beating-932-in-time-by-maxor-ppxn
Not much algorithm found in this question ..\n\nPerhaps the most subtle point is to convert the nums into a set to avoid duplicated calculation?\n\n# Code\npyth
MaxOrgus
NORMAL
2024-08-27T03:26:09.340833+00:00
2024-08-27T03:26:09.340853+00:00
20
false
Not much algorithm found in this question ..\n\nPerhaps the most subtle point is to convert the nums into a set to avoid duplicated calculation?\n\n# Code\n```python3 []\nclass Solution:\n def countPairs(self, nums: List[int]) -> int:\n possiblepair = {}\n \n res = 0\n nums = [str(n) for n...
0
0
['Python3']
0
count-almost-equal-pairs-ii
Hash Solution, C
hash-solution-c-by-fitran-pmca
Intuition\nTo solve the problem of finding pairs of "almost equal" numbers in the array, we can use a hash table. The idea is to generate all possible numbers t
Fitran
NORMAL
2024-08-26T18:10:40.391073+00:00
2024-08-28T12:03:08.164823+00:00
27
false
# Intuition\nTo solve the problem of finding pairs of "almost equal" numbers in the array, we can use a hash table. The idea is to generate all possible numbers that can be formed by swapping up to two pairs of digits in each number and check if they exist in the hash table. By storing previously encountered numbers in...
0
0
['Hash Table', 'String', 'C', 'Hash Function', 'C++', 'Java', 'Python3']
0
count-almost-equal-pairs-ii
Easier to understand Binary search & unordered map use
easier-to-understand-binary-search-unord-j1zi
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
kritimalik9
NORMAL
2024-08-26T18:04:12.826810+00:00
2024-08-26T18:04:12.826875+00:00
14
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-almost-equal-pairs-ii
Combination of pair Indexes.
combination-of-pair-indexes-by-wangtan83-hie0
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
wangtan83
NORMAL
2024-08-26T17:12:15.985789+00:00
2024-08-26T17:13:26.466008+00:00
8
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-almost-equal-pairs-ii
Simple Approach Explained!!✅💯🔥
simple-approach-explained-by-manibhushan-3l6k
\n# Complexity\n- Time complexity: O(n * maxSize^4)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(n * maxSize^2)\n Add your space complex
Manibhushan20
NORMAL
2024-08-26T15:04:12.178176+00:00
2024-08-26T15:04:12.178226+00:00
19
false
\n# Complexity\n- Time complexity: O(n * maxSize^4)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(n * maxSize^2)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```cpp []\nclass Solution {\npublic:\n // Variable to store the maximum number of digits among all numb...
0
0
['C++']
0
count-almost-equal-pairs-ii
Easy Java Solution
easy-java-solution-by-danish_jamil-gj30
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
Danish_Jamil
NORMAL
2024-08-26T07:27:34.460569+00:00
2024-08-26T07:27:34.460587+00:00
11
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-almost-equal-pairs-ii
CPP BEST SOLUTION
cpp-best-solution-by-shreyanshjain999-2046
C++ SOLUTION\n\nclass Solution {\npublic:\n string str(int digits,int num){\n int a=log10(num)+1;\n string s=to_string(num);\n for(int i
Shreyanshjain999
NORMAL
2024-08-26T06:55:08.488437+00:00
2024-08-26T06:55:08.488470+00:00
18
false
**C++ SOLUTION**\n\nclass Solution {\npublic:\n string str(int digits,int num){\n int a=log10(num)+1;\n string s=to_string(num);\n for(int i=0;i<digits-a;i++){\n s="0"+s;\n }\n return s;\n }\n unordered_set<string> cases(int digits,int num){\n string s=str(d...
0
0
['Greedy', 'C']
0
count-almost-equal-pairs-ii
c++() brute force
c-brute-force-by-zx007pi-w9ve
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
zx007pi
NORMAL
2024-08-26T06:45:22.337378+00:00
2024-08-27T16:44:29.704275+00:00
17
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-almost-equal-pairs-ii
CHECK MY SOLUTION 👇👇
check-my-solution-by-lokeshkumar_2106-adpo
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
lokeshkumar_2106
NORMAL
2024-08-26T05:06:00.905968+00:00
2024-08-26T05:06:00.905996+00:00
22
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-almost-equal-pairs-ii
[C++] Brutal Force
c-brutal-force-by-hesicheng20-zupl
Intuition\nThe key insight is to focus on the differences in their digit arrays and determine if these differences can be reconciled with the allowed swaps.\n\n
hesicheng20
NORMAL
2024-08-26T05:02:12.364170+00:00
2024-08-26T05:02:12.364206+00:00
25
false
# Intuition\nThe key insight is to focus on the differences in their digit arrays and determine if these differences can be reconciled with the allowed swaps.\n\n# Approach\n- **Preprocess Digits**: Convert each number in the array into an array of its digits for easier comparison.\n- **Check Almost Equal**: Implement ...
0
0
['C++']
0
count-almost-equal-pairs-ii
Python Solution
python-solution-by-krishna5972-mus8
Intuition\n Describe your first thoughts on how to solve this problem. \nTry to generate possible swaps a digit can lead to add up how many pairs are posible wi
krishna5972
NORMAL
2024-08-26T04:32:29.828110+00:00
2024-08-26T04:32:29.828140+00:00
41
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nTry to generate possible swaps a digit can lead to add up how many pairs are posible with the combination if the generated digit is available\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n$$O(...
0
0
['Python3']
1
count-almost-equal-pairs-ii
Beats 100% JAVA
beats-100-java-by-murariambofficial-dwbo
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
murariambofficial
NORMAL
2024-08-26T00:21:00.158829+00:00
2024-08-26T00:21:00.158859+00:00
16
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-almost-equal-pairs-ii
Java Brute Force, using map to group all the ones with same digits
java-brute-force-using-map-to-group-all-72exm
Intuition\n Describe your first thoughts on how to solve this problem. \nSince all the numbers are less than 10^7, so make all the number string with length = 7
realstar
NORMAL
2024-08-26T00:06:09.908738+00:00
2024-08-26T00:06:09.908763+00:00
8
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nSince all the numbers are less than 10^7, so make all the number string with length = 7, attach 0 in front to make them same length.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nUsing a hashmap, with key = sorte...
0
0
['Java']
0
count-almost-equal-pairs-ii
Easy Video Solution (Critical Thinking )🔥 || How to 🤔 in Interview || Simulation || String || JAVA
easy-video-solution-critical-thinking-ho-yzcz
Intuition\n# If you like the solution Please Upvote and subscribe to my youtube channel\n\n\n\n\n# EASY VIDEO EXPLANATION \n\n\nhttps://youtu.be/weYmUnmqwZ4\n\n
mmohit073
NORMAL
2024-08-25T20:16:31.293374+00:00
2024-08-25T20:16:31.293400+00:00
10
false
# Intuition\n# **If you like the solution Please Upvote and subscribe to my youtube channel**\n\n\n\n\n# EASY VIDEO EXPLANATION \n\n\nhttps://youtu.be/weYmUnmqwZ4\n\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...
0
0
['Math', 'String', 'Java']
0
count-almost-equal-pairs-ii
[Java] Enumerating all the possible neighbors
java-enumerating-all-the-possible-neighb-iqyt
Intuition\nAfter trying so many optimizations for the brute force approach, which tries to enumerate all the results after swapping nums[i] and nums[j], where i
deepanshu
NORMAL
2024-08-25T17:14:45.030422+00:00
2024-08-25T17:14:45.030458+00:00
1
false
# Intuition\nAfter trying so many optimizations for the brute force approach, which tries to enumerate all the results after swapping nums[i] and nums[j], where i < j and see if it matches takes $$O(N^2.D^4)$$, where D = number of digits in a nums[x]. There are multipe approaches which optimizes this approach as well.\...
0
0
['Java']
0
count-almost-equal-pairs-ii
Easy Java solution, no fancy things
easy-java-solution-no-fancy-things-by-ka-nuzx
Intuition\n Describe your first thoughts on how to solve this problem. \nGenerate all numbers which could be generated using swapping 0, 1 or 2 times and add th
kartikeysemwal
NORMAL
2024-08-25T15:11:07.399787+00:00
2024-08-25T15:11:07.399831+00:00
15
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nGenerate all numbers which could be generated using swapping 0, 1 or 2 times and add them to hashmap with freq. For the current number, check how many times it previously was seen and add it to answer.\n\n# Code\n```java []\nclass Solutio...
0
0
['Java']
0
count-almost-equal-pairs-ii
My Solution
my-solution-by-hope_ma-0k60
\n/**\n * Time Complexity: O(n * log(n) + n * (log(max_num) ^ 4))\n * Space Complexity: O(n_characters)\n * where `n` is the length of the vector `nums`\n *
hope_ma
NORMAL
2024-08-25T13:17:53.922400+00:00
2024-08-25T16:30:19.861166+00:00
2
false
```\n/**\n * Time Complexity: O(n * log(n) + n * (log(max_num) ^ 4))\n * Space Complexity: O(n_characters)\n * where `n` is the length of the vector `nums`\n * `max_num` is the maximum number of the vector `nums`\n * `n_characters` is the number of the characters\n * of the string re...
0
0
[]
0
count-almost-equal-pairs-ii
Rust Solution
rust-solution-by-xiaoping3418-17qc
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
xiaoping3418
NORMAL
2024-08-25T12:29:02.884486+00:00
2024-08-25T12:29:02.884508+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
['Rust']
0
count-almost-equal-pairs-ii
Intuitive solution though C++
intuitive-solution-though-c-by-informal0-gh4m
Intuition\nCalculate every value for every element in nums after swap at most twice, after that, you can get the number of element with same value within time c
informal007
NORMAL
2024-08-25T11:34:49.661485+00:00
2024-08-25T12:22:36.019017+00:00
2
false
# Intuition\nCalculate every value for every element in nums after swap at most twice, after that, you can get the number of element with same value within time complexity O(logN) using [multiset](https://en.cppreference.com/w/cpp/container/multiset)\n\n# Approach\nThe solution is intuitive. But several tips are worth ...
0
0
['C++']
0
count-almost-equal-pairs-ii
ONLY SUGGESTION : This problem has a very tight time constraint!!
only-suggestion-this-problem-has-a-very-pth2x
Intuition\n Describe your first thoughts on how to solve this problem. \nFor each element calculate all the elements that could be created using two swaps of di
roshanbangar
NORMAL
2024-08-25T10:33:06.521364+00:00
2024-08-25T10:33:06.521405+00:00
47
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nFor each element calculate all the elements that could be created using two swaps of digits. Rest of the comments in the code. \n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nPlease check the comments. \n\n# Compl...
0
0
['C++']
0
count-almost-equal-pairs-ii
Easy C++ Code with Comments for better understanding.
easy-c-code-with-comments-for-better-und-31ix
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
spidycoder178
NORMAL
2024-08-25T09:49:52.270465+00:00
2024-08-25T09:49:52.270509+00:00
32
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^2)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(...
0
0
['C++']
0
count-almost-equal-pairs-ii
😂There's NO N*M^4 solution ,Passed N*M^5
theres-no-nm4-solution-passed-nm5-by-sam-n7gz
Reason\n Describe your first thoughts on how to solve this problem. \nall of u will have ignored complexity of either comparing string or inserting numbers of s
sameonall
NORMAL
2024-08-25T09:49:17.004179+00:00
2024-08-27T16:09:36.402697+00:00
22
false
# Reason\n<!-- Describe your first thoughts on how to solve this problem. -->\nall of u will have ignored complexity of either comparing string or inserting numbers of string into a set or interconversion, which is basically O(length of the string)\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\...
0
0
['C++']
0
count-almost-equal-pairs-ii
Brute Force || O(N*7*7*7*7)
brute-force-on7777-by-ameynaik09-4q9e
Intuition\n Describe your first thoughts on how to solve this problem. \nFor each number take a hashmap of all the values that can be formed by applying either
ameynaik09
NORMAL
2024-08-25T09:11:54.946904+00:00
2024-08-25T09:11:54.946933+00:00
49
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nFor each number take a hashmap of all the values that can be formed by applying either one or two operations. Then simaltaneously check all that values whether have occured in the nums till now if yes add their freq to your main ans. \n\n...
0
0
['C++']
0
count-almost-equal-pairs-ii
Simple and easy solution (100% memory and time beats)
simple-and-easy-solution-100-memory-and-ikd52
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
Meet_Khanpara
NORMAL
2024-08-25T08:02:51.074958+00:00
2024-08-25T08:02:51.074997+00:00
27
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^2)\n\n# Code\n```java []\nclass Solution {\n public boolean ist(int a, int b) {\n String s = Integer.toString(a);\n ...
0
0
['String', 'Java']
0
count-almost-equal-pairs-ii
JAVA || Faster than 100% || Intuitive Approach || Extending the easir variant code ||
java-faster-than-100-intuitive-approach-y7xyc
Intuition\n Describe your first thoughts on how to solve this problem. \nIntuition was keeping track of indexes where corresponding values in num1 and num2 has
ManjeetYadav36
NORMAL
2024-08-25T06:52:47.142203+00:00
2024-08-25T06:52:47.142241+00:00
25
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nIntuition was keeping track of indexes where corresponding values in num1 and num2 has a mismatch.\nIn easier variant when only one swap was allowed, if we have exactly 2 pairs of such indexes, we can check whether they can be wapped to m...
0
0
['Java']
0
count-almost-equal-pairs-ii
Python || 100% Beats || Simple solution
python-100-beats-simple-solution-by-vila-7ari
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
vilaparthibhaskar
NORMAL
2024-08-25T06:41:15.534751+00:00
2024-08-25T06:41:15.534789+00:00
37
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
['Hash Table', 'Python3']
0
count-almost-equal-pairs-ii
Trie fun
trie-fun-by-kamanashisroy-sfdz
Intuition\nIf a is matching with b, then be is matching with a too. \nSo if we calculate all matches (a,b and b,a)and then divide by 2, we get the result.\n\nTo
kamanashisroy
NORMAL
2024-08-25T06:16:26.477897+00:00
2024-08-25T06:16:26.477929+00:00
59
false
# Intuition\nIf a is matching with b, then be is matching with a too. \nSo if we calculate all matches (a,b and b,a)and then divide by 2, we get the result.\n\nTo reduce the branches while searching we can use trie . We can put the original values in the nums in the trie first.\n\nNow during the exploration of the swap...
0
0
['Python3']
1
count-almost-equal-pairs-ii
Java Passes beats 100% but same code TLE in C++
java-passes-beats-100-but-same-code-tle-5m34k
Complexity\n- Time complexity: O(n^2 * 7) \n\n- Space complexity: O(1) \n\nC++ []\n// TLE 625/630 same logic passes in Java\nclass Solution {\npublic:\n int
nitinsrichakri
NORMAL
2024-08-25T05:39:52.801032+00:00
2024-08-25T05:39:52.801068+00:00
12
false
# Complexity\n- Time complexity: $$O(n^2 * 7)$$ \n\n- Space complexity: $$O(1)$$ \n\n``` C++ []\n// TLE 625/630 same logic passes in Java\nclass Solution {\npublic:\n int countPairs(vector<int>& a) {\n int n=a.size(),ans=0;\n for(int i=0;i<n;i++){\n for(int j=i+1;j<n;j++)\n {\n ...
0
0
['Java']
0
count-almost-equal-pairs-ii
hehehehehe
hehehehehe-by-priyanshu_gupta_9620-6zls
Code\ncpp []\nclass Solution {\npublic:\n string tostg(int a){\n string ans="";\n while(a){\n ans+=(\'0\'+(a%10));\n a/=1
Priyanshu_gupta_9620
NORMAL
2024-08-25T05:33:23.143757+00:00
2024-08-25T05:33:23.143774+00:00
84
false
# Code\n```cpp []\nclass Solution {\npublic:\n string tostg(int a){\n string ans="";\n while(a){\n ans+=(\'0\'+(a%10));\n a/=10;\n }\n return ans;\n }\n int countPairs(vector<int>& nums) {\n map<int,int> mp;\n vector<string> v;\n int maxi=*...
0
0
['C++']
0
count-almost-equal-pairs-ii
Java HashMap Sort
java-hashmap-sort-by-mot882000-1ljj
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
mot882000
NORMAL
2024-08-25T05:18:43.705970+00:00
2024-08-25T05:18:43.705999+00:00
33
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
['Hash Table', 'Sorting', 'Java']
0
count-almost-equal-pairs-ii
Java HashMap Sort
java-hashmap-sort-by-mot882000-2r4x
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
mot882000
NORMAL
2024-08-25T05:16:12.729398+00:00
2024-08-25T05:16:12.729419+00:00
17
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
['Hash Table', 'Sorting', 'Java']
0
count-almost-equal-pairs-ii
Easy Solution :)
easy-solution-by-user20222-8iih
Code\ncpp []\nclass Solution {\npublic:\n int countPairs(vector<int>& nums) {\n int n = nums.size();\n int count = 0;\n unordered_map<in
user20222
NORMAL
2024-08-25T05:13:50.632226+00:00
2024-08-25T05:13:50.632258+00:00
66
false
# Code\n```cpp []\nclass Solution {\npublic:\n int countPairs(vector<int>& nums) {\n int n = nums.size();\n int count = 0;\n unordered_map<int,int>mp;\n for(auto&it:nums)mp[it]++; \n vector<vector<int>> pos(n);\n for (int i = 0; i < n; ++i) {\n pos[i] = f(nums[i])...
0
0
['C++']
0
count-almost-equal-pairs-ii
Bruteforce Rust
bruteforce-rust-by-do7and-phvk
\n# Complexity\n- Time complexity:O(n^2)\n Add your time complexity here, e.g. O(n) \n\n\n# Code\nrust []\n\nimpl Solution {\n pub fn count_pairs(nums: Vec<i
do7and
NORMAL
2024-08-25T05:03:53.843169+00:00
2024-08-25T05:03:53.843197+00:00
18
false
\n# Complexity\n- Time complexity:$$O(n^2)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n\n# Code\n```rust []\n\nimpl Solution {\n pub fn count_pairs(nums: Vec<i32>) -> i32 {\n fn check(mut a:i32,mut b:i32)-> bool {\n if (a == b) {return true;}\n let mut flag = 0;\n ...
0
0
['Rust']
0
count-almost-equal-pairs-ii
Almost linear python solution : O(N) * (7^4)
almost-linear-python-solution-on-74-by-u-x5dv
Intuition\n Describe your first thoughts on how to solve this problem. \nFirst you need to zfill all nums to max num len.\n\nWe are going to create all posible
utkarshkolhe
NORMAL
2024-08-25T05:01:41.833403+00:00
2024-08-25T05:01:41.833422+00:00
57
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nFirst you need to zfill all nums to max num len.\n\nWe are going to create all posible 2 level swaps which would be at most 7^4. because number is less than 10^7.\n\nWe then go reverse on our nums array creating counter dictionary and for...
0
0
['Python3']
0
count-almost-equal-pairs-ii
Sometimes brute force works.
sometimes-brute-force-works-by-jccccc-pujf
Intuition\n Describe your first thoughts on how to solve this problem. \nCheck each pair with brute force. Not a fancy solution though.\n# Approach\n Describe y
jccccc
NORMAL
2024-08-25T04:47:38.110780+00:00
2024-08-25T04:47:38.110799+00:00
26
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nCheck each pair with brute force. Not a fancy solution though.\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n- Time complexity:$$O(n^2)$$\n\n- Space complexity:$$O(1)$$\n\n# Code\n```java []\nclass Solution {\n ...
0
0
['Java']
0
count-almost-equal-pairs-ii
Works in Java, TLE in python, super simple solution.
works-in-java-tle-in-python-super-simple-f6l5
Intuition\nThe hint given after the contest was the intuiton.\n\n# Code\njava []\nimport java.util.*;\n\nclass Solution {\n public HashSet<Integer> get_possi
Mudit-B
NORMAL
2024-08-25T04:44:51.493118+00:00
2024-08-25T04:45:44.215672+00:00
24
false
# Intuition\nThe hint given after the contest was the intuiton.\n\n# Code\n```java []\nimport java.util.*;\n\nclass Solution {\n public HashSet<Integer> get_possible_integers(int num) {\n HashSet<Integer> possibleSwaps = new HashSet<>();\n // find out all the possible combination of swaps\n poss...
0
0
['Java', 'Python3']
0
count-almost-equal-pairs-ii
Fastest Solution in C++, Java, and Python
fastest-solution-in-c-java-and-python-by-l5l6
Credit:\nSpecial thanks to bilyhurington for his c++ solution which derives the other forms.\n\n# Code\nc++ []\nclass Solution {\npublic:\n const int L=7;\n
20250309.retired_account
NORMAL
2024-08-25T04:40:44.867091+00:00
2024-08-25T04:40:44.867116+00:00
115
false
# Credit:\nSpecial thanks to [bilyhurington](https://leetcode.com/u/bilyhurington) for his c++ solution which derives the other forms.\n\n# Code\n```c++ []\nclass Solution {\npublic:\n const int L=7;\n int countPairs(vector<int>& nums) {\n int n=nums.size();\n unordered_map<string,int> mp,id;\n ...
0
0
['Python', 'C++', 'Java', 'Python3']
0
count-almost-equal-pairs-ii
Simple Brute force Solution
simple-brute-force-solution-by-ankuraj_2-cc6z
Code\ncpp []\nclass Solution {\npublic:\n unordered_set<int> f(int a) {\n unordered_set<int> st;\n string s=to_string(a);\n for(int i=0;
ankuraj_27
NORMAL
2024-08-25T04:35:57.660293+00:00
2024-08-25T04:35:57.660342+00:00
60
false
# Code\n```cpp []\nclass Solution {\npublic:\n unordered_set<int> f(int a) {\n unordered_set<int> st;\n string s=to_string(a);\n for(int i=0;i<s.size();i++) {\n for(int j=i+1;j<s.size();j++) {\n string temp=s;\n swap(temp[i],temp[j]);\n st....
0
0
['C++']
0
count-almost-equal-pairs-ii
Java || 100% Beats
java-100-beats-by-vilaparthibhaskar-st0z
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
vilaparthibhaskar
NORMAL
2024-08-25T04:18:55.839731+00:00
2024-08-25T04:18:55.839750+00:00
29
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-almost-equal-pairs-ii
Optimizing the brute force O(n*n) approach
optimizing-the-brute-force-onn-approach-xgkz8
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \nWorking around the time
Amit_Aswal
NORMAL
2024-08-25T04:18:11.602084+00:00
2024-08-25T04:18:11.602112+00:00
36
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nWorking around the time limit by sorting the array and using the previous result \n\n# Complexity\n- Time complexity:\n- O(N*N)\n<!-- Add your time complexity here, e....
0
0
['Java']
0
count-almost-equal-pairs-ii
Easy Map Solution
easy-map-solution-by-kvivekcodes-7sll
Starting from beginning, use one and two swaps and then see if rearranged numbers are present or not.\nTo avoid overcounting just maintain of count of numbers o
kvivekcodes
NORMAL
2024-08-25T04:15:47.531787+00:00
2024-08-25T04:15:47.531813+00:00
33
false
Starting from beginning, use one and two swaps and then see if rearranged numbers are present or not.\nTo avoid overcounting just maintain of count of numbers of ending numbers only.\n\n# Code\n```cpp []\nclass Solution {\npublic:\n int countPairs(vector<int>& nums) {\n int n = nums.size();\n\n int ans...
0
0
['C++']
0
count-almost-equal-pairs-ii
Short solution [Python3]
short-solution-python3-by-timetoai-xrmv
Approach\nProblem is as simple as count equal numbers pairs, just do this with permutations.\n\ngo function generates all possible permutations within 2 steps.\
timetoai
NORMAL
2024-08-25T04:09:29.714078+00:00
2024-08-25T04:09:29.714108+00:00
27
false
# Approach\nProblem is as simple as count equal numbers pairs, just do this with permutations.\n\n`go` function generates all possible permutations within 2 steps.\n\n# Code\n```python3 []\nclass Solution:\n def countPairs(self, nums: List[int]) -> int:\n @cache\n def go(num):\n cur = [list(...
0
0
['Python3']
0
count-almost-equal-pairs-ii
Beats 100% java users
beats-100-java-users-by-aditya_vish-k13z
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
aditya_vish
NORMAL
2024-08-25T04:07:16.423153+00:00
2024-08-25T04:07:16.423183+00:00
16
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-almost-equal-pairs-ii
Easy || C++ || Brute force Code
easy-c-brute-force-code-by-raven572-fir5
Intuition\n Describe your first thoughts on how to solve this problem. \nSimple brute solution using set and map\n\n# Approach\n Describe your approach to solvi
raven572
NORMAL
2024-08-25T04:04:38.434491+00:00
2024-08-25T04:04:38.434525+00:00
180
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nSimple brute solution using set and map\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 you...
0
0
['C++']
0
count-almost-equal-pairs-ii
Python Hard
python-hard-by-lucasschnee-is13
python3 []\nclass Solution:\n def countPairs(self, nums: List[int]) -> int:\n N = len(nums)\n \n lookup = defaultdict(int)\n \n
lucasschnee
NORMAL
2024-08-25T04:04:12.504704+00:00
2024-08-25T04:04:12.504729+00:00
39
false
```python3 []\nclass Solution:\n def countPairs(self, nums: List[int]) -> int:\n N = len(nums)\n \n lookup = defaultdict(int)\n \n \n \n mx = 0\n \n total = 0\n \n for i in range(N):\n nums[i] = str(nums[i])\n mx = max(...
0
0
['Python3']
0
count-almost-equal-pairs-ii
Counting Almost Equal Pairs with Double Swap in a List | coderkb
counting-almost-equal-pairs-with-double-lw230
Intuition\nTo count pairs of integers in an array that become equal when two digits are swapped at most twice, we can generate all possible numbers by performin
coderkb
NORMAL
2024-08-25T04:02:32.279881+00:00
2024-08-25T04:02:32.279906+00:00
213
false
## Intuition\nTo count pairs of integers in an array that become equal when two digits are swapped at most twice, we can generate all possible numbers by performing up to two swaps on each number\'s digits. We then check how many of these generated numbers have already been seen in the array.\n\n## Approach\n1. **Digit...
0
0
['C++']
0
count-almost-equal-pairs-ii
Just Brute Force in 29 lines
just-brute-force-in-29-lines-by-explosiv-u8yf
\n# Code\npython3 []\nclass Solution:\n def countPairs(self, nums: List[int]) -> int:\n result = 0\n cc = collections.Counter()\n for nu
ExplosiveBattery
NORMAL
2024-08-25T04:02:27.126666+00:00
2024-08-25T04:04:07.993631+00:00
274
false
\n# Code\n```python3 []\nclass Solution:\n def countPairs(self, nums: List[int]) -> int:\n result = 0\n cc = collections.Counter()\n for num in nums:\n result += cc[num]\n\n # change\n num_str = str(num)\n num_str = (7 - len(num_str)) * \'0\' + num_str...
0
0
['Python3']
1