| | 1 | | // -------------------------------------------------------------------------------- |
| | 2 | | // Copyright (C) 2025 Eugene Eremeev (also known as Yevhenii Yeriemeieiv). |
| | 3 | | // All Rights Reserved. |
| | 4 | | // -------------------------------------------------------------------------------- |
| | 5 | | // This software is the confidential and proprietary information of Eugene Eremeev |
| | 6 | | // (also known as Yevhenii Yeriemeieiv) ("Confidential Information"). You shall not |
| | 7 | | // disclose such Confidential Information and shall use it only in accordance with |
| | 8 | | // the terms of the license agreement you entered into with Eugene Eremeev (also |
| | 9 | | // known as Yevhenii Yeriemeieiv). |
| | 10 | | // -------------------------------------------------------------------------------- |
| | 11 | |
|
| | 12 | | using System.Text; |
| | 13 | |
|
| | 14 | | namespace LeetCode.Algorithms.FlipColumnsForMaximumNumberOfEqualRows; |
| | 15 | |
|
| | 16 | | /// <inheritdoc /> |
| | 17 | | public class FlipColumnsForMaximumNumberOfEqualRowsDictionary : IFlipColumnsForMaximumNumberOfEqualRows |
| | 18 | | { |
| | 19 | | /// <summary> |
| | 20 | | /// Time complexity - O(n * m) |
| | 21 | | /// Space complexity - O(n * m) |
| | 22 | | /// </summary> |
| | 23 | | /// <param name="matrix"></param> |
| | 24 | | /// <returns></returns> |
| | 25 | | public int MaxEqualRowsAfterFlips(int[][] matrix) |
| 3 | 26 | | { |
| 3 | 27 | | var patternDictionary = new Dictionary<string, int>(); |
| | 28 | |
|
| 23 | 29 | | foreach (var currentRow in matrix) |
| 7 | 30 | | { |
| 7 | 31 | | var patternStringBuilder = new StringBuilder(); |
| | 32 | |
|
| 55 | 33 | | foreach (var cell in currentRow) |
| 17 | 34 | | { |
| 17 | 35 | | patternStringBuilder.Append(currentRow[0] == cell ? 'T' : 'F'); |
| 17 | 36 | | } |
| | 37 | |
|
| 7 | 38 | | var rowPattern = patternStringBuilder.ToString(); |
| | 39 | |
|
| 7 | 40 | | if (!patternDictionary.TryAdd(rowPattern, 1)) |
| 2 | 41 | | { |
| 2 | 42 | | patternDictionary[rowPattern]++; |
| 2 | 43 | | } |
| 7 | 44 | | } |
| | 45 | |
|
| 3 | 46 | | return patternDictionary.Values.Max(); |
| 3 | 47 | | } |
| | 48 | | } |