Skip to content

Commit adfe2cd

Browse files
add 1862
1 parent 0cfebce commit adfe2cd

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ _If you like this project, please leave me a star._ ★
88

99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|-----|----------------|---------------|--------|-------------|-------------
11+
|1862|[Sum of Floored Pairs](https://leetcode.com/problems/sum-of-floored-pairs/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1862.java) ||Hard|Math|
1112
|1861|[Rotating the Box](https://leetcode.com/problems/rotating-the-box/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1861.java) ||Medium|Array, Two Pointers|
1213
|1860|[Incremental Memory Leak](https://leetcode.com/problems/incremental-memory-leak/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1860.java) ||Medium|Math|
1314
|1859|[Sorting the Sentence](https://leetcode.com/problems/sorting-the-sentence/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1859.java) ||Easy|String, Sort|
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.fishercoder.solutions;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
import java.util.TreeMap;
6+
7+
public class _1862 {
8+
public static class Solution1 {
9+
/**TODO: this results in TLE, fix it.*/
10+
public int sumOfFlooredPairs(int[] nums) {
11+
TreeMap<Integer, Integer> map = new TreeMap<>();
12+
for (int num : nums) {
13+
map.put(num, map.getOrDefault(num, 0) + 1);
14+
}
15+
List<Integer> list = new ArrayList<>(map.keySet());
16+
int mod = 1000000007;
17+
long sum = 0l;
18+
for (int i = list.size() - 1; i >= 0; i--) {
19+
for (int j = i; j >= 0; j--) {
20+
sum += (list.get(i) / list.get(j)) * map.get(list.get(j)) * map.get(list.get(i));
21+
sum %= mod;
22+
}
23+
}
24+
return (int) sum;
25+
}
26+
}
27+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.fishercoder;
2+
3+
import com.fishercoder.solutions._1862;
4+
import org.junit.BeforeClass;
5+
import org.junit.Test;
6+
7+
import static org.junit.Assert.assertEquals;
8+
9+
public class _1862Test {
10+
private static _1862.Solution1 solution1;
11+
12+
@BeforeClass
13+
public static void setup() {
14+
solution1 = new _1862.Solution1();
15+
}
16+
17+
@Test
18+
public void test1() {
19+
assertEquals(49, solution1.sumOfFlooredPairs(new int[]{7, 7, 7, 7, 7, 7, 7}));
20+
}
21+
22+
@Test
23+
public void test2() {
24+
assertEquals(10, solution1.sumOfFlooredPairs(new int[]{2, 5, 9}));
25+
}
26+
27+
@Test
28+
public void test3() {
29+
assertEquals(17, solution1.sumOfFlooredPairs(new int[]{4, 3, 4, 3, 5}));
30+
}
31+
32+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy