Skip to content

Commit 4c3ad97

Browse files
authored
Merge branch 'master' into master
2 parents 7068e54 + a008cc2 commit 4c3ad97

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1023
-71
lines changed

.github/workflows/close-failed-prs.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,13 @@ jobs:
5959
6060
const meaningfulCommits = commits.filter(c => {
6161
const msg = c.commit.message.toLowerCase();
62+
const date = new Date(c.commit.committer.date);
6263
const isMergeFromMain = mainBranches.some(branch =>
6364
msg.startsWith(`merge branch '${branch}'`) ||
6465
msg.includes(`merge remote-tracking branch '${branch}'`)
6566
);
66-
return !isMergeFromMain;
67+
68+
return !isMergeFromMain && date > cutoff;
6769
});
6870
6971
// Get checks with error handling
@@ -151,4 +153,4 @@ jobs:
151153
} catch (error) {
152154
console.error(`❌ Fatal error: ${error.message}`);
153155
throw error;
154-
}
156+
}

DIRECTORY.md

Lines changed: 52 additions & 4 deletions
Large diffs are not rendered by default.

pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@
112112
<dependency>
113113
<groupId>com.puppycrawl.tools</groupId>
114114
<artifactId>checkstyle</artifactId>
115-
<version>12.1.1</version>
115+
<version>12.1.2</version>
116116
</dependency>
117117
</dependencies>
118118
</plugin>
@@ -127,7 +127,7 @@
127127
<plugin>
128128
<groupId>com.mebigfatguy.fb-contrib</groupId>
129129
<artifactId>fb-contrib</artifactId>
130-
<version>7.6.15</version>
130+
<version>7.7.0</version>
131131
</plugin>
132132
<plugin>
133133
<groupId>com.h3xstream.findsecbugs</groupId>
@@ -155,4 +155,4 @@
155155
</plugin>
156156
</plugins>
157157
</build>
158-
</project>
158+
</project>

spotbugs-exclude.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,12 @@
201201
<Match>
202202
<Bug pattern="SPP_FIELD_COULD_BE_STATIC" />
203203
</Match>
204+
<Match>
205+
<Bug pattern="ITC_INHERITANCE_TYPE_CHECKING" />
206+
</Match>
207+
<Match>
208+
<Bug pattern="FII_USE_ARRAYS_STREAM" />
209+
</Match>
204210
<!-- find-sec-bugs -->
205211
<Match>
206212
<Bug pattern="PREDICTABLE_RANDOM" />
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package com.thealgorithms.backtracking;
2+
3+
import java.util.ArrayList;
4+
import java.util.Arrays;
5+
import java.util.List;
6+
7+
/** Backtracking: pick/not-pick with reuse of candidates. */
8+
public final class CombinationSum {
9+
private CombinationSum() {
10+
throw new UnsupportedOperationException("Utility class");
11+
}
12+
13+
public static List<List<Integer>> combinationSum(int[] candidates, int target) {
14+
List<List<Integer>> results = new ArrayList<>();
15+
if (candidates == null || candidates.length == 0) {
16+
return results;
17+
}
18+
19+
// Sort to help with pruning duplicates and early termination
20+
Arrays.sort(candidates);
21+
backtrack(candidates, target, 0, new ArrayList<>(), results);
22+
return results;
23+
}
24+
25+
private static void backtrack(int[] candidates, int remaining, int start, List<Integer> combination, List<List<Integer>> results) {
26+
if (remaining == 0) {
27+
// Found valid combination; add a copy
28+
results.add(new ArrayList<>(combination));
29+
return;
30+
}
31+
32+
for (int i = start; i < candidates.length; i++) {
33+
int candidate = candidates[i];
34+
35+
// If candidate is greater than remaining target, further candidates (sorted) will also be too big
36+
if (candidate > remaining) {
37+
break;
38+
}
39+
40+
// include candidate
41+
combination.add(candidate);
42+
// Because we can reuse the same element, we pass i (not i + 1)
43+
backtrack(candidates, remaining - candidate, i, combination, results);
44+
// backtrack: remove last
45+
combination.remove(combination.size() - 1);
46+
}
47+
}
48+
}

src/main/java/com/thealgorithms/backtracking/FloodFill.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ private FloodFill() {
1212
* Get the color at the given coordinates of a 2D image
1313
*
1414
* @param image The image to be filled
15-
* @param x The x co-ordinate of which color is to be obtained
16-
* @param y The y co-ordinate of which color is to be obtained
15+
* @param x The x coordinate of which color is to be obtained
16+
* @param y The y coordinate of which color is to be obtained
1717
*/
1818

1919
public static int getPixel(final int[][] image, final int x, final int y) {
@@ -24,8 +24,8 @@ public static int getPixel(final int[][] image, final int x, final int y) {
2424
* Put the color at the given coordinates of a 2D image
2525
*
2626
* @param image The image to be filled
27-
* @param x The x co-ordinate at which color is to be filled
28-
* @param y The y co-ordinate at which color is to be filled
27+
* @param x The x coordinate at which color is to be filled
28+
* @param y The y coordinate at which color is to be filled
2929
*/
3030
public static void putPixel(final int[][] image, final int x, final int y, final int newColor) {
3131
image[x][y] = newColor;
@@ -35,8 +35,8 @@ public static void putPixel(final int[][] image, final int x, final int y, final
3535
* Fill the 2D image with new color
3636
*
3737
* @param image The image to be filled
38-
* @param x The x co-ordinate at which color is to be filled
39-
* @param y The y co-ordinate at which color is to be filled
38+
* @param x The x coordinate at which color is to be filled
39+
* @param y The y coordinate at which color is to be filled
4040
* @param newColor The new color which to be filled in the image
4141
* @param oldColor The old color which is to be replaced in the image
4242
*/
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
package com.thealgorithms.bitmanipulation;
2+
3+
/**
4+
* Utility class for performing circular bit rotations on 32-bit integers.
5+
* Bit rotation is a circular shift operation where bits shifted out on one end
6+
* are reinserted on the opposite end.
7+
*
8+
* <p>This class provides methods for both left and right circular rotations,
9+
* supporting only 32-bit integer operations with proper shift normalization
10+
* and error handling.</p>
11+
*
12+
* @see <a href="https://en.wikipedia.org/wiki/Bit_rotation">Bit Rotation</a>
13+
*/
14+
public final class BitRotate {
15+
16+
/**
17+
* Private constructor to prevent instantiation.
18+
* This is a utility class with only static methods.
19+
*/
20+
private BitRotate() {
21+
throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
22+
}
23+
24+
/**
25+
* Performs a circular left rotation (left shift) on a 32-bit integer.
26+
* Bits shifted out from the left side are inserted on the right side.
27+
*
28+
* @param value the 32-bit integer value to rotate
29+
* @param shift the number of positions to rotate left (must be non-negative)
30+
* @return the result of left rotating the value by the specified shift amount
31+
* @throws IllegalArgumentException if shift is negative
32+
*
33+
* @example
34+
* // Binary: 10000000 00000000 00000000 00000001
35+
* rotateLeft(0x80000001, 1)
36+
* // Returns: 3 (binary: 00000000 00000000 00000000 00000011)
37+
*/
38+
public static int rotateLeft(int value, int shift) {
39+
if (shift < 0) {
40+
throw new IllegalArgumentException("Shift amount cannot be negative: " + shift);
41+
}
42+
43+
// Normalize shift to the range [0, 31] using modulo 32
44+
shift = shift % 32;
45+
46+
if (shift == 0) {
47+
return value;
48+
}
49+
50+
// Left rotation: (value << shift) | (value >>> (32 - shift))
51+
return (value << shift) | (value >>> (32 - shift));
52+
}
53+
54+
/**
55+
* Performs a circular right rotation (right shift) on a 32-bit integer.
56+
* Bits shifted out from the right side are inserted on the left side.
57+
*
58+
* @param value the 32-bit integer value to rotate
59+
* @param shift the number of positions to rotate right (must be non-negative)
60+
* @return the result of right rotating the value by the specified shift amount
61+
* @throws IllegalArgumentException if shift is negative
62+
*
63+
* @example
64+
* // Binary: 00000000 00000000 00000000 00000011
65+
* rotateRight(3, 1)
66+
* // Returns: -2147483647 (binary: 10000000 00000000 00000000 00000001)
67+
*/
68+
public static int rotateRight(int value, int shift) {
69+
if (shift < 0) {
70+
throw new IllegalArgumentException("Shift amount cannot be negative: " + shift);
71+
}
72+
73+
// Normalize shift to the range [0, 31] using modulo 32
74+
shift = shift % 32;
75+
76+
if (shift == 0) {
77+
return value;
78+
}
79+
80+
// Right rotation: (value >>> shift) | (value << (32 - shift))
81+
return (value >>> shift) | (value << (32 - shift));
82+
}
83+
}

src/main/java/com/thealgorithms/ciphers/AES.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2738,7 +2738,7 @@ public static BigInteger decrypt(BigInteger cipherText, BigInteger key) {
27382738

27392739
public static void main(String[] args) {
27402740
try (Scanner input = new Scanner(System.in)) {
2741-
System.out.println("Enter (e) letter for encrpyt or (d) letter for decrypt :");
2741+
System.out.println("Enter (e) letter for encrypt or (d) letter for decrypt :");
27422742
char choice = input.nextLine().charAt(0);
27432743
String in;
27442744
switch (choice) {

src/main/java/com/thealgorithms/conversions/TurkishToLatinConversion.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ private TurkishToLatinConversion() {
1616
* 2. Replace all turkish characters with their corresponding latin characters
1717
* 3. Return the converted string
1818
*
19-
* @param param String paramter
19+
* @param param String parameter
2020
* @return String
2121
*/
2222
public static String convertTurkishToLatin(String param) {

src/main/java/com/thealgorithms/datastructures/graphs/BellmanFord.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ public void show(int source, int end,
160160
break;
161161
}
162162
}
163-
if (neg == 0) { // Go ahead and show results of computaion
163+
if (neg == 0) { // Go ahead and show results of computation
164164
System.out.println("Distance is: " + dist[end]);
165165
System.out.println("Path followed:");
166166
System.out.print(source + " ");

0 commit comments

Comments
 (0)