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
insertion-sort-list
JAVA 2ms insertion sort
java-2ms-insertion-sort-by-kushguptacse-9qh0
\npublic ListNode insertionSortList(ListNode head) {\n ListNode dummy = new ListNode(Integer.MIN_VALUE);\n\t\tListNode curr = head;\n ListNode pre
kushguptacse
NORMAL
2020-02-26T08:11:07.854287+00:00
2020-02-26T08:11:07.854333+00:00
502
false
```\npublic ListNode insertionSortList(ListNode head) {\n ListNode dummy = new ListNode(Integer.MIN_VALUE);\n\t\tListNode curr = head;\n ListNode prev = dummy;\n\t\twhile (curr != null) {\n //to save checking from start below condition is used\n if(prev.val > curr.val)\n ...
3
0
['Linked List', 'Iterator', 'Java']
0
insertion-sort-list
Python solution
python-solution-by-zitaowang-5t82
Time complexity: O(n^2), space complexity: O(1).\n\n\nclass Solution:\n def insertionSortList(self, head):\n """\n :type head: ListNode\n
zitaowang
NORMAL
2018-12-28T05:59:17.993744+00:00
2018-12-28T05:59:17.993796+00:00
559
false
Time complexity: `O(n^2)`, space complexity: `O(1)`.\n\n```\nclass Solution:\n def insertionSortList(self, head):\n """\n :type head: ListNode\n :rtype: ListNode\n """\n if not head or not head.next:\n return head\n dummy = ListNode(float(\'inf\'))\n dummy....
3
0
[]
0
insertion-sort-list
5ms, O(1) space: 5 small steps that easy to follow
5ms-o1-space-5-small-steps-that-easy-to-uyouc
Preparation: * Order in LinkedList will be changed, extra variable required -> ListNode n. * LinkedList needs to be divided in sorted and unsorted parts -> List
akquard
NORMAL
2018-10-20T03:19:27.086650+00:00
2018-10-22T22:43:06.674300+00:00
290
false
**Preparation:** * Order in LinkedList will be changed, extra variable required -> `ListNode n`. * LinkedList needs to be divided in sorted and unsorted parts -> `ListNode pivot `. * Iteration of sorted part starting from head -> `ListNode current = head`. **Implementation:** 1. Iterate LinkedList. 2. Special case: `p...
3
0
[]
0
insertion-sort-list
15 Lines Java Solution Using DummyHead
15-lines-java-solution-using-dummyhead-b-wcw0
\n public ListNode insertionSortList(ListNode head) {\n ListNode dummy = new ListNode(0); // use dummyHead\n ListNode cur = head;\n whil
meganlee
NORMAL
2018-07-19T03:41:56.832961+00:00
2018-07-19T03:41:56.832961+00:00
269
false
```\n public ListNode insertionSortList(ListNode head) {\n ListNode dummy = new ListNode(0); // use dummyHead\n ListNode cur = head;\n while (cur != null) {\n ListNode iter = dummy; // find the correct insertion point\n while (iter.next != null && iter.next.val < cur.val) {...
3
0
[]
0
insertion-sort-list
TLE for Python?
tle-for-python-by-ice4026-2g85
I have a Time Limit Exceeded when input a list of 5000 numbers.\n\n class Solution:\n # @param head, a ListNode\n # @return a ListNode\n def insertS
ice4026
NORMAL
2014-04-24T11:45:35+00:00
2014-04-24T11:45:35+00:00
2,235
false
I have a Time Limit Exceeded when input a list of 5000 numbers.\n\n class Solution:\n # @param head, a ListNode\n # @return a ListNode\n def insertSort(self, head):\n if head==None or head.next==None:\n return head\n self.insertSort(head.next)\n l=head\n r=head.next\n ...
3
0
['Python']
3
insertion-sort-list
Python accepted iterative solution (Another solution is about 330ms).
python-accepted-iterative-solution-anoth-esnl
suppose already sorted the part from the second node, then just need to merge the first node with the second part, if head.val is smaller, then the second can b
oldcodingfarmer
NORMAL
2015-08-15T12:29:48+00:00
2015-08-15T12:29:48+00:00
740
false
suppose already sorted the part from the second node, then just need to merge the first node with the second part, if head.val is smaller, then the second can be connected behind head node, if head.val is larger than the value of the returned node, then we need to find the position to insert head, and return the return...
3
1
['Recursion', 'Iterator', 'Python']
2
insertion-sort-list
Java 34ms solution, clear logic with separate insert method
java-34ms-solution-clear-logic-with-sepa-3o4q
using insertion sort logic. Insert each new node into a sorted linked list with dummy head.\n \n\n public class Solution {\n public ListNode ins
yanggao
NORMAL
2015-11-23T21:25:29+00:00
2015-11-23T21:25:29+00:00
886
false
using insertion sort logic. Insert each new node into a sorted linked list with dummy head.\n \n\n public class Solution {\n public ListNode insertionSortList(ListNode head) {\n ListNode sortedHeadDummy = new ListNode(0);\n ListNode curr = head;\n while (curr...
3
0
[]
1
insertion-sort-list
Insertion sort python solution
insertion-sort-python-solution-by-lime66-tt5r
class Solution(object):\n def insertionSortList(self, head):\n if not head or not head.next:\n return head\n \n d
lime66
NORMAL
2016-02-25T05:11:56+00:00
2016-02-25T05:11:56+00:00
888
false
class Solution(object):\n def insertionSortList(self, head):\n if not head or not head.next:\n return head\n \n dummy = ListNode(None)\n dummy.next, tail = head, head.next\n dummy.next.next = None\n \n while tail:\n pr...
3
0
['Python']
0
insertion-sort-list
Easy and Concise C++
easy-and-concise-c-by-darkhorse007d-1yvh
\n# Code\ncpp []\nclass Solution {\npublic:\n ListNode* insertionSortList(ListNode* head) {\n ListNode* ans = new ListNode(-6000);\n while(head
darkhorse007d
NORMAL
2024-10-15T19:08:29.189134+00:00
2024-10-15T19:08:29.189162+00:00
113
false
\n# Code\n```cpp []\nclass Solution {\npublic:\n ListNode* insertionSortList(ListNode* head) {\n ListNode* ans = new ListNode(-6000);\n while(head){\n ListNode* curr = ans , *prev = ans;\n while(curr and curr -> val < head -> val){\n prev = curr;\n cu...
2
0
['C++']
0
insertion-sort-list
Best C++ Code (Beats 80%)
best-c-code-beats-80-by-souravsinghal200-qj1e
Intuition\n Describe your first thoughts on how to solve this problem. \nplzz upvote\n# Approach\n Describe your approach to solving the problem. \nplzz upvote\
souravsinghal2004
NORMAL
2024-09-08T12:27:44.428099+00:00
2024-09-08T12:27:44.428120+00:00
461
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nplzz upvote\n# Approach\n<!-- Describe your approach to solving the problem. -->\nplzz upvote\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nplzz upvote\n- Space complexity:\n<!-- Add your space ...
2
0
['C++']
1
insertion-sort-list
Solution By Dare2Solve | Detailed Explanation | Clean Code
solution-by-dare2solve-detailed-explanat-2qjy
Explanation []\nauthorslog.com/blog/cRT2Uc7vvh\n\n# Code\n\ncpp []\nclass Solution {\npublic:\n ListNode* insertionSortList(ListNode* head) {\n if (!h
Dare2Solve
NORMAL
2024-08-14T17:55:38.861224+00:00
2024-08-14T17:55:38.861259+00:00
2,610
false
```Explanation []\nauthorslog.com/blog/cRT2Uc7vvh\n```\n# Code\n\n```cpp []\nclass Solution {\npublic:\n ListNode* insertionSortList(ListNode* head) {\n if (!head)\n return nullptr;\n\n std::vector<int> arr;\n ListNode* current = head;\n\n while (current) {\n arr.pus...
2
0
['Linked List', 'Sorting', 'Python', 'C++', 'Java', 'Python3', 'JavaScript']
1
insertion-sort-list
Clear cpp solution using insertion sort | beats 99.3% | O(1) space
clear-cpp-solution-using-insertion-sort-h25sk
Approach\n Describe your approach to solving the problem. \n\n##### We will follow the procedure of insertion sort as we do for array.\nFor the solution I have
ReNY_1011
NORMAL
2024-06-14T18:09:25.486973+00:00
2024-06-14T18:09:25.487006+00:00
106
false
# Approach\n<!-- Describe your approach to solving the problem. -->\n\n##### We will follow the procedure of insertion sort as we do for array.\nFor the solution I have defined some helper functions namely-\n\n1. `insertNode` which is vanilla insertion in a linked list where the pointer of node after which toinsert is ...
2
0
['Linked List', 'C++']
0
insertion-sort-list
Using insertion sort
using-insertion-sort-by-abhish010102-x2bv
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
abhish010102
NORMAL
2024-06-12T06:38:37.760238+00:00
2024-06-12T06:38:37.760273+00:00
510
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
['C++']
0
insertion-sort-list
Insertion Sort List
insertion-sort-list-by-khushbu_143-8to5
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
khushbu_143
NORMAL
2024-05-14T14:18:40.018265+00:00
2024-05-14T14:18:40.018293+00:00
1,368
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']
1
sum-of-floored-pairs
✅ C++ Short & Easy | Frequency Prefix Sum Solution w/ Explanation
c-short-easy-frequency-prefix-sum-soluti-thet
\u2714\uFE0F Solution (Frequency Prefix Sum)\n\nWe can\'t iterate sum up for all the possible pairs since the given constraints would lead to TLE. \n\nWe need t
archit91
NORMAL
2021-05-15T16:02:57.803850+00:00
2021-05-15T16:43:30.509864+00:00
7,478
false
\u2714\uFE0F ***Solution (Frequency Prefix Sum)***\n\nWe can\'t iterate sum up for all the possible pairs since the given constraints would lead to TLE. \n\nWe need to observe that the result of *`floor(nums[i] / nums[j])`*, will be - \n\n* **`0`** if `nums[i] < nums[j]`\n* **`1`** if `nums[j] <= nums[i] < (2 * nums[j...
115
30
['C']
13
sum-of-floored-pairs
Prefix Sum, Fenwick Tree, Sort and Sieve
prefix-sum-fenwick-tree-sort-and-sieve-b-oi6y
Let max_n be the maximum number in our array. For each number n, we consider all possible factors f in [1, max_n / n].\n\nWe start from the largest factor, and
votrubac
NORMAL
2021-05-15T16:00:41.269949+00:00
2021-05-15T18:29:09.770698+00:00
5,330
false
Let `max_n` be the maximum number in our array. For each number `n`, we consider all possible factors `f` in `[1, max_n / n]`.\n\nWe start from the largest factor, and count how many numbers in our array are greater or equal than `f * n`. Then, we multiply this count by `f` and add it to our result. We then count elem...
57
2
['C']
13
sum-of-floored-pairs
[Java] O(n log(n)) Straightforward brute force with explanation, 76 ms
java-on-logn-straightforward-brute-force-l7fa
Intuition\n\nThe simplest method that everyone would come up with is to calculate floor(nums[i] / nums[j]) for each pair and add them up.\n\njava\n// Omitted mo
maristie
NORMAL
2021-05-15T16:25:42.554708+00:00
2021-05-21T11:20:32.926015+00:00
2,987
false
## Intuition\n\nThe simplest method that everyone would come up with is to calculate `floor(nums[i] / nums[j])` for each pair and add them up.\n\n```java\n// Omitted modulo operations\nint m = nums.length;\nint sum = 0;\nfor (int i = 0; i < m; ++i) {\n for (int j = 0; j < m; ++j) {\n sum += nums[i] / nums[j];...
54
5
[]
6
sum-of-floored-pairs
Python - Five lines, O( n log n)
python-five-lines-o-n-log-n-by-ceay-3ciq
For every dividend in the list nums, we need to calculate the sum of all quotients for all the divisors from the same list nums. To do so, we calculate the sum
ceay
NORMAL
2021-05-15T16:02:02.820551+00:00
2021-05-15T21:36:03.258887+00:00
3,323
false
For every dividend in the list *nums*, we need to calculate the sum of all quotients for all the divisors from the same list *nums*. To do so, we calculate the sum of quotients for each possible number until the maximum number of the list and store it in *quots*. Then, we will sum up all sums of the quotients for all t...
52
14
['Python']
9
sum-of-floored-pairs
C++ Binary Search
c-binary-search-by-lzl124631x-jknc
See my latest update in repo LeetCode\n\n## Solution 1. Binary Search\n\nIntuition: Sort the array A. For each A[i], we can binary search A[p] >= (k - 1) * A[i]
lzl124631x
NORMAL
2021-05-15T16:02:16.155258+00:00
2021-05-15T16:53:19.320415+00:00
2,867
false
See my latest update in repo [LeetCode](https://github.com/lzl124631x/LeetCode)\n\n## Solution 1. Binary Search\n\n**Intuition**: Sort the array `A`. For each `A[i]`, we can binary search `A[p] >= (k - 1) * A[i]` and `A[q] >= k * A[i]`, then all numbers `A[j]` with index in range `[p, q)` has `floor(A[j] / A[i]) = k - ...
35
4
[]
5
sum-of-floored-pairs
C++|Engaging Explanation and comments | SIEVE kind of logic | image | O(nlog(log(max))) | plz Upvote
cengaging-explanation-and-comments-sieve-sxbm
\n\nWhen we first encounter this question it seems like we need to do it for all pairs \nthat is Nc2 PAIRS or n(n-1)/2 which will give TLE\n\n1. For each a[i]
Coder_Shubham_24
NORMAL
2021-05-17T05:22:29.851890+00:00
2021-05-18T06:04:25.038058+00:00
937
false
![image](https://assets.leetcode.com/users/images/2bad3ec3-cf03-4fa7-9a46-8bf68917673d_1621228992.583361.jpeg)\n\nWhen we first encounter this question it seems like we need to do it for all pairs \nthat is Nc2 PAIRS or n*(n-1)/2 which will give TLE\n\n1. For each a[i] we need to consider only numbers greater than a[...
17
3
[]
4
sum-of-floored-pairs
Python3. Sort + binary search
python3-sort-binary-search-by-yaroslav-r-bakt
\nclass Solution:\n # idea:\n # first thing is that we can easily cache in this problem:\n # if we know result of `sum(nums[i] // nums[k] for k in ra
yaroslav-repeta
NORMAL
2021-05-15T16:01:09.426267+00:00
2021-05-15T16:49:34.113042+00:00
1,341
false
```\nclass Solution:\n # idea:\n # first thing is that we can easily cache in this problem:\n # if we know result of `sum(nums[i] // nums[k] for k in range(N))`,\n # then we know result for any `j` that `nums[j] = nums[i]`\n #\n # second. if we sort "nums", we can use binary search:\n # let `...
17
2
[]
3
sum-of-floored-pairs
No Advanced DSA| Lower_Bound + Basic Maths
no-advanced-dsa-lower_bound-basic-maths-axwv7
\n\n#define mod 1000000007\nclass Solution {\npublic:\n int sumOfFlooredPairs(vector<int>& nums) {\n \n int n = nums.size();\n unsigned
its_gupta_ananya
NORMAL
2021-05-15T16:40:55.809171+00:00
2021-05-22T11:26:14.621465+00:00
1,317
false
\n```\n#define mod 1000000007\nclass Solution {\npublic:\n int sumOfFlooredPairs(vector<int>& nums) {\n \n int n = nums.size();\n unsigned long long int ans =0;\n \n sort(nums.begin(), nums.end());\n \n for(int i=0;i<n;++i){\n int ind = 0;\n\t\t\t//k denote...
11
5
['Math', 'Binary Tree', 'C++']
6
sum-of-floored-pairs
Python/Python3 solution BruteForce & Optimized solution using Dictionary
pythonpython3-solution-bruteforce-optimi-zhyv
Brute Foce Solution(Time Limit Exceeded)\n\nThis solution will work if the length of the elements in the testcase is <50000(5 * 10^4).\nIf it exceeds 50000 it w
prasanthksp1009
NORMAL
2021-05-19T17:22:31.306850+00:00
2021-05-19T17:22:31.306896+00:00
983
false
**Brute Foce Solution(Time Limit Exceeded)**\n\nThis solution will work if the length of the elements in the testcase is <50000(5 * 10^4).\nIf it exceeds 50000 it will throw TLE error.\n**Code:**\n```\nclass Solution:\n def sumOfFlooredPairs(self, nums: List[int]) -> int:\n sumP = 0 #To store the value of Sum...
10
0
['Counting', 'Python', 'Python3']
0
sum-of-floored-pairs
[Java] Count all frequencies, then enumerate all floor values, O((distinct value count) * max)
java-count-all-frequencies-then-enumerat-hv0f
We don\'t know the value of nums[i] / nums[j], but we can fix the value of nums[i] / nums[j], then find how many times will this value occurs.\njava\nclass Solu
toffeelu
NORMAL
2021-05-15T16:01:55.388747+00:00
2021-05-16T02:01:06.574134+00:00
934
false
We don\'t know the value of `nums[i] / nums[j]`, but we can fix the value of `nums[i] / nums[j]`, then find how many times will this value occurs.\n```java\nclass Solution {\n public int sumOfFlooredPairs(int[] nums) {\n int MOD = 1_000_000_000 + 7;\n int n = nums.length;\n long res = 0;\n ...
7
0
[]
2
sum-of-floored-pairs
💥💥 C# | 100% beats runtime AND memory [EXPLAINED]
c-100-beats-runtime-and-memory-explained-isrc
\n# Intuition\nThe goal is to find the sum of floor divisions for all possible pairs in the array, where one number divides the other. Directly computing this f
r9n
NORMAL
2024-09-18T20:50:23.267561+00:00
2024-09-18T20:50:23.267581+00:00
69
false
\n# Intuition\nThe goal is to find the sum of floor divisions for all possible pairs in the array, where one number divides the other. Directly computing this for every pair would be too slow, so we use a more efficient approach. By leveraging frequency counts and prefix sums, we avoid redundant calculations and speed ...
6
0
['C#']
0
sum-of-floored-pairs
JAVA Readable Code
java-readable-code-by-himanshuchhikara-0qyh
IDEA:\n Basic idea is for every number let say x . I am not going to check for [1,2,...x) . I know the answer of this range that is 0. Similarly for range [x,x+
himanshuchhikara
NORMAL
2021-05-17T17:40:18.463021+00:00
2021-05-17T17:40:18.463072+00:00
805
false
**IDEA:**\n Basic idea is for every number let say x . I am not going to check for [1,2,...x) . I know the answer of this range that is 0. Similarly for range [x,x+1...2x) If we take floor of x with any value in this answer will be this. keeping this in mind have a eye on code and things will get clear to you .\n \n**C...
6
1
['Counting', 'Prefix Sum', 'Java']
1
sum-of-floored-pairs
[Python] Suffix sums detailed explanation
python-suffix-sums-detailed-explanation-3kip6
\ndef sumOfFlooredPairs(self, nums: List[int]) -> int:\n maxn = 10**5 + 7\n MOD = 10**9 + 7\n f = [0 for i in range(maxn + 1)] # keep a
prasanna648
NORMAL
2021-05-15T16:00:54.333723+00:00
2021-05-15T16:00:54.333746+00:00
681
false
```\ndef sumOfFlooredPairs(self, nums: List[int]) -> int:\n maxn = 10**5 + 7\n MOD = 10**9 + 7\n f = [0 for i in range(maxn + 1)] # keep a count of the frequency of each element in the array\n sf = [0 for i in range(maxn + 1)] # suffix array of the frequencies, sf[i] represents freque...
5
0
[]
2
sum-of-floored-pairs
>90%, >45%, c++ solution with explanation
90-45-c-solution-with-explanation-by-sja-z3ez
According to the hints, my idea is the following :\n\n 1. Iterate over nums in order to find the maximum value max_n.\n 2. Create an array of occurences occs of
sjaubain
NORMAL
2021-11-02T15:00:14.401600+00:00
2021-11-02T15:00:14.401649+00:00
700
false
According to the hints, my idea is the following :\n\n* 1. Iterate over `nums` in order to find the maximum value `max_n`.\n* 2. Create an array of occurences `occs` of size `max_n + 1` (no need to have it of size 10<sup>5</sup> if we only have numbers in range `0` to `max_n`.\n* 3. Iterate over `occs` to create the ar...
4
0
['C', 'Bucket Sort', 'Prefix Sum']
1
sum-of-floored-pairs
Python - 8 lines frequency prefix sum
python-8-lines-frequency-prefix-sum-by-l-q7vp
\nclass Solution:\n def sumOfFlooredPairs(self, nums: List[int]) -> int:\n ans, hi, n, c = 0, max(nums)+1, len(nums), Counter(nums)\n pre = [0]
leetcoder289
NORMAL
2021-05-15T23:29:13.511183+00:00
2021-05-15T23:29:20.844169+00:00
404
false
```\nclass Solution:\n def sumOfFlooredPairs(self, nums: List[int]) -> int:\n ans, hi, n, c = 0, max(nums)+1, len(nums), Counter(nums)\n pre = [0] * hi\n for i in range(1, hi):\n pre[i] = pre[i-1] + c[i]\n for num in set(nums):\n for i in range(num, hi, num):\n ...
4
0
['Python', 'Python3']
2
sum-of-floored-pairs
Easy To Understand || C++ Solution
easy-to-understand-c-solution-by-aayushe-b34m
Code\n\nclass Solution {\npublic:\n int sumOfFlooredPairs(vector<int>& nums) {\n sort(nums.begin(),nums.end());\n long long ans=0;\n int
aayushee_123
NORMAL
2023-02-08T17:00:48.374202+00:00
2023-02-08T17:00:48.374251+00:00
191
false
# Code\n```\nclass Solution {\npublic:\n int sumOfFlooredPairs(vector<int>& nums) {\n sort(nums.begin(),nums.end());\n long long ans=0;\n int mx=nums[nums.size()-1];\n\n // Finding the frequency of all elements in the array.\n unordered_map<int,int> mp;\n for(int i=0;i<nums....
3
0
['Binary Search', 'Sorting', 'C++']
0
sum-of-floored-pairs
Python | Simple algorithm similar to prime number generators
python-simple-algorithm-similar-to-prime-gbzp
\n\n\nclass Solution:\n def sumOfFlooredPairs(self, nums: List[int]) -> int:\n freq = Counter(nums)\n maxVal = max(nums)\n cache = [0 fo
satendrapandey
NORMAL
2022-05-18T05:41:54.571810+00:00
2022-05-18T05:41:54.571837+00:00
466
false
```\n\n\nclass Solution:\n def sumOfFlooredPairs(self, nums: List[int]) -> int:\n freq = Counter(nums)\n maxVal = max(nums)\n cache = [0 for i in range(maxVal + 1)]\n for key in freq:\n num = freq[key]\n count = 1\n while count*key <= maxVal:\n ...
3
0
['Python']
0
sum-of-floored-pairs
C++ | O(Nlog(N))
c-onlogn-by-m-abhi-va35
\n int sumOfFlooredPairs(vector<int>& nums) {\n int N = 1e5 + 100, MOD = 1e9 + 7;\n\n vector<int> frq(N, 0), preFrq(N, 0);\n\n for (int
m-abhi
NORMAL
2021-05-15T20:06:13.447032+00:00
2021-05-15T20:06:13.447066+00:00
243
false
```\n int sumOfFlooredPairs(vector<int>& nums) {\n int N = 1e5 + 100, MOD = 1e9 + 7;\n\n vector<int> frq(N, 0), preFrq(N, 0);\n\n for (int i : nums)\n frq[i]++;\n\n for (int i = 1; i < N; ++i)\n preFrq[i] = preFrq[i - 1] + frq[i];\n\n int ans = 0 ;\n\n ...
3
2
[]
0
sum-of-floored-pairs
C++ Prefix Sums + Iterate over Element Values
c-prefix-sums-iterate-over-element-value-9idp
The naive solution to this problem would have a runtime complexity of O(n^2), which results in a TLE for an array size of at most 1e5. However, note the other p
jiaxiangwu
NORMAL
2021-05-15T16:01:34.373863+00:00
2021-05-15T16:02:09.836670+00:00
416
false
The naive solution to this problem would have a runtime complexity of O(n^2), which results in a TLE for an array size of at most 1e5. However, note the other problem size constraint: 1 <= nums[i] <= 1e5. The range of element value is limited, giving us the idea of iterating all possible element values and sum up their...
3
0
[]
0
sum-of-floored-pairs
Python3/C++ Fenwick Tree Solution
python3-fenwick-tree-solution-by-stefan1-lt1c
ApproachFor each possible i<100000, we have the fact that: numbers between i∗k and i∗(k+1)−1 gives k when divided by i numbers between i∗(k+1) and i∗(k+2)−1 giv
onceACoder_
NORMAL
2025-02-05T17:41:01.587104+00:00
2025-02-12T15:42:12.252911+00:00
67
false
# Approach For each possible $i<100000$, we have the fact that: - numbers between $i*k$ and $i*(k+1)-1$ gives $k$ when divided by $i$ - numbers between $i*(k+1)$ and $i*(k+2)-1$ gives $k+1$ when divided by $i$ - and so on We can use this fact to find each interval $[left,right]$ in which all numbers give k when divid...
2
0
['Python3']
0
sum-of-floored-pairs
C++ || Sieve || prefix sum || easy Swap27 solution
c-sieve-prefix-sum-easy-swap27-solution-w6zd3
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n-sieve\n-prefix sum\n Describe your approach to solving the problem. \n\n
adsulswapnil27
NORMAL
2024-05-18T07:55:13.340920+00:00
2024-05-18T07:55:13.340956+00:00
303
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n-sieve\n-prefix sum\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:n*log(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:n\n<!-- Add your space com...
2
0
['C++']
1
sum-of-floored-pairs
[Python] Sorting + Binary Search with thought process when being asked during interviews
python-sorting-binary-search-with-though-vs88
Sorting + Binary Search\nMy strategy of resolving hard problems is to start with brute-force solution, and then improve it to sub/optimal approachs by identifyi
jandk
NORMAL
2021-10-16T20:04:01.439073+00:00
2021-10-16T20:06:07.789442+00:00
341
false
### Sorting + Binary Search\nMy strategy of resolving hard problems is to start with brute-force solution, and then improve it to sub/optimal approachs by identifying and fixing bottleneck.\nSo the brute-force approach for this problem is quite simple, we try out each possible pair of `nums[i], nums[j]` and calculate t...
2
0
[]
0
sum-of-floored-pairs
(C++) 1862. Sum of Floored Pairs
c-1862-sum-of-floored-pairs-by-qeetcode-ptv0
\n\nclass Solution {\npublic:\n int sumOfFlooredPairs(vector<int>& nums) {\n int m = *max_element(nums.begin(), nums.end()); \n vector<long> va
qeetcode
NORMAL
2021-05-16T15:41:23.624726+00:00
2021-05-21T16:15:12.939979+00:00
364
false
\n```\nclass Solution {\npublic:\n int sumOfFlooredPairs(vector<int>& nums) {\n int m = *max_element(nums.begin(), nums.end()); \n vector<long> vals(m+1); \n for (auto x : nums) \n ++vals[x]; \n \n for (int x = m; x > 0; --x) \n for (int xx = 2*x; xx <= m; xx ...
2
0
['C']
1
sum-of-floored-pairs
C++ ON2 solution Using Frequency Array
c-on2-solution-using-frequency-array-by-jg2zk
\nclass Solution {\npublic:\n int sumOfFlooredPairs(vector<int>& nums) {\n int A[200005]={0};\n\t int M[200005]={0};\n int N = *max_element(
kartikeya72001
NORMAL
2021-05-15T16:29:25.848297+00:00
2021-05-15T16:33:22.647681+00:00
396
false
```\nclass Solution {\npublic:\n int sumOfFlooredPairs(vector<int>& nums) {\n int A[200005]={0};\n\t int M[200005]={0};\n int N = *max_element(nums.begin(), nums.end())*2+1;\n \n for(int i=0;i<nums.size();i++)\n A[nums[i]]++;\n \n for(int i=1;i<N;i++)\n\t\t ...
2
0
['C', 'Counting']
2
sum-of-floored-pairs
Reverse Logic Count Prefix Sum with Sieve method O(nlogn) Complexity
reverse-logic-count-prefix-sum-with-siev-fm9d
Intuition\n Describe your first thoughts on how to solve this problem. \n- Here we are going to think in reverse order\n- we are going to fix denominator and fl
yash559
NORMAL
2024-08-16T13:56:42.293234+00:00
2024-08-16T13:56:42.293277+00:00
60
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n- Here we are going to think in reverse order\n- we are going to fix denominator and floor fractional result and we are going to find how many numerators satisfy this condition.\n- we need **prefix count sum(sieve method)**\n\n***Main Int...
1
0
['C++']
0
sum-of-floored-pairs
Python 3 best N log(N) solution with 98.78% beats.
python-3-best-n-logn-solution-with-9878-9vv2c
Intuition\n Describe your first thoughts on how to solve this problem. \nThink about frequencies and multiples!\n\n# Approach\n Describe your approach to solvin
MAS5236
NORMAL
2024-04-19T01:42:36.853376+00:00
2024-04-19T01:42:36.853412+00:00
301
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThink about frequencies and multiples!\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nFrequencies and multiples.\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nN log(N)\n...
1
0
['Python3']
1
sum-of-floored-pairs
Best Java Solution || Beats 80%
best-java-solution-beats-80-by-ravikumar-g2qm
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
ravikumar50
NORMAL
2023-10-12T19:55:51.519754+00:00
2023-10-12T19:55:51.519779+00:00
353
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
1
0
['Java']
0
sum-of-floored-pairs
[PYTHON] | ALGORITHM
python-algorithm-by-omkarxpatel-bzie
\nRuntime: 3561 ms, faster than 73.68% of Python3 online submissions for Sum of Floored Pairs.\nMemory Usage: 32.6 MB, less than 56.84% of Python3 online submis
omkarxpatel
NORMAL
2022-07-13T14:40:28.246118+00:00
2022-07-13T14:40:28.246146+00:00
415
false
\nRuntime: **3561 ms, faster than 73.68%** of Python3 online submissions for Sum of Floored Pairs.\nMemory Usage: **32.6 MB, less than 56.84%** of Python3 online submissions for Sum of Floored Pairs.\n```\n\nclass Solution:\n def sumOfFlooredPairs(self, n: List[int]) -> int:\n f, m, c = Counter(n), max(n), [0...
1
0
['Python', 'Python3']
0
sum-of-floored-pairs
Segment Tree & prefix sum Solution || Very slow but unique || C++
segment-tree-prefix-sum-solution-very-sl-2105
As most of the solutions posted here is highly dependent on prefix array sum and other techniques, I thought that solving using segment tree is a pretty unique
NAHDI51
NORMAL
2021-08-11T13:02:33.118043+00:00
2021-08-11T13:02:33.118076+00:00
287
false
As most of the solutions posted here is highly dependent on prefix array sum and other techniques, I thought that solving using segment tree is a pretty unique idea.\n\nThis is a materialized idea of the HINTS 1 & 2 provided there.\n\n```\nclass segment_tree {\nvector<int> seg;\nint size;\npublic:\nsegment_tree(vector<...
1
0
['Tree', 'C', 'Prefix Sum']
0
sum-of-floored-pairs
C++
c-by-wzypangpang-yqb1
\nclass Solution {\n typedef long long ll;\npublic:\n int sumOfFlooredPairs(vector<int>& nums) {\n const int len = 100002;\n ll eg[len] = {}
wzypangpang
NORMAL
2021-05-29T03:53:09.175816+00:00
2021-05-29T03:53:09.175842+00:00
338
false
```\nclass Solution {\n typedef long long ll;\npublic:\n int sumOfFlooredPairs(vector<int>& nums) {\n const int len = 100002;\n ll eg[len] = {}; // eg[i] means # of elements equal or greater than i.\n int cnt[len] = {}; // cnt[i] means of elements equal to i.\n int maxnum = 0;\n ...
1
0
[]
0
sum-of-floored-pairs
Java: Sorting with Divide and Conquer
java-sorting-with-divide-and-conquer-by-mmgpr
This solution is not the fastest. It takes 1141ms but uses a different approach than what is mentioned in other posts that utilize a frequency and prefix array.
amitghattimare
NORMAL
2021-05-28T19:31:03.185872+00:00
2021-05-28T19:37:04.953240+00:00
271
false
This solution is not the fastest. It takes 1141ms but uses a different approach than what is mentioned in other posts that utilize a frequency and prefix array.\n\nFirst, we sort the array because that doesn\'t change the answer or time complexity and lets us use previous computations for repeated elements. Then starti...
1
0
[]
0
sum-of-floored-pairs
[C++, 240ms] Prefix sum * frequency with explanation
c-240ms-prefix-sum-frequency-with-explan-1dts
Basic idea: ranges for the numerators. E.g. 4/4..7/4=1, 8/4..11/4=2. Multiply by count(4..7)*count(4) for the first, count(8..11)*count(4) for the second, etc.\
nauful
NORMAL
2021-05-26T18:38:01.180059+00:00
2021-05-26T18:38:01.180103+00:00
337
false
Basic idea: ranges for the numerators. E.g. 4/4..7/4=1, 8/4..11/4=2. Multiply by `count(4..7)*count(4)` for the first, `count(8..11)*count(4)` for the second, etc.\n\n```\nclass Solution {\npublic:\n int sumOfFlooredPairs(vector<int>& nums) {\n const int M = 1e9 + 7;\n const int N = 1e5 + 1;\n \...
1
1
[]
0
sum-of-floored-pairs
JavaScript DP
javascript-dp-by-ektegjetost-uw9b
The idea:\nFor each number, we have x other numbers that are at least as large as it, then some subset that are 2x larger, 3x larger, etc until you go over MAX.
ektegjetost
NORMAL
2021-05-16T19:35:12.815575+00:00
2021-05-16T19:35:27.274843+00:00
171
false
The idea:\nFor each number, we have ```x``` other numbers that are at least as large as it, then some subset that are 2x larger, 3x larger, etc until you go over MAX.\n- Any number that\'s between sizes of ```1 x n``` to ```1.99999... x n``` count once\n- numbers between ```2 x n``` to ```2.99999... x n``` count twice,...
1
0
['Dynamic Programming', 'JavaScript']
0
sum-of-floored-pairs
[C++] | Prefix Sum
c-prefix-sum-by-avishubht762-a4mo
\nclass Solution {\npublic:\n int sumOfFlooredPairs(vector<int>& nums) \n {\n long long mod = 1e9+7;\n long long h[200002]={0};\n int mx=INT_M
avishubht762
NORMAL
2021-05-16T11:58:51.397630+00:00
2021-05-16T13:09:08.452390+00:00
189
false
```\nclass Solution {\npublic:\n int sumOfFlooredPairs(vector<int>& nums) \n {\n long long mod = 1e9+7;\n long long h[200002]={0};\n int mx=INT_MIN;\n for(auto x: nums)\n {\n h[x]++;\n mx=max(mx,x);\n }\n vector<int> pfx(2*mx+1,0);\n for(int i=1;i<=2*mx;i++)\n {...
1
1
['C', 'Sorting', 'Prefix Sum']
0
sum-of-floored-pairs
C++ Solution using Lower bound + Optimization
c-solution-using-lower-bound-optimizatio-01pr
```\nint sumOfFlooredPairs(vector& nums) {\n long long ans=0,mod=1000000007,p=0;\n sort(nums.begin(),nums.end());\n int n=nums.size();\n
nonymous
NORMAL
2021-05-16T05:48:31.347662+00:00
2021-05-16T05:50:28.576077+00:00
70
false
```\nint sumOfFlooredPairs(vector<int>& nums) {\n long long ans=0,mod=1000000007,p=0;\n sort(nums.begin(),nums.end());\n int n=nums.size();\n for(int i=0;i<n;i++)\n {\n if(i>0 && nums[i]==nums[i-1])\n {\n ans=(ans+p)%mod;\n continue;...
1
0
[]
0
sum-of-floored-pairs
Java - Simple Brute approach, Using memorization, 100% faster!!!
java-simple-brute-approach-using-memoriz-358a
\nimport java.util.Arrays;\n\nclass Solution {\n public int sumOfFlooredPairs(int[] arr) {\n \n \tint i,j,k,max,n=arr.length;\n \tlong sum=0,tot
pgthebigshot
NORMAL
2021-05-15T18:02:28.880190+00:00
2021-05-15T20:47:24.095008+00:00
513
false
```\nimport java.util.Arrays;\n\nclass Solution {\n public int sumOfFlooredPairs(int[] arr) {\n \n \tint i,j,k,max,n=arr.length;\n \tlong sum=0,tot=0;\n \tArrays.sort(arr);\n \tmax=arr[n-1];\n \tint count[]=new int[max+1];\n \tfor(i=0;i<n;i++)\n \t\tcount[arr[i]]++;\n \tfor(i=1;i<=max;...
1
0
['Java']
3
sum-of-floored-pairs
Simple C++ solution | Prefix Sum
simple-c-solution-prefix-sum-by-nayakash-sath
\n#define ll long long\n#define mod 1000000007\nclass Solution {\npublic:\n int sumOfFlooredPairs(vector<int>& a) {\n ll n=a.size(),s=0,mx=0;\n
nayakashutosh9
NORMAL
2021-05-15T16:57:01.800014+00:00
2021-05-15T16:57:01.800048+00:00
122
false
```\n#define ll long long\n#define mod 1000000007\nclass Solution {\npublic:\n int sumOfFlooredPairs(vector<int>& a) {\n ll n=a.size(),s=0,mx=0;\n for(int i=0;i<n;i++){\n s+=a[i];mx=max(mx,a[i]*1LL);\n }\n vector<int> p(4*mx+1,0);\n for(int i=0;i<n;i++) p[a[i]]++;\n ...
1
1
[]
0
sum-of-floored-pairs
C++ | easy to understand sol
c-easy-to-understand-sol-by-kena7-bg30
\nclass Solution {\npublic:\n int mod=1000000007;\n int sumOfFlooredPairs(vector<int>& nums) \n {\n vector<int>v(200002,0);\n for(auto x:
kenA7
NORMAL
2021-05-15T16:10:36.488395+00:00
2021-05-15T16:10:36.488427+00:00
215
false
```\nclass Solution {\npublic:\n int mod=1000000007;\n int sumOfFlooredPairs(vector<int>& nums) \n {\n vector<int>v(200002,0);\n for(auto x:nums)\n v[x+1]++;\n for(int i=1;i<=200001;i++)\n v[i]+=v[i-1];\n int res=0;\n for(auto x:nums)\n {\n ...
1
2
[]
0
sum-of-floored-pairs
C++
c-by-user5976fh-iqfo
null
user5976fh
NORMAL
2025-04-10T07:50:26.878297+00:00
2025-04-10T07:50:26.878297+00:00
4
false
```cpp [] class Solution { public: int s = 100001, MOD = 1e9 + 7; int p[100001] = {}; int sumOfFlooredPairs(vector<int>& nums) { for (auto& n : nums) ++p[n]; for (int i = 1; i < s; ++i) p[i] += p[i - 1]; long long ans = 0; for (int i = 1; i < s; ++i) { ...
0
0
['C++']
0
sum-of-floored-pairs
JAVA
java-by-karthi_saravanan_t-iycj
Code
KARTHI_SARAVANAN_T
NORMAL
2025-02-01T06:11:50.946237+00:00
2025-02-01T06:11:50.946237+00:00
9
false
# Code ```java [] public class Solution { public int sumOfFlooredPairs(int[] nums) { int N = (int) 1e5; // Maximum possible value in nums int mod = (int) 1e9 + 7; // Modulo value // Step 1: Create a frequency map to count occurrences of each number int[] frequencyMap = new int[N +...
0
0
['Java']
0
sum-of-floored-pairs
Explained Clean Code | Beats 100% 23ms
explained-clean-code-beats-100-23ms-by-i-mg3o
IntuitionSimilar to the Sieve of Eratosthenes, this solution uses a frequency-based counting approach to compute floor division contributions across all array p
ivangnilomedov
NORMAL
2025-01-31T15:10:09.821267+00:00
2025-01-31T15:10:09.821267+00:00
11
false
# Intuition Similar to the Sieve of Eratosthenes, this solution uses a frequency-based counting approach to compute floor division contributions across all array pairs. # Approach The key insight is transforming the problem from pair-wise computation to a frequency-based counting strategy: 1. **Frequency Accumulation...
0
0
['C++']
0
sum-of-floored-pairs
1862. Sum of Floored Pairs
1862-sum-of-floored-pairs-by-g8xd0qpqty-escg
IntuitionApproachComplexity Time complexity: Space complexity: Code
G8xd0QPqTy
NORMAL
2025-01-15T14:45:41.397929+00:00
2025-01-15T14:45:41.397929+00:00
12
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code `...
0
0
['Java']
0
sum-of-floored-pairs
Easy O(nlogn) Solution || Easy to understand || Beats 99% || C++
easy-onlogn-solution-easy-to-understand-pxll3
Complexity Time complexity:O(max(nums)∗log(max(nums))) Space complexity:O(max(nums)) Code
dubeyad2003
NORMAL
2024-12-25T13:06:35.761725+00:00
2024-12-25T13:06:35.761725+00:00
22
false
# Complexity - Time complexity:$$O(max(nums) * log(max(nums)))$$ <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity:$$O(max(nums))$$ <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code ```cpp [] class Solution { public: int sumOfFlooredPairs(vector<int>& nums) { int mx = *m...
0
0
['C++']
0
sum-of-floored-pairs
⚡| python | highly optimized | O(n + m. logm)| Beats 100%| ⚡
python-highly-optimized-on-m-logm-beats-bwpn2
Intuition\nRather than checking every pair (i, j), we use the frequency of each number and cumulative sums to compute the result in a more efficient way, reduci
bhoomika1005
NORMAL
2024-11-23T17:54:56.110878+00:00
2024-11-23T17:54:56.110901+00:00
3
false
# Intuition\nRather than checking every pair (i, j), we use the frequency of each number and cumulative sums to compute the result in a more efficient way, reducing the need for nested loops.\n# Approach\nWe optimize the problem using frequency counting and prefix sums. Instead of checking every pair, we first count ho...
0
0
['Python']
0
sum-of-floored-pairs
c++ solution
c-solution-by-dilipsuthar60-mffa
\nclass Solution {\npublic:\n const int MAX=1e5+5;\n const int mod= 1e9+7;\n int sumOfFlooredPairs(vector<int>& nums) {\n vector<long long>prefi
dilipsuthar17
NORMAL
2024-11-08T12:25:16.964114+00:00
2024-11-08T12:25:16.964144+00:00
8
false
```\nclass Solution {\npublic:\n const int MAX=1e5+5;\n const int mod= 1e9+7;\n int sumOfFlooredPairs(vector<int>& nums) {\n vector<long long>prefix(MAX,0);\n unordered_map<int,int>mp;\n int n=nums.size();\n for(auto &it:nums){\n prefix[it]++;\n mp[it]++;\n ...
0
0
['C', 'C++']
0
sum-of-floored-pairs
Intuition
intuition-by-singh_avi-ink9
Intuition\nThis problem seems simple but is tricky. The key idea is as follows:\n\n1. The nums array contains a maximum number m. \n2. For each number from 0 to
singh_avi
NORMAL
2024-10-23T09:47:37.332112+00:00
2024-10-23T09:47:37.332132+00:00
8
false
# Intuition\nThis problem seems simple but is tricky. The key idea is as follows:\n\n1. The nums array contains a maximum number m. \n2. For each number from 0 to m, we keep a track of the frequency of each one of them\n3. For any number n and p where p > n, the number of elements between n and p (inclusive) can be fou...
0
0
['Go']
0
sum-of-floored-pairs
1862. Sum of Floored Pairs.cpp
1862-sum-of-floored-pairscpp-by-202021ga-fwds
Code\n\nclass Solution {\npublic:\n int sumOfFlooredPairs(vector<int>& nums) {\n int m = *max_element(nums.begin(), nums.end()); \n vector<long
202021ganesh
NORMAL
2024-10-18T10:20:37.341632+00:00
2024-10-18T10:20:37.341672+00:00
1
false
**Code**\n```\nclass Solution {\npublic:\n int sumOfFlooredPairs(vector<int>& nums) {\n int m = *max_element(nums.begin(), nums.end()); \n vector<long> vals(m+1); \n for (auto x : nums) \n ++vals[x]; \n for (int x = m; x > 0; --x) \n for (int xx = 2*x; xx <= ...
0
0
['C']
0
sum-of-floored-pairs
Sum of Floored Pairs
sum-of-floored-pairs-by-ansh1707-30ph
\n\n# Code\npython []\nfrom collections import Counter\n\nclass Solution(object):\n def sumOfFlooredPairs(self, nums):\n # Create a list to store the
Ansh1707
NORMAL
2024-10-14T02:12:36.413006+00:00
2024-10-14T02:12:36.413044+00:00
0
false
\n\n# Code\n```python []\nfrom collections import Counter\n\nclass Solution(object):\n def sumOfFlooredPairs(self, nums):\n # Create a list to store the increases and a counter for the frequencies of nums\n incs, counter = [0] * (max(nums) + 1), Counter(nums) \n \n # Loop over all the di...
0
0
['Python']
0
sum-of-floored-pairs
Typescript
typescript-by-ggnohope-2hkn
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
ggnohope
NORMAL
2024-09-18T14:00:49.360878+00:00
2024-09-18T14:00:49.360902+00:00
3
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
0
0
['TypeScript']
0
sum-of-floored-pairs
Python || binary search || Memoization
python-binary-search-memoization-by-vila-k9lz
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-09-07T22:38:35.170184+00:00
2024-09-07T23:04:02.982220+00:00
10
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(Nlog(N))\n\n- Space complexity:\n<!-- Add your space complexity here, e.g....
0
0
['Array', 'Math', 'Binary Search', 'Memoization', 'Python3']
0
sum-of-floored-pairs
Fenwick Tree Solution || Explained
fenwick-tree-solution-explained-by-rasto-gibd
Complexity\n- Time complexity: O(n*log(n)) \n\n- Space complexity: O(n) \n\n# Code\n\n#define mod 1000000007\nclass FenwickTree\n{\n vector<int> BIT;\n pu
coder_rastogi_21
NORMAL
2024-06-26T09:54:46.237136+00:00
2024-06-26T09:54:46.237184+00:00
26
false
# Complexity\n- Time complexity: $$O(n*log(n))$$ \n\n- Space complexity: $$O(n)$$ \n\n# Code\n```\n#define mod 1000000007\nclass FenwickTree\n{\n vector<int> BIT;\n public:\n FenwickTree(int n) {\n BIT.resize(n+1);\n }\n\n void update(int i, int delta)\n {\n for(; i<int(BIT.size()); i +=...
0
0
['Binary Indexed Tree', 'C++']
0
sum-of-floored-pairs
Two counters
two-counters-by-yoongyeom-av6s
Code\n\nclass Solution:\n def sumOfFlooredPairs(self, nums: List[int]) -> int:\n c = Counter(nums)\n mx= max(nums)\n muls = defaultdict
YoonGyeom
NORMAL
2024-04-29T14:00:32.314876+00:00
2024-04-29T14:00:32.314912+00:00
15
false
# Code\n```\nclass Solution:\n def sumOfFlooredPairs(self, nums: List[int]) -> int:\n c = Counter(nums)\n mx= max(nums)\n muls = defaultdict(int)\n for key in c:\n t = 1\n while t*key <= mx:\n muls[t*key]+=c[key]\n t+=1\n t = sor...
0
0
['Python3']
0
sum-of-floored-pairs
This problem is very hard!
this-problem-is-very-hard-by-heiseshandi-p2u1
Intuition\n\nThis problem involves finding the sum of all pairs (nums[i], nums[j]) in an array such that for each pair, the result is the quotient of nums[j] /
heiseshandian
NORMAL
2024-03-31T15:42:24.921983+00:00
2024-03-31T15:42:24.922015+00:00
7
false
## Intuition\n\nThis problem involves finding the sum of all pairs `(nums[i], nums[j])` in an array such that for each pair, the result is the quotient of `nums[j] / nums[i]` floored (i.e., the integer part of the division). The challenge lies in efficiently calculating this sum for all pairs without directly simulatin...
0
0
['TypeScript']
0
sum-of-floored-pairs
😆Runtime 160 ms Beats 100.00% of users with Go
runtime-160-ms-beats-10000-of-users-with-9x3n
Code\n\nfunc sumOfFlooredPairs(arr []int) int {\n const mod = int(1e9 + 7)\n\t// n := len(arr)\n\tvar ans int64\n\tmax := -1\n\n\tfor _, num := range arr {\n
pvt2024
NORMAL
2024-02-27T06:21:16.985867+00:00
2024-02-27T06:21:16.985900+00:00
7
false
# Code\n```\nfunc sumOfFlooredPairs(arr []int) int {\n const mod = int(1e9 + 7)\n\t// n := len(arr)\n\tvar ans int64\n\tmax := -1\n\n\tfor _, num := range arr {\n\t\tif num > max {\n\t\t\tmax = num\n\t\t}\n\t}\n\n\tfreq := make([]int, max+1)\n\tfor _, num := range arr {\n\t\tfreq[num]++\n\t}\n\n\tpre := make([]int, ...
0
0
['Go']
0
sum-of-floored-pairs
just an example
just-an-example-by-igormsc-8umi
Code\n\nclass Solution {\n \n fun sumOfFlooredPairs(nums: IntArray): Int {\n val maxN = nums.max()\n val v = nums.fold(IntArray(N+1)) { a, n
igormsc
NORMAL
2024-01-07T17:54:13.623580+00:00
2024-01-07T17:54:13.623617+00:00
2
false
# Code\n```\nclass Solution {\n \n fun sumOfFlooredPairs(nums: IntArray): Int {\n val maxN = nums.max()\n val v = nums.fold(IntArray(N+1)) { a, n -> a.also{ a[n]++ } }.apply {(1..N).forEach { i -> this[i] += this[i-1] }}\n return nums.toSet().fold(0.toLong()){ sum, x ->\n (sum + ge...
0
0
['Kotlin']
0
sum-of-floored-pairs
nlogn solution
nlogn-solution-by-13ethand-seyl
//the main part of the solution is to notice that for a fixed k, there are only so many value floor(n/k) can have\n //so lets ask the question, for a denomin
13ethand
NORMAL
2023-12-14T01:11:01.190385+00:00
2023-12-14T01:11:01.190407+00:00
73
false
//the main part of the solution is to notice that for a fixed k, there are only so many value floor(n/k) can have\n //so lets ask the question, for a denominator aj how many indices exist such that floor(ai/aj)=some value q\n //if we want to find some target value then we sum up number of indices that have value ...
0
0
['C++']
0
sum-of-floored-pairs
Python most optimized solution
python-most-optimized-solution-by-taco-m-hxic
Intuition\n Describe your first thoughts on how to solve this problem. \n[[2//2, 2//5, 2//9],\n [5//2, 5//5, 5//9],\n [9//2, 9//5, 9//9]]\n\n let\'s take 9//2 w
taco-man
NORMAL
2023-10-17T16:32:46.276786+00:00
2023-10-17T16:32:46.276805+00:00
36
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n[[2//2, 2//5, 2//9],\n [5//2, 5//5, 5//9],\n [9//2, 9//5, 9//9]]\n\n let\'s take 9//2 what it represents, it represents that there are total\n of 4 number (2,4,6,8) before 9 that are multiple of 2. so its value \n would be 4. same goes fo...
0
0
['Hash Table', 'Math', 'Prefix Sum', 'Python3']
0
sum-of-floored-pairs
nlogn solution using maths
nlogn-solution-using-maths-by-culer2024-a249
\n\n# Code\n\nclass Solution:\n def sumOfFlooredPairs(self, nums: List[int]) -> int:\n n,ans = 2*max(nums) + 11,0\n p,arr = [0 for _ in range(n)],[
culer2024
NORMAL
2023-08-17T18:13:37.750104+00:00
2023-08-17T18:13:37.750137+00:00
29
false
\n\n# Code\n```\nclass Solution:\n def sumOfFlooredPairs(self, nums: List[int]) -> int:\n n,ans = 2*max(nums) + 11,0\n p,arr = [0 for _ in range(n)],[]\n for i in nums:\n p[i] += 1 \n if p[i] == 1 : arr.append(i)\n arr.sort()\n for i in range(1,n): p[i] += p[i-1] \n for x ...
0
0
['Python3']
0
sum-of-floored-pairs
🔥O(1) SC || ✅Easy & Clean Code✅ || 🌟Binary Search💯
o1-sc-easy-clean-code-binary-search-by-a-gx5g
Complexity\n- Time complexity:\nO(nlogn)\n\n- Space complexity:\nO(1)\n\n# Code\n## Please Upvote if u found my Solution useful\uD83E\uDD17\n\nclass Solution {\
aDish_21
NORMAL
2023-08-01T20:11:08.642334+00:00
2023-08-01T20:11:08.642358+00:00
129
false
# Complexity\n- Time complexity:\nO(nlogn)\n\n- Space complexity:\nO(1)\n\n# Code\n## Please Upvote if u found my Solution useful\uD83E\uDD17\n```\nclass Solution {\npublic:\n int mod = 1e9 + 7;\n int sumOfFlooredPairs(vector<int>& nums) {\n sort(nums.begin(),nums.end());\n int n = nums.size(), i = ...
0
0
['Array', 'Math', 'Binary Search', 'C++']
0
sum-of-floored-pairs
Counting I guesssss
counting-i-guesssss-by-stolenfuture-lnoi
Complexity\n- Time complexity:\n Add your time complexity here, e.g. O(n) \nO(n + max_num * log(max_num))\n- Space complexity:\n Add your space complexity here,
StolenFuture
NORMAL
2023-06-11T21:58:45.042290+00:00
2023-06-11T21:58:45.042319+00:00
34
false
# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n$$O(n + max_num * log(max_num))$$\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n$$O(maxnum)$$\n# Code\n```\nclass Solution:\n def sumOfFlooredPairs(self, nums: List[int]) -> int:\n MOD = 10...
0
0
['Python3']
0
sum-of-floored-pairs
Factor Frequency Prefix Sum w/Num Frequency Product | Commented and Explained | O(N) T/S
factor-frequency-prefix-sum-wnum-frequen-uwrr
Intuition\n Describe your first thoughts on how to solve this problem. \nThe problem description is deceptively simple and at first a brute force even seems a l
laichbr
NORMAL
2023-05-31T12:57:18.839045+00:00
2023-05-31T12:57:18.839074+00:00
18
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe problem description is deceptively simple and at first a brute force even seems a likely and doable option, for which I got 19/51 and then 25/51 with first Time and then Memory limit expired. From this, it becomes more obvious that we...
0
0
['Python3']
0
sum-of-floored-pairs
C# version that minimizes the number of iterations in loops.
c-version-that-minimizes-the-number-of-i-q21b
Intuition\nInitial thought was nested loops, however that was inefficient.\n\n# Approach\nCreate an array that contains the frequency, or count, of each number
TwistedStem
NORMAL
2023-05-31T02:24:47.082083+00:00
2023-05-31T02:24:47.082119+00:00
17
false
# Intuition\nInitial thought was nested loops, however that was inefficient.\n\n# Approach\nCreate an array that contains the frequency, or count, of each number in the given array. Create a second array that contains the prepared summation counts.\n\nLooping through the frequency map, determine the count by taking th...
0
0
['C#']
0
sum-of-floored-pairs
C++
c-by-tinachien-kgmo
\nusing LL = long long ;\nclass Solution {\n int maxN = 1e5 ;\n int M = 1e9 + 7 ;\npublic:\n int sumOfFlooredPairs(vector<int>& nums) {\n int n
TinaChien
NORMAL
2023-05-01T06:57:23.758509+00:00
2023-05-01T06:57:23.758540+00:00
27
false
```\nusing LL = long long ;\nclass Solution {\n int maxN = 1e5 ;\n int M = 1e9 + 7 ;\npublic:\n int sumOfFlooredPairs(vector<int>& nums) {\n int n = nums.size() ;\n vector<int>count(maxN + 1) ;\n vector<LL>presum(maxN + 1) ;\n for(auto& x : nums)\n count[x]++ ;\n f...
0
0
[]
0
sum-of-floored-pairs
C++ implementation | SOE and Prefix SUM
c-implementation-soe-and-prefix-sum-by-k-13gn
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n1. calculate sieve arra
kumarsubham373
NORMAL
2023-04-23T09:29:29.460420+00:00
2023-04-23T09:29:29.460465+00:00
122
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. calculate sieve array\n2. calculate prefix sum of sieve array\n3. iterate a loop to find the value and update the sum value.\n\n# Complexity\n- Time complexity:\n- ...
0
0
['C++']
0
sum-of-floored-pairs
concept of map, freq and SOE
concept-of-map-freq-and-soe-by-yashsharm-a32h
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
YashSharma2210
NORMAL
2023-04-23T09:25:46.107406+00:00
2023-04-23T09:25:46.107456+00:00
73
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
sum-of-floored-pairs
Algorithm for Integer Arrays
algorithm-for-integer-arrays-by-setunico-l3vu
\n\nfunction sumOfFlooredPairs(nums) {\n const MOD = 1000000007;\n const maxNum = Math.max(...nums);\n const freq = new Array(maxNum + 1).fill(0);\n for (le
setunicode
NORMAL
2023-04-04T15:28:51.218172+00:00
2023-04-04T15:28:51.218213+00:00
36
false
\n```\nfunction sumOfFlooredPairs(nums) {\n const MOD = 1000000007;\n const maxNum = Math.max(...nums);\n const freq = new Array(maxNum + 1).fill(0);\n for (let num of nums) {\n freq[num]++;\n }\n for (let i = 1; i <= maxNum; i++) {\n freq[i] += freq[i - 1];\n }\n let res = 0;\n for (let i = 1; i <= maxN...
0
0
['JavaScript']
0
sum-of-floored-pairs
Best java 35ms
best-java-35ms-by-ht38nhatphan-srnp
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
ht38nhatphan
NORMAL
2023-04-02T20:52:23.156345+00:00
2023-04-02T20:52:23.156384+00:00
138
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
sum-of-floored-pairs
3 Solutions Python
3-solutions-python-by-sarthakbhandari-r5pp
Harmonic Series: 1/1 + 1/2 + 1/3 + .... + 1/n is logarithmic https://en.wikipedia.org/wiki/Harmonic_series_(mathematics)\nThis fact is used in deriving time co
sarthakBhandari
NORMAL
2023-03-16T23:50:58.136424+00:00
2023-03-16T23:56:50.178982+00:00
38
false
Harmonic Series: `1/1 + 1/2 + 1/3 + .... + 1/n` is logarithmic https://en.wikipedia.org/wiki/Harmonic_series_(mathematics)\nThis fact is used in deriving time complexities\n\n**Binary Search Approach\nTime: O(n * logn * logn)\nSpace: O(n)**\n```\ndef sumOfFlooredPairs(self, nums: List[int]) -> int:\n mx = max(nums)...
0
0
['Math', 'Binary Search', 'Prefix Sum']
0
sum-of-floored-pairs
Python (Simple Hashmap + Prefix Sum)
python-simple-hashmap-prefix-sum-by-rnot-u79c
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
rnotappl
NORMAL
2023-03-06T13:07:24.845886+00:00
2023-03-06T13:07:24.845932+00:00
50
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
sum-of-floored-pairs
Python3 Solution With Prefix Sum
python3-solution-with-prefix-sum-by-ixuh-0e8i
\nclass Solution:\n def sumOfFlooredPairs(self, nums: List[int]) -> int:\n \n num_max = max(nums) + 1\n counter = [0]*(num_max)\n
ixuhangyi
NORMAL
2022-12-31T12:53:05.583149+00:00
2022-12-31T12:55:09.023358+00:00
101
false
```\nclass Solution:\n def sumOfFlooredPairs(self, nums: List[int]) -> int:\n \n num_max = max(nums) + 1\n counter = [0]*(num_max)\n \n for n in nums:\n counter[n] += 1\n \n counter_prefix = [0] * (num_max)\n counter_prefix[0] = counter[0]\n ...
0
0
['Python']
0
sum-of-floored-pairs
Python Easy to Understand Solution | Sorting | Binary Search
python-easy-to-understand-solution-sorti-ycph
\n\n# Code\n\nclass Solution:\n def sumOfFlooredPairs(self, nums: List[int]) -> int:\n nums.sort()\n res, mod, cache = 0, 1000000007, {}\n
hemantdhamija
NORMAL
2022-12-08T11:01:28.171565+00:00
2022-12-08T11:01:28.171613+00:00
174
false
\n\n# Code\n```\nclass Solution:\n def sumOfFlooredPairs(self, nums: List[int]) -> int:\n nums.sort()\n res, mod, cache = 0, 1000000007, {}\n for idx, num in enumerate(nums):\n if num in cache:\n res += cache[num]\n else:\n currentRes, j = 0, i...
0
0
['Binary Search', 'Sorting', 'Python', 'Python3']
0
sum-of-floored-pairs
sort and count values in range using binary search
sort-and-count-values-in-range-using-bin-piyb
\nfrom collections import Counter\nimport bisect\n\nclass Solution:\n def sumOfFlooredPairs(self, nums: List[int]) -> int:\n n = len(nums)\n ct
theabbie
NORMAL
2022-11-27T06:17:19.286732+00:00
2022-11-27T06:17:19.286768+00:00
109
false
```\nfrom collections import Counter\nimport bisect\n\nclass Solution:\n def sumOfFlooredPairs(self, nums: List[int]) -> int:\n n = len(nums)\n ctr = Counter(nums)\n nums.sort()\n res = 0\n for el in ctr:\n mul = 1\n while el * mul <= nums[-1]:\n ...
0
0
['Python']
0
sum-of-floored-pairs
Easy C++ solution || commented
easy-c-solution-commented-by-saiteja_bal-xsgb
\nclass Solution {\npublic:\n #define ll long long\n #define MOD 1000000007;\n int sumOfFlooredPairs(vector<int>& nums) {\n ll ans=0;\n l
saiteja_balla0413
NORMAL
2022-10-29T14:27:11.171513+00:00
2022-10-29T14:27:11.171542+00:00
65
false
```\nclass Solution {\npublic:\n #define ll long long\n #define MOD 1000000007;\n int sumOfFlooredPairs(vector<int>& nums) {\n ll ans=0;\n long long last=1e5;\n //store the frequencies as a prefix sum\n vector<ll> pref(1e5+1,0);\n for(int i=0;i<nums.size();i++)\n p...
0
0
[]
0
sum-of-floored-pairs
✔️ Java solution: faster than 98.7% of other submissions
java-solution-faster-than-987-of-other-s-w5vg
This Github repository, https://github.com/AnasImloul/Leetcode-solutions, have all the solutions I was looking for.\nIt is extremely beneficial to have every so
Kagoot
NORMAL
2022-08-21T21:53:02.836091+00:00
2022-08-21T21:53:02.836123+00:00
223
false
This Github repository, https://github.com/AnasImloul/Leetcode-solutions, have all the solutions I was looking for.\nIt is extremely beneficial to have every solution available in one place. I hope it is useful to you as well.\n```\nclass Solution {\n public int sumOfFlooredPairs(int[] nums) {\n Arrays.sort(n...
0
0
['Java']
0
sum-of-floored-pairs
Java | O(nlogn) | Number theory
java-onlogn-number-theory-by-utsav_deep-e1t5
\nclass Solution {\n public int sumOfFlooredPairs(int[] nums) {\n Arrays.sort(nums);\n int n=nums.length;\n long cnt[]=new long[nums[n-1
utsav_deep
NORMAL
2022-06-15T06:25:15.100258+00:00
2022-06-15T06:27:30.129486+00:00
296
false
```\nclass Solution {\n public int sumOfFlooredPairs(int[] nums) {\n Arrays.sort(nums);\n int n=nums.length;\n long cnt[]=new long[nums[n-1]+2];\n for(int num:nums){\n cnt[num+1]++;\n }\n for(int i=1;i<cnt.length;i++){\n cnt[i]+=cnt[i-1];\n }\n ...
0
0
['Math', 'Java']
0
sum-of-floored-pairs
prefix sum for couting frequency otherwise brute force
prefix-sum-for-couting-frequency-otherwi-akrm
\nclass Solution {\npublic:\n int sumOfFlooredPairs(vector<int>& a) \n {\n int n=a.size();\n int fre[200005]; memset(fre,0,sizeof(fre));\n
diyora13
NORMAL
2022-06-09T10:44:31.140203+00:00
2022-06-09T10:44:31.140249+00:00
226
false
```\nclass Solution {\npublic:\n int sumOfFlooredPairs(vector<int>& a) \n {\n int n=a.size();\n int fre[200005]; memset(fre,0,sizeof(fre));\n map<int,int> mp;\n for(int i=0;i<n;i++)\n mp[a[i]]++,fre[a[i]]++;\n for(int i=1;i<200005;i++)\n fre[i]+=fre[i-1];\n...
0
0
['C', 'Prefix Sum', 'C++']
0
sum-of-floored-pairs
C++ NUMBER THEORY || SEIVE LIKE SOLUTION
c-number-theory-seive-like-solution-by-z-bfz1
\n int sumOfFlooredPairs(vector<int>& A ) {\n \n int mod = 1e9;\n mod += 7 ;\n\n int mx = *max_element(A.begin(),A.end());\n
zerojude
NORMAL
2022-05-31T03:12:08.135447+00:00
2022-05-31T03:12:08.135488+00:00
231
false
```\n int sumOfFlooredPairs(vector<int>& A ) {\n \n int mod = 1e9;\n mod += 7 ;\n\n int mx = *max_element(A.begin(),A.end());\n mx = 2*mx+1 ;\n \n vector<int>t(mx,0);\n \n for( auto x : A )\n t[x]++;\n \n vector<int>P(mx+1,0);\n ...
0
0
['C']
0
sum-of-floored-pairs
[Python] nln(n) time complexity. Count, sort and enumerate
python-nlnn-time-complexity-count-sort-a-0o2m
First count nums and sort, we mark largerst value + 1 as n, use presum to calculate how many numbers are less or equeal to v in array precnt. Then we iterate al
cava
NORMAL
2022-05-26T07:57:07.909937+00:00
2022-05-26T07:57:07.909970+00:00
160
false
First count nums and sort, we mark largerst value + 1 as n, use presum to calculate how many numbers are less or equeal to v in array *precnt*. Then we iterate all *k, v* pair in *cnt*, *v (precnt[min((t + 1) k - 1, n - 1)] - precnt[t k - 1]) t* will contribute to answer. For example nums = [2,3,4,5,6,7,8], k = 2...
0
0
[]
0
sum-of-floored-pairs
Rust Solution
rust-solution-by-rchaser53-j07d
\nuse std::collections::*;\n\ntype Target = usize;\ntype UseValue = usize;\nfn upper_bound(arr: &Vec<Target>, x: &UseValue) -> usize {\n let mut low = 0;\n le
rchaser53
NORMAL
2022-05-25T13:55:39.380864+00:00
2022-05-25T13:55:39.380901+00:00
79
false
```\nuse std::collections::*;\n\ntype Target = usize;\ntype UseValue = usize;\nfn upper_bound(arr: &Vec<Target>, x: &UseValue) -> usize {\n let mut low = 0;\n let mut high = arr.len();\n while low != high {\n let mid = (low + high) / 2;\n match arr[mid].cmp(x) {\n std::cmp::Ordering::Less | std::cmp::Orde...
0
0
['Rust']
0
sum-of-floored-pairs
Python | Binary Search with bisect_right After Sorting | O(nlogn) | Clean Code
python-binary-search-with-bisect_right-a-kmpw
```\nfrom bisect import bisect_right\n\nclass Solution:\n def sumOfFlooredPairs(self, nums: List[int]) -> int:\n M = 109 + 7\n nums.sort()\n
aryonbe
NORMAL
2022-04-15T03:15:59.535475+00:00
2022-04-22T10:44:31.119543+00:00
159
false
```\nfrom bisect import bisect_right\n\nclass Solution:\n def sumOfFlooredPairs(self, nums: List[int]) -> int:\n M = 10**9 + 7\n nums.sort()\n i = 0\n n = len(nums)\n res = 0\n while i < n:\n cur = nums[i]\n l = bisect_right(nums, cur)\n #num...
0
0
['Binary Search', 'Python']
0
sum-of-floored-pairs
C++ Solution (Got 376 ms runtime)
c-solution-got-376-ms-runtime-by-alamsah-cqoa
Will love to hear the improvements for this code in terms of performance as well as code quality .\n\n\nclass Solution {\n int MOD=1e9+7;\npublic:\n int s
alamsahil939
NORMAL
2022-04-03T19:20:48.324877+00:00
2022-04-04T21:36:57.434803+00:00
198
false
Will love to hear the improvements for this code in terms of performance as well as code quality .\n\n```\nclass Solution {\n int MOD=1e9+7;\npublic:\n int sumOfFlooredPairs(vector<int>& nums) {\n vector<int> freq(1e5+1,0);\n vector<int> validNums;\n int maxNum=INT_MIN;\n for(int i=0;i...
0
0
[]
0
sum-of-floored-pairs
Binary Search Python
binary-search-python-by-saianirudh_me-6w2r
\nclass Solution:\n def sumOfFlooredPairs(self, nums: List[int]) -> int:\n nums.sort()\n r,x=0,len(nums)\n for i in range(len(nums)):\n
saianirudh_me
NORMAL
2022-03-15T11:27:47.435163+00:00
2022-03-15T11:27:47.435193+00:00
113
false
```\nclass Solution:\n def sumOfFlooredPairs(self, nums: List[int]) -> int:\n nums.sort()\n r,x=0,len(nums)\n for i in range(len(nums)):\n if i>0 and nums[i]==nums[i-1]:\n r+=tmp\n continue\n tmp,n,l=0,nums[-1]//nums[i],x\n while n>0...
0
0
[]
0
sum-of-floored-pairs
Java|SimpleSolution:165ms|with|Explanation
javasimplesolution165mswithexplanation-b-o5vs
\n\n/*\nHow did you solve it \n 1. its math solution , we bascailly count the quotient for each number \n \n example if we have 2,5,9 in input \n \n our range w
victordey2007
NORMAL
2022-03-09T20:37:32.560268+00:00
2022-03-09T20:37:32.560311+00:00
123
false
```\n\n/*\nHow did you solve it \n 1. its math solution , we bascailly count the quotient for each number \n \n example if we have 2,5,9 in input \n \n our range will be till 9\n \n 0 1 2 3 4 5 6 7 8 9 \n 2 1 1 1 1\n 5 1\n 9 1\n -------------------------\n 0 0 1 2 3 4 ...
0
0
[]
0
sum-of-floored-pairs
Java prefix sum
java-prefix-sum-by-mi1-a6af
\nclass Solution {\n public int sumOfFlooredPairs(int[] nums) {\n int mod = (int) Math.pow(10,9)+7;\n HashMap<Integer,Integer> map = new HashMa
mi1
NORMAL
2022-02-18T19:48:44.868746+00:00
2022-02-18T19:48:44.868787+00:00
108
false
```\nclass Solution {\n public int sumOfFlooredPairs(int[] nums) {\n int mod = (int) Math.pow(10,9)+7;\n HashMap<Integer,Integer> map = new HashMap<>();\n int max = Arrays.stream(nums).max().getAsInt();\n int [] arr = new int[2*max];\n for(int num : nums){\n arr[num]++;\...
0
0
[]
0
sum-of-floored-pairs
What is wrong with this solution for TLE?
what-is-wrong-with-this-solution-for-tle-jp57
```class Solution {\n public int sumOfFlooredPairs(int[] nums) {\n int sum = 0;\n \n\n ArrayDeque q = new ArrayDeque();\n for(i
nexant9
NORMAL
2022-02-10T04:01:33.550070+00:00
2022-02-10T04:01:33.550095+00:00
92
false
```class Solution {\n public int sumOfFlooredPairs(int[] nums) {\n int sum = 0;\n \n\n ArrayDeque<Integer> q = new ArrayDeque<Integer>();\n for(int i : nums)\n q.offer(i);\n\n while(!q.isEmpty()) {\n int top = q.poll();\n for(int i = 0; i < nums.lengt...
0
1
['Queue']
1
sum-of-floored-pairs
Floored pair
floored-pair-by-yadavanuj109-zpsp
Explanation : \n Sort the array\n Find the prefix sum (ps) where the ith element contains number of elements <= i. \n For eg. sorted arr -> 1, 1, 2, 5
yadavanuj109
NORMAL
2022-02-01T03:47:58.787241+00:00
2022-02-01T03:47:58.787284+00:00
143
false
**Explanation** : \n* Sort the array\n* Find the prefix sum (ps) where the ith element contains number of elements <= i. \n For eg. sorted arr -> 1, 1, 2, 5\n\t prefix sum -> 0, 2, 2, 3, 3, 4\n* Since the array is sorted. Time complexity for finding the floored sum will be O(n)\n **Reason** : ...
0
0
['Math', 'Prefix Sum']
0