Skip to content

Commit

Permalink
181st Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Shyam-Chen committed Jul 27, 2024
1 parent 0199484 commit 23ab594
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 6 deletions.
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,14 @@ Ace Coding Interview with 75 Qs
[1732]: ./src/page-16/1732.%20Find%20the%20Highest%20Altitude/largestAltitude.ts
[724]: ./src/page-7/724.%20Find%20Pivot%20Index/pivotIndex.ts

| Hash Map / Set | | |
| ---------------------------------------- | -------- | ------ |
| 2215. Find the Difference of Two Arrays | Solution | Easy |
| 1207. Unique Number of Occurrences | Solution | Easy |
| 1657. Determine if Two Strings Are Close | Solution | Medium |
| 2352. Equal Row and Column Pairs | Solution | Medium |
| Hash Map / Set | | |
| ---------------------------------------- | ---------------- | ------ |
| 2215. Find the Difference of Two Arrays | [Solution][2215] | Easy |
| 1207. Unique Number of Occurrences | Solution | Easy |
| 1657. Determine if Two Strings Are Close | Solution | Medium |
| 2352. Equal Row and Column Pairs | Solution | Medium |

[2215]: ./src/page-21/2215.%20Find%20the%20Difference%20of%20Two%20Arrays/findDifference.ts

| Stack | | |
| ---------------------------------- | -------- | ------ |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { findDifference } from './findDifference';

describe('2215. Find the Difference of Two Arrays', () => {
test('findDifference', () => {
expect(findDifference([1, 2, 3], [2, 4, 6])).toStrictEqual([
[1, 3],
[4, 6],
]);
expect(findDifference([1, 2, 3, 3], [1, 1, 2, 2])).toStrictEqual([[3], []]);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
type FindDifference = (nums1: number[], nums2: number[]) => number[][];

/**
* Accepted
*/
export const findDifference: FindDifference = (nums1, nums2) => {
// Create sets from nums1 and nums2
const set1 = new Set(nums1);
const set2 = new Set(nums2);

// Find distinct elements in nums1 not in nums2
const distinctNums1 = Array.from(set1).filter((num) => !set2.has(num));

// Find distinct elements in nums2 not in nums1
const distinctNums2 = Array.from(set2).filter((num) => !set1.has(num));

return [distinctNums1, distinctNums2];
};

0 comments on commit 23ab594

Please sign in to comment.