Skip to content

Commit 3973ef6

Browse files
committed
Updated tags
1 parent 50b2e37 commit 3973ef6

File tree

8 files changed

+227
-182
lines changed

8 files changed

+227
-182
lines changed

src/main/java/g3701_3800/s3707_equal_score_substrings/Solution.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package g3701_3800.s3707_equal_score_substrings;
22

3-
// #Easy #Biweekly_Contest_167 #2025_10_13_Time_1_ms_(100.00%)_Space_42.24_MB_(96.38%)
3+
// #Easy #String #Prefix_Sum #Biweekly_Contest_167
4+
// #2025_10_14_Time_1_ms_(100.00%)_Space_42.65_MB_(41.05%)
45

56
public class Solution {
67
public boolean scoreBalance(String s) {

src/main/java/g3701_3800/s3708_longest_fibonacci_subarray/Solution.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package g3701_3800.s3708_longest_fibonacci_subarray;
22

3-
// #Medium #Biweekly_Contest_167 #2025_10_13_Time_1_ms_(100.00%)_Space_58.20_MB_(81.69%)
3+
// #Medium #Array #Biweekly_Contest_167 #2025_10_14_Time_1_ms_(100.00%)_Space_58.41_MB_(37.64%)
44

55
public class Solution {
66
public int longestSubarray(int[] nums) {

src/main/java/g3701_3800/s3709_design_exam_scores_tracker/ExamTracker.java

Lines changed: 42 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,69 @@
11
package g3701_3800.s3709_design_exam_scores_tracker;
22

3-
// #Medium #Biweekly_Contest_167 #2025_10_13_Time_114_ms_(100.00%)_Space_101.17_MB_(89.67%)
3+
// #Medium #Array #Binary_Search #Design #Prefix_Sum #Biweekly_Contest_167
4+
// #2025_10_14_Time_102_ms_(99.55%)_Space_101.26_MB_(83.89%)
45

56
import java.util.ArrayList;
6-
import java.util.List;
77

88
@SuppressWarnings("java:S6213")
99
public class ExamTracker {
10-
List<Integer> arr = new ArrayList<>();
11-
List<Long> psum = new ArrayList<>();
10+
11+
private final ArrayList<Integer> ti;
12+
private final ArrayList<Long> pr;
13+
14+
public ExamTracker() {
15+
ti = new ArrayList<>();
16+
pr = new ArrayList<>();
17+
}
1218

1319
public void record(int time, int score) {
14-
arr.add(time);
15-
if (psum.isEmpty()) {
16-
psum.add((long) score);
17-
} else {
18-
psum.add(psum.get(psum.size() - 1) + score);
19-
}
20+
ti.add(time);
21+
long pv = pr.isEmpty() ? 0L : pr.get(pr.size() - 1);
22+
pr.add(pv + (long) score);
2023
}
2124

2225
public long totalScore(int startTime, int endTime) {
23-
int start = bs(startTime);
24-
int end = be(endTime);
25-
26-
if (start > end || start == arr.size() || end == -1) {
27-
return 0;
26+
int n = ti.size();
27+
if (n == 0) {
28+
return 0L;
2829
}
29-
30-
long total = 0;
31-
total += psum.get(end);
32-
if (start - 1 >= 0) {
33-
total -= psum.get(start - 1);
30+
int l = lB(startTime);
31+
int rE = fGt(endTime);
32+
int r = rE - 1;
33+
if (l > r) {
34+
return 0L;
3435
}
35-
return total;
36+
long sR = pr.get(r);
37+
long sL = (l > 0) ? pr.get(l - 1) : 0L;
38+
return sR - sL;
3639
}
3740

38-
public int bs(int startTime) {
39-
int low = 0;
40-
int high = arr.size() - 1;
41-
42-
int ans = arr.size();
43-
while (low <= high) {
44-
int mid = (low + high) / 2;
45-
if (arr.get(mid) >= startTime) {
46-
ans = mid;
47-
high = mid - 1;
41+
private int lB(int t) {
42+
int l = 0;
43+
int r = ti.size();
44+
while (l < r) {
45+
int m = (l + r) >>> 1;
46+
if (ti.get(m) < t) {
47+
l = m + 1;
4848
} else {
49-
low = mid + 1;
49+
r = m;
5050
}
5151
}
52-
53-
return ans;
52+
return l;
5453
}
5554

56-
public int be(int endTime) {
57-
int low = 0;
58-
int high = arr.size() - 1;
59-
60-
int ans = -1;
61-
while (low <= high) {
62-
int mid = (low + high) / 2;
63-
if (arr.get(mid) <= endTime) {
64-
ans = mid;
65-
low = mid + 1;
55+
private int fGt(int t) {
56+
int l = 0;
57+
int r = ti.size();
58+
while (l < r) {
59+
int m = (l + r) >>> 1;
60+
if (ti.get(m) <= t) {
61+
l = m + 1;
6662
} else {
67-
high = mid - 1;
63+
r = m;
6864
}
6965
}
70-
71-
return ans;
66+
return l;
7267
}
7368
}
7469

Lines changed: 51 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,70 @@
11
package g3701_3800.s3710_maximum_partition_factor;
22

3-
// #Hard #Biweekly_Contest_167 #2025_10_13_Time_305_ms_(50.00%)_Space_55.41_MB_(49.74%)
3+
// #Hard #Array #Binary_Search #Graph #Union_Find #Biweekly_Contest_167 #Depth_First_Search
4+
// #Breadth_First_Search #2025_10_14_Time_46_ms_(99.31%)_Space_45.31_MB_(84.72%)
45

5-
import java.util.ArrayList;
6-
import java.util.Comparator;
7-
import java.util.HashMap;
8-
import java.util.List;
9-
import java.util.Map;
6+
import java.util.Arrays;
107

118
public class Solution {
12-
public int maxPartitionFactor(int[][] arr) {
13-
int n = arr.length;
9+
public int maxPartitionFactor(int[][] points) {
10+
int n = points.length;
1411
if (n == 2) {
1512
return 0;
1613
}
17-
// Step 1: Create list of (distance, i, j)
18-
List<int[]> edges = new ArrayList<>();
14+
int[][] dist = new int[n][n];
15+
int maxDist = 0;
1916
for (int i = 0; i < n; i++) {
2017
for (int j = i + 1; j < n; j++) {
21-
int d = Math.abs(arr[i][0] - arr[j][0]) + Math.abs(arr[i][1] - arr[j][1]);
22-
edges.add(new int[] {d, i, j});
18+
int d =
19+
Math.abs(points[i][0] - points[j][0])
20+
+ Math.abs(points[i][1] - points[j][1]);
21+
dist[i][j] = dist[j][i] = d;
22+
if (d > maxDist) {
23+
maxDist = d;
24+
}
2325
}
2426
}
25-
// Step 2: Sort by distance
26-
edges.sort(Comparator.comparingInt(a -> a[0]));
27-
// Step 3: Union-Find setup
28-
int[] parent = new int[n];
29-
int[] weight = new int[n];
30-
for (int i = 0; i < n; i++) {
31-
parent[i] = i;
32-
weight[i] = 1;
33-
}
34-
Map<Integer, Integer> opp = new HashMap<>();
35-
// Step 4: Process edges
36-
for (int[] e : edges) {
37-
int d = e[0];
38-
int i = e[1];
39-
int j = e[2];
40-
if (find(i, parent) == find(j, parent)) {
41-
return d;
42-
}
43-
if (opp.containsKey(i)) {
44-
union(opp.get(i), j, parent, weight);
27+
int low = 0;
28+
int high = maxDist;
29+
while (low < high) {
30+
int mid = low + (high - low + 1) / 2;
31+
if (isFeasible(dist, mid)) {
32+
low = mid;
33+
} else {
34+
high = mid - 1;
4535
}
46-
if (opp.containsKey(j)) {
47-
union(opp.get(j), i, parent, weight);
48-
}
49-
opp.put(i, j);
50-
opp.put(j, i);
5136
}
52-
return edges.get(edges.size() - 1)[0];
37+
return low;
5338
}
5439

55-
private int find(int a, int[] parent) {
56-
if (parent[a] != a) {
57-
parent[a] = find(parent[a], parent);
58-
}
59-
return parent[a];
60-
}
61-
62-
private void union(int x, int y, int[] parent, int[] weight) {
63-
x = find(x, parent);
64-
y = find(y, parent);
65-
if (x == y) {
66-
return;
67-
}
68-
if (weight[x] < weight[y]) {
69-
int temp = x;
70-
x = y;
71-
y = temp;
40+
private boolean isFeasible(int[][] dist, int t) {
41+
int n = dist.length;
42+
int[] color = new int[n];
43+
Arrays.fill(color, -1);
44+
int[] queue = new int[n];
45+
for (int i = 0; i < n; i++) {
46+
if (color[i] != -1) {
47+
continue;
48+
}
49+
int head = 0;
50+
int tail = 0;
51+
queue[tail++] = i;
52+
color[i] = 0;
53+
while (head < tail) {
54+
int u = queue[head++];
55+
for (int v = 0; v < n; v++) {
56+
if (u == v || dist[u][v] >= t) {
57+
continue;
58+
}
59+
if (color[v] == -1) {
60+
color[v] = color[u] ^ 1;
61+
queue[tail++] = v;
62+
} else if (color[v] == color[u]) {
63+
return false;
64+
}
65+
}
66+
}
7267
}
73-
weight[y] += weight[x];
74-
parent[x] = y;
68+
return true;
7569
}
7670
}

src/main/java/g3701_3800/s3712_sum_of_elements_with_frequency_divisible_by_k/Solution.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package g3701_3800.s3712_sum_of_elements_with_frequency_divisible_by_k;
22

3-
// #Easy #Weekly_Contest_471 #2025_10_13_Time_1_ms_(99.96%)_Space_42.21_MB_(100.00%)
3+
// #Easy #Array #Hash_Table #Counting #Weekly_Contest_471
4+
// #2025_10_14_Time_1_ms_(99.96%)_Space_42.30_MB_(98.20%)
45

56
public class Solution {
67
public int sumDivisibleByK(int[] nums, int k) {

src/main/java/g3701_3800/s3713_longest_balanced_substring_i/Solution.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package g3701_3800.s3713_longest_balanced_substring_i;
22

3-
// #Medium #Weekly_Contest_471 #2025_10_13_Time_34_ms_(99.73%)_Space_45.52_MB_(50.00%)
3+
// #Medium #String #Hash_Table #Counting #Enumeration #Weekly_Contest_471
4+
// #2025_10_14_Time_32_ms_(99.85%)_Space_45.25_MB_(91.33%)
45

56
public class Solution {
67
public int longestBalanced(String s) {

0 commit comments

Comments
 (0)