diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index d254bbf..3f60590 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -5,7 +5,10 @@
-
+
+
+
+
@@ -51,8 +54,8 @@
@@ -70,29 +73,29 @@
- {
+ "keyToString": {
+ "ASKED_ADD_EXTERNAL_FILES": "true",
+ "RunOnceActivity.OpenProjectViewOnStart": "true",
+ "RunOnceActivity.ShowReadmeOnStart": "true",
+ "com.intellij.testIntegration.createTest.CreateTestDialog.defaultLibrary": "JUnit5",
+ "com.intellij.testIntegration.createTest.CreateTestDialog.defaultLibrarySuperClass.JUnit5": "",
+ "git-widget-placeholder": "main"
}
-}]]>
+}
+
-
-
+
@@ -117,7 +120,7 @@
true
-
+
@@ -130,7 +133,7 @@
-
+
@@ -141,7 +144,7 @@
true
-
+
@@ -154,7 +157,7 @@
-
+
@@ -215,11 +218,11 @@
+
+
-
-
@@ -255,6 +258,11 @@
6
+
+ file://$PROJECT_DIR$/src/test/java/problemset/a2251/FullBloomTest.java
+ 38
+
+
diff --git a/src/main/java/datastructures/Pair.java b/src/main/java/datastructures/Pair.java
new file mode 100644
index 0000000..b51bec4
--- /dev/null
+++ b/src/main/java/datastructures/Pair.java
@@ -0,0 +1,19 @@
+package datastructures;
+
+public class Pair {
+ private Integer index;
+ private Integer person;
+
+ public Pair(Integer index, Integer person) {
+ this.index = index;
+ this.person = person;
+ }
+
+ public Integer getIndex() {
+ return index;
+ }
+
+ public Integer getPerson() {
+ return person;
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/problemset/a2251/FullBloom.java b/src/main/java/problemset/a2251/FullBloom.java
new file mode 100644
index 0000000..dbfba1e
--- /dev/null
+++ b/src/main/java/problemset/a2251/FullBloom.java
@@ -0,0 +1,38 @@
+package problemset.a2251;
+
+import java.util.*;
+
+public class FullBloom {
+
+ public int[] fullBloomFlowers(int[][] flowers, int[] people) {
+ int[] res = new int[people.length];
+ int count = 0;
+ PriorityQueue start = new PriorityQueue<>();
+ PriorityQueue end = new PriorityQueue<>();
+ for (int[] flower : flowers) {
+ start.add(flower[0]);
+ end.add(flower[1]);
+ }
+
+ TreeMap map = new TreeMap<>();
+ for (int i = 0; i < people.length; i++) {
+ map.put(i, people[i]);
+ }
+
+ for (Map.Entry entry : map.entrySet()) {
+ int p = entry.getValue();
+ int i = entry.getKey();
+ while (!start.isEmpty() && start.peek() <= p) {
+ start.poll();
+ count++;
+ }
+ while (!end.isEmpty() && end.peek() < p) {
+ end.poll();
+ count--;
+ }
+
+ res[i] = count;
+ }
+ return res;
+ }
+}
diff --git a/src/test/java/problemset/a2251/FullBloomTest.java b/src/test/java/problemset/a2251/FullBloomTest.java
new file mode 100644
index 0000000..ad8cc0f
--- /dev/null
+++ b/src/test/java/problemset/a2251/FullBloomTest.java
@@ -0,0 +1,41 @@
+package problemset.a2251;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+class FullBloomTest {
+
+ private FullBloom fullBloom;
+
+ private int[][] testcaseOne;
+ private int[] peopleOne;
+ private int[][] testcaseTwo;
+ private int[] peopleTwo;
+
+ @BeforeEach
+ void setUp() {
+ fullBloom = new FullBloom();
+
+ testcaseOne = new int[][]{{1, 6}, {3, 7}, {9, 12}, {4, 13}};
+ peopleOne = new int[]{2, 3, 7, 11};
+
+ testcaseTwo = new int[][]{{1, 10}, {3, 3}};
+ peopleTwo = new int[]{3, 3, 2};
+ }
+
+ @Test
+ void test_fullBloomFlowers() {
+ int[] expectedResult = new int[]{1, 2, 2, 2};
+ int[] actualResult = fullBloom.fullBloomFlowers(testcaseOne, peopleOne);
+ assertArrayEquals(expectedResult, actualResult);
+ }
+
+ @Test
+ void test_fullBloomFlowers_v2() {
+ int[] expectedResult = new int[]{2, 2, 1};
+ int[] actualResult = fullBloom.fullBloomFlowers(testcaseTwo, peopleTwo);
+ assertArrayEquals(expectedResult, actualResult);
+ }
+}
\ No newline at end of file