Skip to content

Commit 2e82356

Browse files
author
Bogdan Hladiuc
committed
Q766 Toeplitz Matrix
1 parent 63e9c10 commit 2e82356

File tree

8 files changed

+163
-3
lines changed

8 files changed

+163
-3
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<ItemGroup>
4+
<ProjectReference Include="..\..\..\Library\Library.csproj" />
5+
</ItemGroup>
6+
7+
<PropertyGroup>
8+
<TargetFramework>net6.0</TargetFramework>
9+
<ImplicitUsings>enable</ImplicitUsings>
10+
<Nullable>enable</Nullable>
11+
</PropertyGroup>
12+
13+
</Project>
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#nullable disable warnings
2+
using System.Diagnostics;
3+
using Library;
4+
5+
namespace Formation {
6+
7+
public class ToeplitzMatrix {
8+
public static void Run() {
9+
var test = new Test {
10+
Id = 1,
11+
Matrix = new int[4][] {
12+
new int[] { 1, 2, 3, 4 },
13+
new int[] { 5, 1, 2, 3 },
14+
new int[] { 6, 5, 1, 2 },
15+
new int[] { 7, 6, 5, 1 }
16+
},
17+
Expected = true
18+
};
19+
20+
AssortedMethods.PrintInt2DArray(test.Matrix);
21+
var result = IsToeplitzMatrix(test.Matrix);
22+
test.Verify(result);
23+
}
24+
25+
private static bool IsToeplitzMatrix(int[][] matrix) {
26+
for (int i = 0; i < matrix.Length; i++) {
27+
for (int j = 0; j < matrix[i].Length; j++) {
28+
var val = matrix[i][j];
29+
30+
if (i > 0 && j > 0 && val != matrix[i - 1][j - 1]) {
31+
return false;
32+
}
33+
}
34+
}
35+
36+
return true;
37+
}
38+
}
39+
40+
internal class Test {
41+
public int Id { get; set; }
42+
public int[][] Matrix { get; set; }
43+
public bool Expected { get; set; }
44+
45+
public void Verify(bool result) {
46+
Debug.Assert(result == Expected, $"Test {Id} failed.");
47+
}
48+
}
49+
}

LeetcodeNew.sln

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Day_2_Spiral_Traversal_Q54"
9191
EndProject
9292
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Day_3_Reverse_Groups_of_K_Nodes_Q25", "Formation\21_Days_Challenge\Day_3_Reverse_Groups_of_K_Nodes_Q25\Day_3_Reverse_Groups_of_K_Nodes_Q25.csproj", "{4936F68E-2FB8-4DC3-96CF-53116D2437E6}"
9393
EndProject
94+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Day_4_Toeplitz_Matrix_Q766", "Formation\21_Days_Challenge\Day_4_Toeplitz_Matrix_Q766\Day_4_Toeplitz_Matrix_Q766.csproj", "{C9FD7A97-4205-421E-A286-3AFE0B2BDA74}"
95+
EndProject
9496
Global
9597
GlobalSection(SolutionConfigurationPlatforms) = preSolution
9698
Debug|Any CPU = Debug|Any CPU
@@ -608,11 +610,24 @@ Global
608610
{4936F68E-2FB8-4DC3-96CF-53116D2437E6}.Release|x64.Build.0 = Release|Any CPU
609611
{4936F68E-2FB8-4DC3-96CF-53116D2437E6}.Release|x86.ActiveCfg = Release|Any CPU
610612
{4936F68E-2FB8-4DC3-96CF-53116D2437E6}.Release|x86.Build.0 = Release|Any CPU
613+
{C9FD7A97-4205-421E-A286-3AFE0B2BDA74}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
614+
{C9FD7A97-4205-421E-A286-3AFE0B2BDA74}.Debug|Any CPU.Build.0 = Debug|Any CPU
615+
{C9FD7A97-4205-421E-A286-3AFE0B2BDA74}.Debug|x64.ActiveCfg = Debug|Any CPU
616+
{C9FD7A97-4205-421E-A286-3AFE0B2BDA74}.Debug|x64.Build.0 = Debug|Any CPU
617+
{C9FD7A97-4205-421E-A286-3AFE0B2BDA74}.Debug|x86.ActiveCfg = Debug|Any CPU
618+
{C9FD7A97-4205-421E-A286-3AFE0B2BDA74}.Debug|x86.Build.0 = Debug|Any CPU
619+
{C9FD7A97-4205-421E-A286-3AFE0B2BDA74}.Release|Any CPU.ActiveCfg = Release|Any CPU
620+
{C9FD7A97-4205-421E-A286-3AFE0B2BDA74}.Release|Any CPU.Build.0 = Release|Any CPU
621+
{C9FD7A97-4205-421E-A286-3AFE0B2BDA74}.Release|x64.ActiveCfg = Release|Any CPU
622+
{C9FD7A97-4205-421E-A286-3AFE0B2BDA74}.Release|x64.Build.0 = Release|Any CPU
623+
{C9FD7A97-4205-421E-A286-3AFE0B2BDA74}.Release|x86.ActiveCfg = Release|Any CPU
624+
{C9FD7A97-4205-421E-A286-3AFE0B2BDA74}.Release|x86.Build.0 = Release|Any CPU
611625
EndGlobalSection
612626
GlobalSection(NestedProjects) = preSolution
613627
{45EB27A3-9FBB-48ED-8C89-E0F074C02E8C} = {71C7D88B-6D5D-4E25-A275-869603700831}
614628
{F4D0F4C2-26A6-43AC-BC80-D1762684A605} = {45EB27A3-9FBB-48ED-8C89-E0F074C02E8C}
615629
{82FE764B-4AA7-4694-B9BC-85119629AF56} = {45EB27A3-9FBB-48ED-8C89-E0F074C02E8C}
616630
{4936F68E-2FB8-4DC3-96CF-53116D2437E6} = {45EB27A3-9FBB-48ED-8C89-E0F074C02E8C}
631+
{C9FD7A97-4205-421E-A286-3AFE0B2BDA74} = {45EB27A3-9FBB-48ED-8C89-E0F074C02E8C}
617632
EndGlobalSection
618633
EndGlobal

Run/Program.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ static void Main(string[] args) {
55
#region Formation
66

77
// Formation.DeleteMiddleNode.Run(); // Day 1
8-
// Formation.SpiralTraversal.Run(); // Day 2
9-
Formation.ReverseKGroup.Run(); // Day 3
8+
// Formation.SpiralTraversal.Run(); // Day 2
9+
// Formation.ReverseKGroup.Run(); // Day 3
10+
Formation.ToeplitzMatrix.Run(); // Day 4
1011

1112
#endregion Formation
1213

Run/Run.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
<ProjectReference Include="..\Formation\21_Days_Challenge\Day_1_Remove_Delete_Middle_Node_Q2095\Day_1_Remove_Delete_Middle_Node_Q2095.csproj" />
4444
<ProjectReference Include="..\Formation\21_Days_Challenge\Day_2_Spiral_Traversal_Q54\Day_2_Spiral_Traversal_Q54.csproj" />
4545
<ProjectReference Include="..\Formation\21_Days_Challenge\Day_3_Reverse_Groups_of_K_Nodes_Q25\Day_3_Reverse_Groups_of_K_Nodes_Q25.csproj" />
46+
<ProjectReference Include="..\Formation\21_Days_Challenge\Day_4_Toeplitz_Matrix_Q766\Day_4_Toeplitz_Matrix_Q766.csproj" />
4647
</ItemGroup>
4748

4849
<PropertyGroup>

Run/obj/Run.csproj.nuget.dgspec.json

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,62 @@
228228
}
229229
}
230230
},
231+
"/Users/Bogdan/Documents/Work/CtCI/VS_Code/LeetcodeNew/Formation/21_Days_Challenge/Day_4_Toeplitz_Matrix_Q766/Day_4_Toeplitz_Matrix_Q766.csproj": {
232+
"version": "1.0.0",
233+
"restore": {
234+
"projectUniqueName": "/Users/Bogdan/Documents/Work/CtCI/VS_Code/LeetcodeNew/Formation/21_Days_Challenge/Day_4_Toeplitz_Matrix_Q766/Day_4_Toeplitz_Matrix_Q766.csproj",
235+
"projectName": "Day_4_Toeplitz_Matrix_Q766",
236+
"projectPath": "/Users/Bogdan/Documents/Work/CtCI/VS_Code/LeetcodeNew/Formation/21_Days_Challenge/Day_4_Toeplitz_Matrix_Q766/Day_4_Toeplitz_Matrix_Q766.csproj",
237+
"packagesPath": "/Users/Bogdan/.nuget/packages/",
238+
"outputPath": "/Users/Bogdan/Documents/Work/CtCI/VS_Code/LeetcodeNew/Formation/21_Days_Challenge/Day_4_Toeplitz_Matrix_Q766/obj/",
239+
"projectStyle": "PackageReference",
240+
"configFilePaths": [
241+
"/Users/Bogdan/.nuget/NuGet/NuGet.Config"
242+
],
243+
"originalTargetFrameworks": [
244+
"net6.0"
245+
],
246+
"sources": {
247+
"https://api.nuget.org/v3/index.json": {}
248+
},
249+
"frameworks": {
250+
"net6.0": {
251+
"targetAlias": "net6.0",
252+
"projectReferences": {
253+
"/Users/Bogdan/Documents/Work/CtCI/VS_Code/LeetcodeNew/Library/Library.csproj": {
254+
"projectPath": "/Users/Bogdan/Documents/Work/CtCI/VS_Code/LeetcodeNew/Library/Library.csproj"
255+
}
256+
}
257+
}
258+
},
259+
"warningProperties": {
260+
"warnAsError": [
261+
"NU1605"
262+
]
263+
}
264+
},
265+
"frameworks": {
266+
"net6.0": {
267+
"targetAlias": "net6.0",
268+
"imports": [
269+
"net461",
270+
"net462",
271+
"net47",
272+
"net471",
273+
"net472",
274+
"net48"
275+
],
276+
"assetTargetFallback": true,
277+
"warn": true,
278+
"frameworkReferences": {
279+
"Microsoft.NETCore.App": {
280+
"privateAssets": "all"
281+
}
282+
},
283+
"runtimeIdentifierGraphPath": "/usr/local/share/dotnet/sdk/6.0.202/RuntimeIdentifierGraph.json"
284+
}
285+
}
286+
},
231287
"/Users/Bogdan/Documents/Work/CtCI/VS_Code/LeetcodeNew/Library/Library.csproj": {
232288
"version": "1.0.0",
233289
"restore": {
@@ -2322,6 +2378,9 @@
23222378
"/Users/Bogdan/Documents/Work/CtCI/VS_Code/LeetcodeNew/Formation/21_Days_Challenge/Day_3_Reverse_Groups_of_K_Nodes_Q25/Day_3_Reverse_Groups_of_K_Nodes_Q25.csproj": {
23232379
"projectPath": "/Users/Bogdan/Documents/Work/CtCI/VS_Code/LeetcodeNew/Formation/21_Days_Challenge/Day_3_Reverse_Groups_of_K_Nodes_Q25/Day_3_Reverse_Groups_of_K_Nodes_Q25.csproj"
23242380
},
2381+
"/Users/Bogdan/Documents/Work/CtCI/VS_Code/LeetcodeNew/Formation/21_Days_Challenge/Day_4_Toeplitz_Matrix_Q766/Day_4_Toeplitz_Matrix_Q766.csproj": {
2382+
"projectPath": "/Users/Bogdan/Documents/Work/CtCI/VS_Code/LeetcodeNew/Formation/21_Days_Challenge/Day_4_Toeplitz_Matrix_Q766/Day_4_Toeplitz_Matrix_Q766.csproj"
2383+
},
23252384
"/Users/Bogdan/Documents/Work/CtCI/VS_Code/LeetcodeNew/Library/Library.csproj": {
23262385
"projectPath": "/Users/Bogdan/Documents/Work/CtCI/VS_Code/LeetcodeNew/Library/Library.csproj"
23272386
},

Run/obj/project.assets.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,19 @@
5454
"bin/placeholder/Day_3_Reverse_Groups_of_K_Nodes_Q25.dll": {}
5555
}
5656
},
57+
"Day_4_Toeplitz_Matrix_Q766/1.0.0": {
58+
"type": "project",
59+
"framework": ".NETCoreApp,Version=v6.0",
60+
"dependencies": {
61+
"Library": "1.0.0"
62+
},
63+
"compile": {
64+
"bin/placeholder/Day_4_Toeplitz_Matrix_Q766.dll": {}
65+
},
66+
"runtime": {
67+
"bin/placeholder/Day_4_Toeplitz_Matrix_Q766.dll": {}
68+
}
69+
},
5770
"Library/1.0.0": {
5871
"type": "project",
5972
"framework": ".NETCoreApp,Version=v6.0",
@@ -520,6 +533,11 @@
520533
"path": "../Formation/21_Days_Challenge/Day_3_Reverse_Groups_of_K_Nodes_Q25/Day_3_Reverse_Groups_of_K_Nodes_Q25.csproj",
521534
"msbuildProject": "../Formation/21_Days_Challenge/Day_3_Reverse_Groups_of_K_Nodes_Q25/Day_3_Reverse_Groups_of_K_Nodes_Q25.csproj"
522535
},
536+
"Day_4_Toeplitz_Matrix_Q766/1.0.0": {
537+
"type": "project",
538+
"path": "../Formation/21_Days_Challenge/Day_4_Toeplitz_Matrix_Q766/Day_4_Toeplitz_Matrix_Q766.csproj",
539+
"msbuildProject": "../Formation/21_Days_Challenge/Day_4_Toeplitz_Matrix_Q766/Day_4_Toeplitz_Matrix_Q766.csproj"
540+
},
523541
"Library/1.0.0": {
524542
"type": "project",
525543
"path": "../Library/Library.csproj",
@@ -717,6 +735,7 @@
717735
"Day_1_Remove_Delete_Middle_Node_Q2095 >= 1.0.0",
718736
"Day_2_Spiral_Traversal_Q54 >= 1.0.0",
719737
"Day_3_Reverse_Groups_of_K_Nodes_Q25 >= 1.0.0",
738+
"Day_4_Toeplitz_Matrix_Q766 >= 1.0.0",
720739
"Library >= 1.0.0",
721740
"Q10_Regular_Expression_Matching >= 1.0.0",
722741
"Q1249_Minimum_Remove_To_Make_Valid_Parentheses >= 1.0.0",
@@ -794,6 +813,9 @@
794813
"/Users/Bogdan/Documents/Work/CtCI/VS_Code/LeetcodeNew/Formation/21_Days_Challenge/Day_3_Reverse_Groups_of_K_Nodes_Q25/Day_3_Reverse_Groups_of_K_Nodes_Q25.csproj": {
795814
"projectPath": "/Users/Bogdan/Documents/Work/CtCI/VS_Code/LeetcodeNew/Formation/21_Days_Challenge/Day_3_Reverse_Groups_of_K_Nodes_Q25/Day_3_Reverse_Groups_of_K_Nodes_Q25.csproj"
796815
},
816+
"/Users/Bogdan/Documents/Work/CtCI/VS_Code/LeetcodeNew/Formation/21_Days_Challenge/Day_4_Toeplitz_Matrix_Q766/Day_4_Toeplitz_Matrix_Q766.csproj": {
817+
"projectPath": "/Users/Bogdan/Documents/Work/CtCI/VS_Code/LeetcodeNew/Formation/21_Days_Challenge/Day_4_Toeplitz_Matrix_Q766/Day_4_Toeplitz_Matrix_Q766.csproj"
818+
},
797819
"/Users/Bogdan/Documents/Work/CtCI/VS_Code/LeetcodeNew/Library/Library.csproj": {
798820
"projectPath": "/Users/Bogdan/Documents/Work/CtCI/VS_Code/LeetcodeNew/Library/Library.csproj"
799821
},

Run/obj/project.nuget.cache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"version": 2,
3-
"dgSpecHash": "PExtQsV6jTLun2CfiLPD9yz1kLS7Hk4gTRIUiljlED5qv3OIiL3AuVeIKs/t6R094YBHKmxVO46LAHmgfXk/PQ==",
3+
"dgSpecHash": "svjxR23MpcYrkEb9654+HSXHxlEVj5P3QdEVr9D3bxT/h6tFyqz3WanVGf91XigMCNeCvdKe9Ukmxv0HnaUCCw==",
44
"success": true,
55
"projectFilePath": "/Users/Bogdan/Documents/Work/CtCI/VS_Code/LeetcodeNew/Run/Run.csproj",
66
"expectedPackageFiles": [],

0 commit comments

Comments
 (0)