diff --git a/.vscode/settings.json b/.vscode/settings.json
index a2b0918..efc2a83 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -7,6 +7,7 @@
"[csharp]": {
"editor.defaultFormatter": "ms-dotnettools.csharp"
},
+ "omnisharp.enableEditorConfigSupport": true,
"[github-actions-workflow]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
diff --git a/algorithm_exercises_csharp/algorithm_exercises_csharp.csproj b/algorithm_exercises_csharp/algorithm_exercises_csharp.csproj
index bfec5ef..98b5e69 100644
--- a/algorithm_exercises_csharp/algorithm_exercises_csharp.csproj
+++ b/algorithm_exercises_csharp/algorithm_exercises_csharp.csproj
@@ -10,6 +10,7 @@
true
+ latest
true
false
@@ -18,4 +19,11 @@
+
+
+
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+ all
+
+
diff --git a/algorithm_exercises_csharp/src/hackerrank/interview_preparation_kit/arrays/ArraysLeftRotation.cs b/algorithm_exercises_csharp/src/hackerrank/interview_preparation_kit/arrays/ArraysLeftRotation.cs
index 7429ed6..5079f0a 100644
--- a/algorithm_exercises_csharp/src/hackerrank/interview_preparation_kit/arrays/ArraysLeftRotation.cs
+++ b/algorithm_exercises_csharp/src/hackerrank/interview_preparation_kit/arrays/ArraysLeftRotation.cs
@@ -1,4 +1,4 @@
-// @link Problem definition [[docs/hackerrank/projecteuler/euler001.md]]
+// @link Problem definition [[docs/hackerrank/interview_preparation_kit/arrays/ctci_array_left_rotation.md]]
namespace algorithm_exercises_csharp.hackerrank.interview_preparation_kit;
diff --git a/algorithm_exercises_csharp_base/algorithm_exercises_csharp_base.csproj b/algorithm_exercises_csharp_base/algorithm_exercises_csharp_base.csproj
index 418d63c..75d5a30 100644
--- a/algorithm_exercises_csharp_base/algorithm_exercises_csharp_base.csproj
+++ b/algorithm_exercises_csharp_base/algorithm_exercises_csharp_base.csproj
@@ -12,6 +12,7 @@
true
+ latest
true
false
@@ -23,6 +24,10 @@
+
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+ all
+
diff --git a/algorithm_exercises_csharp_base/src/Logger.cs b/algorithm_exercises_csharp_base/src/Logger.cs
index bff9c3b..a061312 100644
--- a/algorithm_exercises_csharp_base/src/Logger.cs
+++ b/algorithm_exercises_csharp_base/src/Logger.cs
@@ -68,7 +68,7 @@ public static void error(string message, params object?[] args)
#pragma warning restore CA2254 // Template should be a static expression
}
- public static void debu(string message, params object?[] args)
+ public static void debug(string message, params object?[] args)
{
#pragma warning disable CA2254 // Template should be a static expression
LoggerSingleton.Instance.Logger.LogDebug(message);
diff --git a/algorithm_exercises_csharp_test/Resources/hackerrank/interview_preparation_kit/arrays/ctci_array_left_rotation.testcases.json b/algorithm_exercises_csharp_test/Resources/hackerrank/interview_preparation_kit/arrays/ctci_array_left_rotation.testcases.json
new file mode 100644
index 0000000..1750d96
--- /dev/null
+++ b/algorithm_exercises_csharp_test/Resources/hackerrank/interview_preparation_kit/arrays/ctci_array_left_rotation.testcases.json
@@ -0,0 +1,7 @@
+[
+ {"input": [1, 2, 3, 4, 5], "expected": [2, 3, 4, 5, 1]},
+ {"input": [2, 3, 4, 5, 1], "expected": [3, 4, 5, 1, 2]},
+ {"input": [3, 4, 5, 1, 2], "expected": [4, 5, 1, 2, 3]},
+ {"input": [4, 5, 1, 2, 3], "expected": [5, 1, 2, 3, 4]},
+ {"input": [5, 1, 2, 3, 4], "expected": [1, 2, 3, 4, 5]}
+]
diff --git a/algorithm_exercises_csharp_test/Resources/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/ctci_ransom_note.testcases.json b/algorithm_exercises_csharp_test/Resources/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/ctci_ransom_note.testcases.json
new file mode 100644
index 0000000..8f04948
--- /dev/null
+++ b/algorithm_exercises_csharp_test/Resources/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/ctci_ransom_note.testcases.json
@@ -0,0 +1,20 @@
+[
+ {
+ "title": "Sample Test Case 0",
+ "magazine": ["give", "me", "one", "grand", "today", "night"],
+ "note": ["give", "one", "grand", "today"],
+ "expected": "Yes"
+ },
+ {
+ "title": "Sample Test Case 1",
+ "magazine": ["two", "times", "three", "is", "not", "four"],
+ "note": ["two", "times", "two", "is", "four"],
+ "expected": "No"
+ },
+ {
+ "title": "Sample Test",
+ "magazine": ["two", "two", "times", "three", "is", "not", "four"],
+ "note": ["two", "times", "two", "is", "four"],
+ "expected": "Yes"
+ }
+]
diff --git a/algorithm_exercises_csharp_test/Resources/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/two_strings.testcases.json b/algorithm_exercises_csharp_test/Resources/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/two_strings.testcases.json
new file mode 100644
index 0000000..73d1dcf
--- /dev/null
+++ b/algorithm_exercises_csharp_test/Resources/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/two_strings.testcases.json
@@ -0,0 +1,20 @@
+[
+ {
+ "title": "Example 1",
+ "s1": "and",
+ "s2": "art",
+ "expected": "Yes"
+ },
+ {
+ "title": "Example 2",
+ "s1": "be",
+ "s2": "cat",
+ "expected": "No"
+ },
+ {
+ "title": "Sample Test Case 0",
+ "s1": "hello",
+ "s2": "world",
+ "expected": "Yes"
+ }
+]
diff --git a/algorithm_exercises_csharp_test/Resources/hackerrank/interview_preparation_kit/greedy_algorithms/luck_balance.testcases.json b/algorithm_exercises_csharp_test/Resources/hackerrank/interview_preparation_kit/greedy_algorithms/luck_balance.testcases.json
new file mode 100644
index 0000000..99e0243
--- /dev/null
+++ b/algorithm_exercises_csharp_test/Resources/hackerrank/interview_preparation_kit/greedy_algorithms/luck_balance.testcases.json
@@ -0,0 +1,8 @@
+[
+ {
+ "title": "Sample Test case 0",
+ "k": 3,
+ "contests": [[5, 1], [2, 1], [1, 1], [8, 1], [10, 0], [5, 0]],
+ "expected": 29
+ }
+]
diff --git a/algorithm_exercises_csharp_test/algorithm_exercises_csharp_test.csproj b/algorithm_exercises_csharp_test/algorithm_exercises_csharp_test.csproj
index a7a60e3..bd0d89b 100644
--- a/algorithm_exercises_csharp_test/algorithm_exercises_csharp_test.csproj
+++ b/algorithm_exercises_csharp_test/algorithm_exercises_csharp_test.csproj
@@ -19,6 +19,7 @@
true
+ latest
true
false
@@ -29,6 +30,10 @@
runtime; build; native; contentfiles; analyzers; buildtransitive
all
+
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+ all
+
@@ -50,8 +55,13 @@
-
+
+
+
+
+
+
+
diff --git a/algorithm_exercises_csharp_test/src/hackerrank/interview_preparation_kit/arrays/ArraysLeftRotation.Test.cs b/algorithm_exercises_csharp_test/src/hackerrank/interview_preparation_kit/arrays/ArraysLeftRotation.Test.cs
index d099eef..266d29c 100644
--- a/algorithm_exercises_csharp_test/src/hackerrank/interview_preparation_kit/arrays/ArraysLeftRotation.Test.cs
+++ b/algorithm_exercises_csharp_test/src/hackerrank/interview_preparation_kit/arrays/ArraysLeftRotation.Test.cs
@@ -5,32 +5,37 @@ public class ArraysLeftRotationTest
{
public class ArraysLeftRotationTestCase
{
- public List input = []; public List expected = [];
+ public List input { get; set; } = default!;
+ public List expected { get; set; } = default!;
}
public class ArraysLeftRotationsTestCase
{
- public List input = []; public int d; public List expected = [];
+ public List input { get; set; } = default!;
+ public int d { get; set; }
+ public List expected { get; set; } = default!;
}
- private static readonly ArraysLeftRotationTestCase[] tests = [
- new() { input = [1, 2, 3, 4, 5], expected = [2, 3, 4, 5, 1] },
- new() { input = [2, 3, 4, 5, 1], expected = [3, 4, 5, 1, 2] },
- new() { input = [3, 4, 5, 1, 2], expected = [4, 5, 1, 2, 3] },
- new() { input = [4, 5, 1, 2, 3], expected = [5, 1, 2, 3, 4] },
- new() { input = [5, 1, 2, 3, 4], expected = [1, 2, 3, 4, 5] }
- ];
+ private List testCases { get; set; } = default!;
private static readonly ArraysLeftRotationsTestCase[] testRotationsCases = [
new() { input = [1, 2, 3, 4, 5], d = 4, expected = [5, 1, 2, 3, 4] }
];
+ [TestInitialize]
+ public void testInitialize()
+ {
+ testCases = JsonLoader.resourceLoad>(
+ "hackerrank/interview_preparation_kit/arrays/ctci_array_left_rotation.testcases.json"
+ ) ?? [];
+ }
+
[TestMethod]
public void testRotLeftOne()
{
List result;
- foreach (ArraysLeftRotationTestCase test in tests)
+ foreach (ArraysLeftRotationTestCase test in testCases)
{
result = ArraysLeftRotation.rotLeftOne(test.input);
CollectionAssert.AreEquivalent(test.expected, result);
diff --git a/algorithm_exercises_csharp_test/src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/RansomNote.Test.cs b/algorithm_exercises_csharp_test/src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/RansomNote.Test.cs
index fd6f193..188cc1b 100644
--- a/algorithm_exercises_csharp_test/src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/RansomNote.Test.cs
+++ b/algorithm_exercises_csharp_test/src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/RansomNote.Test.cs
@@ -5,47 +5,28 @@ public class RansomNoteTest
{
public class RansomNoteTestCase
{
- public string title = "";
- public List magazine = [];
- public List note = [];
- public string expected = "";
+ public string title { get; set; } = default!;
+ public List magazine { get; set; } = default!;
+ public List note { get; set; } = default!;
+ public string expected { get; set; } = default!;
}
- public class ArraysLeftRotationsTestCase
+ private List testCases { get; set; } = default!;
+
+ [TestInitialize]
+ public void testInitialize()
{
- public List input = []; public int d; public List expected = [];
+ testCases = JsonLoader.resourceLoad>(
+ "hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/ctci_ransom_note.testcases.json"
+ ) ?? [];
}
- private static readonly RansomNoteTestCase[] tests = [
- new()
- {
- title = "Sample Test Case 0",
- magazine = ["give", "me", "one", "grand", "today", "night"],
- note = ["give", "one", "grand", "today"],
- expected = "Yes"
- },
- new()
- {
- title = "Sample Test Case 1",
- magazine = ["two", "times", "three", "is", "not", "four"],
- note = ["two", "times", "two", "is", "four"],
- expected = "No"
- },
- new()
- {
- title = "Sample Test",
- magazine = ["two", "two", "times", "three", "is", "not", "four"],
- note = ["two", "times", "two", "is", "four"],
- expected = "Yes"
- },
- ];
-
[TestMethod]
public void testCheckMagazine()
{
string result;
- foreach (RansomNoteTestCase test in tests)
+ foreach (RansomNoteTestCase test in testCases)
{
result = RansomNote.checkMagazine(test.magazine, test.note);
Assert.AreEqual(test.expected, result);
diff --git a/algorithm_exercises_csharp_test/src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/TwoStrings.Test.cs b/algorithm_exercises_csharp_test/src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/TwoStrings.Test.cs
index 5f653e4..6ed4bb8 100644
--- a/algorithm_exercises_csharp_test/src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/TwoStrings.Test.cs
+++ b/algorithm_exercises_csharp_test/src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/TwoStrings.Test.cs
@@ -5,42 +5,31 @@ public class TwoStringsTest
{
public class TwoStringsTestCase
{
- public string title = "";
- public string s1 = "";
- public string s2 = "";
- public string expected = "Yes";
+ public string title { get; set; } = default!;
+
+ public string s1 { get; set; } = default!;
+
+ public string s2 { get; set; } = default!;
+
+ public string expected { get; set; } = default!;
}
- private static readonly TwoStringsTestCase[] tests = [
- new()
- {
- title = "Example 1",
- s1 = "and",
- s2 = "art",
- expected = "Yes"
- },
- new()
- {
- title = "Example 2",
- s1 = "be",
- s2 = "cat",
- expected = "No"
- },
- new()
- {
- title = "Sample Test Case 0",
- s1 = "hello",
- s2 = "world",
- expected = "Yes"
- },
- ];
+ private List testCases { get; set; } = default!;
+
+ [TestInitialize]
+ public void testInitialize()
+ {
+ testCases = JsonLoader.resourceLoad>(
+ "hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/two_strings.testcases.json"
+ ) ?? [];
+ }
[TestMethod]
public void testTwoStrings()
{
string result;
- foreach (TwoStringsTestCase test in tests)
+ foreach (TwoStringsTestCase test in testCases)
{
result = TwoStrings.twoStrings(test.s1, test.s2);
Assert.AreEqual(test.expected, result);
diff --git a/algorithm_exercises_csharp_test/src/hackerrank/interview_preparation_kit/greedy_algorithms/LuckBalance.Test.cs b/algorithm_exercises_csharp_test/src/hackerrank/interview_preparation_kit/greedy_algorithms/LuckBalance.Test.cs
index 4192838..a1b44ab 100644
--- a/algorithm_exercises_csharp_test/src/hackerrank/interview_preparation_kit/greedy_algorithms/LuckBalance.Test.cs
+++ b/algorithm_exercises_csharp_test/src/hackerrank/interview_preparation_kit/greedy_algorithms/LuckBalance.Test.cs
@@ -11,36 +11,22 @@ public class LuckBalanceTestCase
public int expected;
}
- private static readonly LuckBalanceTestCase[] tests = [
- new()
- {
- title = "Sample Test case 0",
- k = 3,
- contests = [[5, 1], [2, 1], [1, 1], [8, 1], [10, 0], [5, 0]],
- expected = 29
- },
- new()
- {
- title = "Sample Test case 1",
- k = 5,
- contests = [[13, 1], [10, 1], [9, 1], [8, 1], [13, 1], [12, 1], [18, 1], [13, 1]],
- expected = 42
- },
- new()
- {
- title = "Sample Test case 2",
- k = 2,
- contests = [[5, 1], [4, 0], [6, 1], [2, 1], [8, 0]],
- expected = 21
- }
- ];
+ private List testCases { get; set; } = default!;
+
+ [TestInitialize]
+ public void testInitialize()
+ {
+ testCases = JsonLoader.resourceLoad>(
+ "hackerrank/interview_preparation_kit/greedy_algorithms/luck_balance.testcases.json"
+ ) ?? [];
+ }
[TestMethod]
public void testLuckBalance()
{
int result;
- foreach (LuckBalanceTestCase test in tests)
+ foreach (LuckBalanceTestCase test in testCases)
{
result = LuckBalance.luckBalance(test.k, test.contests);
Assert.AreEqual(
diff --git a/algorithm_exercises_csharp_test/src/lib/JsonLoader.cs b/algorithm_exercises_csharp_test/src/lib/JsonLoader.cs
new file mode 100644
index 0000000..d4a0464
--- /dev/null
+++ b/algorithm_exercises_csharp_test/src/lib/JsonLoader.cs
@@ -0,0 +1,32 @@
+namespace algorithm_exercises_csharp.hackerrank.interview_preparation_kit;
+
+using System.Reflection;
+using System.Text;
+using Newtonsoft.Json;
+
+public static class JsonLoader
+{
+ public static T? resourceLoad(string _path)
+ {
+ string path = _path;
+ path = path.Replace('/', '.');
+ path = path.Replace('\\', '.');
+
+ var info = Assembly.GetExecutingAssembly().GetName();
+ var name = info.Name;
+
+ path = $"{name}.Resources.{path}";
+ Log.debug($"Loading JSON from: {path}");
+
+ using var stream = Assembly
+ .GetExecutingAssembly()
+ .GetManifestResourceStream($"{path}")!;
+
+
+ using var streamReader = new StreamReader(stream, Encoding.UTF8);
+
+ return JsonConvert.DeserializeObject(
+ streamReader.ReadToEnd()
+ );
+ }
+}
diff --git a/docs/hackerrank/interview_preparation_kit/arrays/ctci_array_left_rotation.md b/docs/hackerrank/interview_preparation_kit/arrays/ctci_array_left_rotation.md
index 7b4e341..4f5c0e9 100644
--- a/docs/hackerrank/interview_preparation_kit/arrays/ctci_array_left_rotation.md
+++ b/docs/hackerrank/interview_preparation_kit/arrays/ctci_array_left_rotation.md
@@ -2,8 +2,8 @@
Given an array and a number, d, perform d left rotations on the array.
-- Difficulty: #easy
-- Category: #ProblemSolvingBasic
+- Difficulty: `#easy`
+- Category: `#ProblemSolvingBasic` `#arrays`
A left rotation operation on an array shifts each of the array's elements
$ 1 $ unit to the left. For example, if $ 2 $ left rotations are performed