File tree Expand file tree Collapse file tree 1 file changed +0
-5
lines changed
src/main/java/g3301_3400/s3395_subsequences_with_a_unique_middle_mode_i Expand file tree Collapse file tree 1 file changed +0
-5
lines changed Original file line number Diff line number Diff line change 8
8
import java .util .Map ;
9
9
10
10
public class Solution {
11
-
12
11
private static final int MOD = 1000000007 ;
13
12
14
13
public int subsequencesWithMiddleMode (int [] a ) {
15
14
int n = a .length ;
16
-
17
15
// Create a dictionary to store indices of each number
18
16
Map <Integer , List <Integer >> dict = new HashMap <>();
19
17
for (int i = 0 ; i < n ; i ++) {
20
18
dict .computeIfAbsent (a [i ], k -> new ArrayList <>()).add (i );
21
19
}
22
-
23
20
long ans = 0L ;
24
-
25
21
// Iterate over each unique number and its indices
26
22
for (Map .Entry <Integer , List <Integer >> entry : dict .entrySet ()) {
27
23
List <Integer > b = entry .getValue ();
28
24
int m = b .size ();
29
-
30
25
for (int k = 0 ; k < m ; k ++) {
31
26
int i = b .get (k );
32
27
int r = m - 1 - k ;
You can’t perform that action at this time.
0 commit comments