Skip to content

Commit

Permalink
184th Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Shyam-Chen committed Jul 28, 2024
1 parent 78def55 commit 6489d31
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,12 @@ Ace Coding Interview with 75 Qs
| 2215. Find the Difference of Two Arrays | [Solution][2215] | Easy |
| 1207. Unique Number of Occurrences | [Solution][1207] | Easy |
| 1657. Determine if Two Strings Are Close | [Solution][1657] | Medium |
| 2352. Equal Row and Column Pairs | Solution | Medium |
| 2352. Equal Row and Column Pairs | [Solution][2352] | Medium |

[2215]: ./src/page-21/2215.%20Find%20the%20Difference%20of%20Two%20Arrays/findDifference.ts
[1207]: ./src/page-12/1207.%20Unique%20Number%20of%20Occurrences/uniqueOccurrences.ts
[1657]: ./src/page-16/1657.%20Determine%20if%20Two%20Strings%20Are%20Close/closeStrings.ts
[2352]: ./src/page-22/2352.%20Equal%20Row%20and%20Column%20Pairs/equalPairs.ts

| Stack | | |
| ---------------------------------- | -------- | ------ |
Expand Down
22 changes: 22 additions & 0 deletions src/page-22/2352. Equal Row and Column Pairs/equalPairs.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { equalPairs } from './equalPairs';

describe('2352. Equal Row and Column Pairs', () => {
test('equalPairs', () => {
expect(
equalPairs([
[3, 2, 1],
[1, 7, 6],
[2, 7, 7],
]),
).toBe(1);

expect(
equalPairs([
[3, 1, 2, 2],
[1, 4, 4, 5],
[2, 4, 2, 2],
[2, 4, 2, 2],
]),
).toBe(3);
});
});
24 changes: 24 additions & 0 deletions src/page-22/2352. Equal Row and Column Pairs/equalPairs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
type EqualPairs = (grid: number[][]) => number;

/**
* Accepted
*/
export const equalPairs: EqualPairs = (grid) => {
const rowMap = new Map<string, number>();

// Store each row in the map
for (let i = 0; i < grid.length; i++) {
const row = grid[i].join();
rowMap.set(row, (rowMap.get(row) || 0) + 1);
}

let count = 0;

// Check each column against the stored rows
for (let j = 0; j < grid.length; j++) {
const col = grid.map((row) => row[j]).join();
count += rowMap.get(col) || 0;
}

return count;
};

0 comments on commit 6489d31

Please sign in to comment.