Skip to content

Commit d17a7e0

Browse files
authored
Merge branch 'master' into add-library-sort
2 parents b93a13a + 0125123 commit d17a7e0

5 files changed

Lines changed: 25 additions & 10 deletions

File tree

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
steps:
1111
- uses: actions/checkout@v7
1212
- name: Set up JDK
13-
uses: actions/setup-java@v5.4.0
13+
uses: actions/setup-java@v5.5.0
1414
with:
1515
java-version: 21
1616
distribution: 'temurin'

.github/workflows/codeql.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,21 @@ jobs:
2424
uses: actions/checkout@v7
2525

2626
- name: Set up JDK
27-
uses: actions/setup-java@v5.4.0
27+
uses: actions/setup-java@v5.5.0
2828
with:
2929
java-version: 21
3030
distribution: 'temurin'
3131

3232
- name: Initialize CodeQL
33-
uses: github/codeql-action/init@v4.36.2
33+
uses: github/codeql-action/init@v4.36.3
3434
with:
3535
languages: 'java-kotlin'
3636

3737
- name: Build
3838
run: mvn --batch-mode --update-snapshots verify
3939

4040
- name: Perform CodeQL Analysis
41-
uses: github/codeql-action/analyze@v4.36.2
41+
uses: github/codeql-action/analyze@v4.36.3
4242
with:
4343
category: "/language:java-kotlin"
4444

@@ -55,12 +55,12 @@ jobs:
5555
uses: actions/checkout@v7
5656

5757
- name: Initialize CodeQL
58-
uses: github/codeql-action/init@v4.36.2
58+
uses: github/codeql-action/init@v4.36.3
5959
with:
6060
languages: 'actions'
6161

6262
- name: Perform CodeQL Analysis
63-
uses: github/codeql-action/analyze@v4.36.2
63+
uses: github/codeql-action/analyze@v4.36.3
6464
with:
6565
category: "/language:actions"
6666
...

.github/workflows/infer.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
- uses: actions/checkout@v7
1919

2020
- name: Set up JDK
21-
uses: actions/setup-java@v5.4.0
21+
uses: actions/setup-java@v5.5.0
2222
with:
2323
java-version: 21
2424
distribution: 'temurin'

.github/workflows/stale.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
pull-requests: write
1212
runs-on: ubuntu-latest
1313
steps:
14-
- uses: actions/stale@v10
14+
- uses: actions/stale@v10.3.0
1515
with:
1616
stale-issue-message: 'This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contribution!'
1717
close-issue-message: 'Please reopen this issue once you have made the required changes. If you need help, feel free to ask in our [Discord](https://the-algorithms.com/discord) server or ping one of the maintainers here. Thank you for your contribution!'

src/main/java/com/thealgorithms/graph/AccountMerge.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,25 @@
1010
/**
1111
* Merges account records using Disjoint Set Union (Union-Find) on shared emails.
1212
*
13-
* <p>Input format: each account is a list where the first element is the user name and the
14-
* remaining elements are emails.
13+
* <p>Each account is expected to be a list where the first element is the user name and the
14+
* remaining elements are email addresses. Accounts that share at least one email are merged into a
15+
* single record.
1516
*/
1617
public final class AccountMerge {
1718
private AccountMerge() {
19+
// Utility class; do not instantiate.
1820
}
1921

22+
/**
23+
* Merges accounts that share one or more email addresses.
24+
*
25+
* <p>The returned list is sorted by account owner name, then by the first email address when
26+
* multiple merged groups have the same owner name. Within each merged account, emails are
27+
* returned in lexicographic order.
28+
*
29+
* @param accounts a list of accounts where each entry contains a user name followed by emails
30+
* @return merged accounts, or an empty list when {@code accounts} is null or empty
31+
*/
2032
public static List<List<String>> mergeAccounts(List<List<String>> accounts) {
2133
if (accounts == null || accounts.isEmpty()) {
2234
return List.of();
@@ -73,6 +85,9 @@ public static List<List<String>> mergeAccounts(List<List<String>> accounts) {
7385
return merged;
7486
}
7587

88+
/**
89+
* Lightweight union-find structure with path compression and union by rank.
90+
*/
7691
private static final class UnionFind {
7792
private final int[] parent;
7893
private final int[] rank;

0 commit comments

Comments
 (0)