Created
February 15, 2025 16:05
-
-
Save jamescurran/0e0d9781d6e1ea761b4495c6008f0714 to your computer and use it in GitHub Desktop.
Daily Challenge #JS-102: Calculate Unique Elements in a Square Matrix (In C#)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| Calculate Unique Elements in a Square Matrix | |
| Given a square matrix, write a function that computes the number of unique elements in the matrix. A square matrix is a two-dimensional array where the number of rows is equal to the number of columns. | |
| Example: | |
| Input: [[2, 3, 2], [9, 3, 1], [1, 2, 5]] | |
| Output: 5 | |
| */ | |
| int countUniqueElements(int[][] matrix) => matrix.SelectMany(m => m).Distinct().Count(); | |
| void Main() | |
| { | |
| int[][] matrix = new int[][] { new int[] { 2, 3, 2 }, new int[] { 9, 3,1 }, new int[] { 1, 2, 5 }}; | |
| countUniqueElements(matrix).Dump(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment