Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,20 @@ public static boolean isSubset(int[] a, int[] b) {
* array.
*/
public static int[] removeSet(int[] a, int[] b) {
if (b.length == 0) {
return a;
}
// Iterate over each element in the second array
// and check if the element exists in the first array
if (!isSubset(a, b)) {
throw new IllegalArgumentException("Element not found in the first array");
}
// Remove the elements of the second array from the first array
int[] resultArray = new int[a.length - b.length];
if (resultArray.length == 0) {
return resultArray;
}

int index = 0;
for (int elementA : a) {
boolean found = false;
Expand Down