From f4315185b2dcfce6f9e9da0b21a6efd954a87c35 Mon Sep 17 00:00:00 2001 From: Aswin Deivanayagam Subramanian <150608459+Ashprogrammer29@users.noreply.github.com> Date: Fri, 27 Dec 2024 21:59:07 +0530 Subject: [PATCH 01/37] Create Python_Aswin_01.py --- December 01/Python_Aswin_01.py | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 December 01/Python_Aswin_01.py diff --git a/December 01/Python_Aswin_01.py b/December 01/Python_Aswin_01.py new file mode 100644 index 0000000..19cea7c --- /dev/null +++ b/December 01/Python_Aswin_01.py @@ -0,0 +1,8 @@ +def find_missing_number(N, array): + expected_sum = N * (N + 1) // 2 + actual_sum = sum(array) + return expected_sum - actual_sum + +# Test cases +print(find_missing_number(5, [1, 2, 4, 5])) # Output: 3 +print(find_missing_number(3, [1, 3])) # Output: 2 From e3f86ae81f734df0bcff87dd82d0214f2bef5b04 Mon Sep 17 00:00:00 2001 From: Aswin Deivanayagam Subramanian <150608459+Ashprogrammer29@users.noreply.github.com> Date: Fri, 27 Dec 2024 22:00:53 +0530 Subject: [PATCH 02/37] Question 01 has been completed. --- December 01/C#_Aswin_01.cs | 24 ++++++++++++++++++++++++ December 01/Python_Aswin_01.py | 8 -------- 2 files changed, 24 insertions(+), 8 deletions(-) create mode 100644 December 01/C#_Aswin_01.cs delete mode 100644 December 01/Python_Aswin_01.py diff --git a/December 01/C#_Aswin_01.cs b/December 01/C#_Aswin_01.cs new file mode 100644 index 0000000..d1c2e70 --- /dev/null +++ b/December 01/C#_Aswin_01.cs @@ -0,0 +1,24 @@ +using System; + +class Program +{ + static int FindMissingNumber(int N, int[] array) + { + int expectedSum = N * (N + 1) / 2; + int actualSum = 0; + + foreach (int num in array) + { + actualSum += num; + } + + return expectedSum - actualSum; + } + + static void Main() + { + // Test cases + Console.WriteLine(FindMissingNumber(5, new int[] { 1, 2, 4, 5 })); // Output: 3 + Console.WriteLine(FindMissingNumber(3, new int[] { 1, 3 })); // Output: 2 + } +} diff --git a/December 01/Python_Aswin_01.py b/December 01/Python_Aswin_01.py deleted file mode 100644 index 19cea7c..0000000 --- a/December 01/Python_Aswin_01.py +++ /dev/null @@ -1,8 +0,0 @@ -def find_missing_number(N, array): - expected_sum = N * (N + 1) // 2 - actual_sum = sum(array) - return expected_sum - actual_sum - -# Test cases -print(find_missing_number(5, [1, 2, 4, 5])) # Output: 3 -print(find_missing_number(3, [1, 3])) # Output: 2 From 5440ca58cd33087049ea358e664a4e6d04ffe854 Mon Sep 17 00:00:00 2001 From: Aswin Deivanayagam Subramanian <150608459+Ashprogrammer29@users.noreply.github.com> Date: Fri, 27 Dec 2024 22:02:23 +0530 Subject: [PATCH 03/37] Question 02 has been completed. --- December 02/C#_Aswin_02.cs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 December 02/C#_Aswin_02.cs diff --git a/December 02/C#_Aswin_02.cs b/December 02/C#_Aswin_02.cs new file mode 100644 index 0000000..6270ee6 --- /dev/null +++ b/December 02/C#_Aswin_02.cs @@ -0,0 +1,25 @@ +using System; + +class Program +{ + static int[] WaveSort(int[] arr) + { + Array.Sort(arr); + for (int i = 0; i < arr.Length - 1; i += 2) + { + int temp = arr[i]; + arr[i] = arr[i + 1]; + arr[i + 1] = temp; + } + return arr; + } + + static void Main() + { + int[] result1 = WaveSort(new int[] { 10, 5, 6, 3, 2, 20, 100, 80 }); + Console.WriteLine(string.Join(", ", result1)); + + int[] result2 = WaveSort(new int[] { 1, 2, 3, 4, 5, 6 }); + Console.WriteLine(string.Join(", ", result2)); + } +} From baab1b5c6ba94f723bae885dba83ffe2adbf673c Mon Sep 17 00:00:00 2001 From: Aswin Deivanayagam Subramanian <150608459+Ashprogrammer29@users.noreply.github.com> Date: Fri, 27 Dec 2024 22:04:32 +0530 Subject: [PATCH 04/37] Question 03 has been completed. --- December 03/C#_Aswin_03.cs | 41 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 December 03/C#_Aswin_03.cs diff --git a/December 03/C#_Aswin_03.cs b/December 03/C#_Aswin_03.cs new file mode 100644 index 0000000..52c4f51 --- /dev/null +++ b/December 03/C#_Aswin_03.cs @@ -0,0 +1,41 @@ +using System; +using System.Text; + +class Program +{ + static string AlternatingSquareArrangement(int R, int B) + { + if (Math.Abs(R - B) > 1) + { + return "Not possible"; + } + + StringBuilder result = new StringBuilder(); + int major = R >= B ? R : B; + int minor = R >= B ? B : R; + char majorColor = R >= B ? 'R' : 'B'; + char minorColor = R >= B ? 'B' : 'R'; + + for (int i = 0; i < major + minor; i++) + { + if (major > 0) + { + result.Append(majorColor); + major--; + } + if (minor > 0 && (result.Length == 0 || result[result.Length - 1] == majorColor)) + { + result.Append(minorColor); + minor--; + } + } + + return result.ToString(); + } + + static void Main() + { + Console.WriteLine(AlternatingSquareArrangement(3, 2)); + Console.WriteLine(AlternatingSquareArrangement(4, 2)); + } +} From 3b32c511ce8787f3c2482fc9a264cb58aaca0ab6 Mon Sep 17 00:00:00 2001 From: Aswin Deivanayagam Subramanian <150608459+Ashprogrammer29@users.noreply.github.com> Date: Fri, 27 Dec 2024 22:06:35 +0530 Subject: [PATCH 05/37] Question 01 has been completed. --- .../{C#_Aswin_01.cs => C#_Aswin_Deivanayagam_Subramanian_01.cs} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename December 01/{C#_Aswin_01.cs => C#_Aswin_Deivanayagam_Subramanian_01.cs} (100%) diff --git a/December 01/C#_Aswin_01.cs b/December 01/C#_Aswin_Deivanayagam_Subramanian_01.cs similarity index 100% rename from December 01/C#_Aswin_01.cs rename to December 01/C#_Aswin_Deivanayagam_Subramanian_01.cs From 58638d6b12aeb39ae4a5614d01cbdb59523418c4 Mon Sep 17 00:00:00 2001 From: Aswin Deivanayagam Subramanian <150608459+Ashprogrammer29@users.noreply.github.com> Date: Fri, 27 Dec 2024 22:08:17 +0530 Subject: [PATCH 06/37] Question 02 has been completed. --- .../{C#_Aswin_02.cs => C#_Aswin_Deivanayagam_Subramanian_02.cs} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename December 02/{C#_Aswin_02.cs => C#_Aswin_Deivanayagam_Subramanian_02.cs} (100%) diff --git a/December 02/C#_Aswin_02.cs b/December 02/C#_Aswin_Deivanayagam_Subramanian_02.cs similarity index 100% rename from December 02/C#_Aswin_02.cs rename to December 02/C#_Aswin_Deivanayagam_Subramanian_02.cs From 96c234ee9e7236fcdf636a1818ee8474c3e2dc2f Mon Sep 17 00:00:00 2001 From: Aswin Deivanayagam Subramanian <150608459+Ashprogrammer29@users.noreply.github.com> Date: Fri, 27 Dec 2024 22:08:38 +0530 Subject: [PATCH 07/37] Question 03 has been completed. --- .../{C#_Aswin_03.cs => C#_Aswin_Deivanayagam_Subramanian_03.cs} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename December 03/{C#_Aswin_03.cs => C#_Aswin_Deivanayagam_Subramanian_03.cs} (100%) diff --git a/December 03/C#_Aswin_03.cs b/December 03/C#_Aswin_Deivanayagam_Subramanian_03.cs similarity index 100% rename from December 03/C#_Aswin_03.cs rename to December 03/C#_Aswin_Deivanayagam_Subramanian_03.cs From a6f984feb2205818c531eacb422b99b2968ef2d7 Mon Sep 17 00:00:00 2001 From: Aswin Deivanayagam Subramanian <150608459+Ashprogrammer29@users.noreply.github.com> Date: Fri, 27 Dec 2024 22:09:29 +0530 Subject: [PATCH 08/37] Completed --- .../C#_Aswin_Deivanayagam_Subramanian_04.cs | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 December 04/C#_Aswin_Deivanayagam_Subramanian_04.cs diff --git a/December 04/C#_Aswin_Deivanayagam_Subramanian_04.cs b/December 04/C#_Aswin_Deivanayagam_Subramanian_04.cs new file mode 100644 index 0000000..a63c54e --- /dev/null +++ b/December 04/C#_Aswin_Deivanayagam_Subramanian_04.cs @@ -0,0 +1,28 @@ +using System; + +class Program +{ + static int PlantGrowthTracker(int n) + { + if (n == 1 || n == 2) + { + return 1; + } + + int prev = 1, curr = 1; + for (int i = 3; i <= n; i++) + { + int temp = curr; + curr = prev + curr; + prev = temp; + } + + return curr; + } + + static void Main() + { + Console.WriteLine(PlantGrowthTracker(10)); + Console.WriteLine(PlantGrowthTracker(12)); + } +} From 02dc45863bfbf03d4466f0b221c3878160f7e291 Mon Sep 17 00:00:00 2001 From: Aswin Deivanayagam Subramanian <150608459+Ashprogrammer29@users.noreply.github.com> Date: Fri, 27 Dec 2024 22:10:05 +0530 Subject: [PATCH 09/37] Completed --- .../C#_Aswin_Deivanayagam_Subramanian_05.cs | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 December 05/C#_Aswin_Deivanayagam_Subramanian_05.cs diff --git a/December 05/C#_Aswin_Deivanayagam_Subramanian_05.cs b/December 05/C#_Aswin_Deivanayagam_Subramanian_05.cs new file mode 100644 index 0000000..4add84e --- /dev/null +++ b/December 05/C#_Aswin_Deivanayagam_Subramanian_05.cs @@ -0,0 +1,20 @@ +using System; + +class Program +{ + static int Josephus(int n, int k) + { + int safePosition = 0; + for (int i = 1; i <= n; i++) + { + safePosition = (safePosition + k) % i; + } + return safePosition + 1; + } + + static void Main() + { + Console.WriteLine(Josephus(3, 2)); + Console.WriteLine(Josephus(5, 3)); + } +} From 97fb939614878106ee4c63f5e70eacd2639f15f9 Mon Sep 17 00:00:00 2001 From: Aswin Deivanayagam Subramanian <150608459+Ashprogrammer29@users.noreply.github.com> Date: Fri, 27 Dec 2024 22:10:34 +0530 Subject: [PATCH 10/37] Completed --- .../C#_Aswin_Deivanayagam_Subramanian_06.cs | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 December 06/C#_Aswin_Deivanayagam_Subramanian_06.cs diff --git a/December 06/C#_Aswin_Deivanayagam_Subramanian_06.cs b/December 06/C#_Aswin_Deivanayagam_Subramanian_06.cs new file mode 100644 index 0000000..e5c19f1 --- /dev/null +++ b/December 06/C#_Aswin_Deivanayagam_Subramanian_06.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; + +class Program +{ + static List> TargetPairFinder(int[] numbers, int target) + { + List> uniquePairs = new List>(); + HashSet seen = new HashSet(); + + foreach (int num in numbers) + { + int complement = target - num; + if (seen.Contains(complement)) + { + uniquePairs.Add(new Tuple(complement, num)); + } + else + { + seen.Add(num); + } + } + + return uniquePairs; + } + + static void Main() + { + var result1 = TargetPairFinder(new int[] { 2, 4, 3, 7, 1, 5 }, 6); + foreach (var pair in result1) + { + Console.WriteLine($"({pair.Item1}, {pair.Item2})"); + } + + var result2 = TargetPairFinder(new int[] { 10, 15, 3, 7, 8, 12, 5 }, 20); + foreach (var pair in result2) + { + Console.WriteLine($"({pair.Item1}, {pair.Item2})"); + } + } +} From fc7469f5ac987890b14061884cd90b144eef9fad Mon Sep 17 00:00:00 2001 From: Aswin Deivanayagam Subramanian <150608459+Ashprogrammer29@users.noreply.github.com> Date: Fri, 27 Dec 2024 22:11:02 +0530 Subject: [PATCH 11/37] Completed --- .../C#_Aswin_Deivanayagam_Subramanian_07.cs | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 December 06/C#_Aswin_Deivanayagam_Subramanian_07.cs diff --git a/December 06/C#_Aswin_Deivanayagam_Subramanian_07.cs b/December 06/C#_Aswin_Deivanayagam_Subramanian_07.cs new file mode 100644 index 0000000..4782371 --- /dev/null +++ b/December 06/C#_Aswin_Deivanayagam_Subramanian_07.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; + +class Program +{ + static List> GeneratePascalTriangle(int numRows) + { + List> result = new List>(); + + if (numRows == 0) + { + return result; + } + + result.Add(new List { 1 }); + + for (int i = 1; i < numRows; i++) + { + List row = new List { 1 }; + + for (int j = 1; j < i; j++) + { + row.Add(result[i - 1][j - 1] + result[i - 1][j]); + } + + row.Add(1); + result.Add(row); + } + + return result; + } + + static void Main() + { + var triangle = GeneratePascalTriangle(5); + foreach (var row in triangle) + { + Console.WriteLine(string.Join(" ", row)); + } + } +} From 4cfa1a424df8bebe6d363055a87e88789b95f73e Mon Sep 17 00:00:00 2001 From: Aswin Deivanayagam Subramanian <150608459+Ashprogrammer29@users.noreply.github.com> Date: Fri, 27 Dec 2024 22:11:30 +0530 Subject: [PATCH 12/37] Completed --- .../C#_Aswin_Deivanayagam_Subramanian_08.cs | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 December 06/C#_Aswin_Deivanayagam_Subramanian_08.cs diff --git a/December 06/C#_Aswin_Deivanayagam_Subramanian_08.cs b/December 06/C#_Aswin_Deivanayagam_Subramanian_08.cs new file mode 100644 index 0000000..f38a439 --- /dev/null +++ b/December 06/C#_Aswin_Deivanayagam_Subramanian_08.cs @@ -0,0 +1,31 @@ +using System; + +class Program +{ + static int DigitSquareSum(int N) + { + int DigitSquareSumOfNumber(int num) + { + int total = 0; + while (num > 0) + { + int digit = num % 10; + total += digit * digit; + num /= 10; + } + return total; + } + + int totalSum = 0; + for (int i = 1; i <= N; i++) + { + totalSum += DigitSquareSumOfNumber(i); + } + return totalSum; + } + + static void Main() + { + Console.WriteLine(DigitSquareSum(10)); // Example usage + } +} From 2c791bc5d3fa7bceb2a4aa88d9b6603b6bc431e6 Mon Sep 17 00:00:00 2001 From: Aswin Deivanayagam Subramanian <150608459+Ashprogrammer29@users.noreply.github.com> Date: Fri, 27 Dec 2024 22:12:50 +0530 Subject: [PATCH 13/37] Completed --- .../C#_Aswin_Deivanayagam_Subramanian_07.cs | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 December 07/C#_Aswin_Deivanayagam_Subramanian_07.cs diff --git a/December 07/C#_Aswin_Deivanayagam_Subramanian_07.cs b/December 07/C#_Aswin_Deivanayagam_Subramanian_07.cs new file mode 100644 index 0000000..4782371 --- /dev/null +++ b/December 07/C#_Aswin_Deivanayagam_Subramanian_07.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; + +class Program +{ + static List> GeneratePascalTriangle(int numRows) + { + List> result = new List>(); + + if (numRows == 0) + { + return result; + } + + result.Add(new List { 1 }); + + for (int i = 1; i < numRows; i++) + { + List row = new List { 1 }; + + for (int j = 1; j < i; j++) + { + row.Add(result[i - 1][j - 1] + result[i - 1][j]); + } + + row.Add(1); + result.Add(row); + } + + return result; + } + + static void Main() + { + var triangle = GeneratePascalTriangle(5); + foreach (var row in triangle) + { + Console.WriteLine(string.Join(" ", row)); + } + } +} From 364e027e7a364bd617337360318f741e1f1cd7a7 Mon Sep 17 00:00:00 2001 From: Aswin Deivanayagam Subramanian <150608459+Ashprogrammer29@users.noreply.github.com> Date: Fri, 27 Dec 2024 22:13:18 +0530 Subject: [PATCH 14/37] Completed --- .../C#_Aswin_Deivanayagam_Subramanian_08.cs | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 December 08/C#_Aswin_Deivanayagam_Subramanian_08.cs diff --git a/December 08/C#_Aswin_Deivanayagam_Subramanian_08.cs b/December 08/C#_Aswin_Deivanayagam_Subramanian_08.cs new file mode 100644 index 0000000..f38a439 --- /dev/null +++ b/December 08/C#_Aswin_Deivanayagam_Subramanian_08.cs @@ -0,0 +1,31 @@ +using System; + +class Program +{ + static int DigitSquareSum(int N) + { + int DigitSquareSumOfNumber(int num) + { + int total = 0; + while (num > 0) + { + int digit = num % 10; + total += digit * digit; + num /= 10; + } + return total; + } + + int totalSum = 0; + for (int i = 1; i <= N; i++) + { + totalSum += DigitSquareSumOfNumber(i); + } + return totalSum; + } + + static void Main() + { + Console.WriteLine(DigitSquareSum(10)); // Example usage + } +} From 661dc134195486855ae41fa9cf689f9d3f5b14d9 Mon Sep 17 00:00:00 2001 From: Aswin Deivanayagam Subramanian <150608459+Ashprogrammer29@users.noreply.github.com> Date: Fri, 27 Dec 2024 22:13:49 +0530 Subject: [PATCH 15/37] Completed --- .../C#_Aswin_Deivanayagam_Subramanian_09.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 December 09/C#_Aswin_Deivanayagam_Subramanian_09.cs diff --git a/December 09/C#_Aswin_Deivanayagam_Subramanian_09.cs b/December 09/C#_Aswin_Deivanayagam_Subramanian_09.cs new file mode 100644 index 0000000..978201e --- /dev/null +++ b/December 09/C#_Aswin_Deivanayagam_Subramanian_09.cs @@ -0,0 +1,15 @@ +using System; +using System.Linq; + +class Program +{ + static int CountCustomersWithOneReturn(int[] returns) + { + return returns.Count(r => r == 1); + } + + static void Main() + { + Console.WriteLine(CountCustomersWithOneReturn(new int[] { 1, 2, 1, 3, 1 })); // Example usage + } +} From 47e2066b2bad2b0c10cca6df4c8333311baa5c24 Mon Sep 17 00:00:00 2001 From: Aswin Deivanayagam Subramanian <150608459+Ashprogrammer29@users.noreply.github.com> Date: Fri, 27 Dec 2024 22:14:21 +0530 Subject: [PATCH 16/37] Completed --- .../C#_Aswin_Deivanayagam_Subramanian_10.cs | 102 ++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 December 10/C#_Aswin_Deivanayagam_Subramanian_10.cs diff --git a/December 10/C#_Aswin_Deivanayagam_Subramanian_10.cs b/December 10/C#_Aswin_Deivanayagam_Subramanian_10.cs new file mode 100644 index 0000000..c1caf1b --- /dev/null +++ b/December 10/C#_Aswin_Deivanayagam_Subramanian_10.cs @@ -0,0 +1,102 @@ +using System; +using System.Collections.Generic; + +class Program +{ + static List> FindTaskOrder(List>> tasks) + { + var graph = new Dictionary>(); + var inDegree = new Dictionary(); + + foreach (var task in tasks) + { + int taskId = task.Item1; + List dependencies = task.Item2; + foreach (var dependency in dependencies) + { + if (!graph.ContainsKey(dependency)) + { + graph[dependency] = new List(); + } + graph[dependency].Add(taskId); + + if (!inDegree.ContainsKey(taskId)) + { + inDegree[taskId] = 0; + } + inDegree[taskId]++; + } + + if (!inDegree.ContainsKey(taskId)) + { + inDegree[taskId] = 0; + } + } + + var queue = new Queue(); + foreach (var task in inDegree) + { + if (task.Value == 0) + { + queue.Enqueue(task.Key); + } + } + + var result = new List>(); + + while (queue.Count > 0) + { + var concurrentTasks = new List(); + int currentQueueSize = queue.Count; + for (int i = 0; i < currentQueueSize; i++) + { + int task = queue.Dequeue(); + concurrentTasks.Add(task); + if (graph.ContainsKey(task)) + { + foreach (var neighbor in graph[task]) + { + inDegree[neighbor]--; + if (inDegree[neighbor] == 0) + { + queue.Enqueue(neighbor); + } + } + } + } + result.Add(concurrentTasks); + } + + if (inDegree.Values.Contains(1)) + { + return new List> { new List { -1 } }; // Error: Cyclic dependency detected + } + + return result; + } + + static void Main() + { + var tasks = new List>>() + { + new Tuple>(1, new List{2, 3}), + new Tuple>(2, new List{4}), + new Tuple>(3, new List{4}), + new Tuple>(4, new List()) + }; + + var taskOrder = FindTaskOrder(tasks); + + if (taskOrder.Count == 1 && taskOrder[0][0] == -1) + { + Console.WriteLine("Error: Cyclic dependency detected"); + } + else + { + foreach (var taskBatch in taskOrder) + { + Console.WriteLine(string.Join(", ", taskBatch)); + } + } + } +} From 7141b5811d7e651e5ab889d6d267835470c9b518 Mon Sep 17 00:00:00 2001 From: Aswin Deivanayagam Subramanian <150608459+Ashprogrammer29@users.noreply.github.com> Date: Fri, 27 Dec 2024 22:15:03 +0530 Subject: [PATCH 17/37] Completed --- .../C#_Aswin_Deivanayagam_Subramanian_11.cs | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 December 11/C#_Aswin_Deivanayagam_Subramanian_11.cs diff --git a/December 11/C#_Aswin_Deivanayagam_Subramanian_11.cs b/December 11/C#_Aswin_Deivanayagam_Subramanian_11.cs new file mode 100644 index 0000000..50f2f19 --- /dev/null +++ b/December 11/C#_Aswin_Deivanayagam_Subramanian_11.cs @@ -0,0 +1,34 @@ +using System; + +class Program +{ + static bool RobotReturnToOrigin(string moves) + { + int x = 0, y = 0; + foreach (char move in moves) + { + if (move == 'R') + { + x += 1; + } + else if (move == 'L') + { + x -= 1; + } + else if (move == 'U') + { + y += 1; + } + else if (move == 'D') + { + y -= 1; + } + } + return x == 0 && y == 0; + } + + static void Main() + { + Console.WriteLine(RobotReturnToOrigin("UDLR")); // Example usage + } +} From 2a8578bf4aa13241e9ed7ee81988d77e77e342af Mon Sep 17 00:00:00 2001 From: Aswin Deivanayagam Subramanian <150608459+Ashprogrammer29@users.noreply.github.com> Date: Fri, 27 Dec 2024 22:15:38 +0530 Subject: [PATCH 18/37] Completed --- .../C#_Aswin_Deivanayagam_Subramanian_12.cs | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 December 12/C#_Aswin_Deivanayagam_Subramanian_12.cs diff --git a/December 12/C#_Aswin_Deivanayagam_Subramanian_12.cs b/December 12/C#_Aswin_Deivanayagam_Subramanian_12.cs new file mode 100644 index 0000000..0ec04df --- /dev/null +++ b/December 12/C#_Aswin_Deivanayagam_Subramanian_12.cs @@ -0,0 +1,68 @@ +using System; +using System.Collections.Generic; + +class Program +{ + static List SmartTicketingSystem(int N, List requests) + { + var queue = new LinkedList>(); + var results = new List(); + int availableTickets = N; + + foreach (var request in requests) + { + var parts = request.Split(); + string customer = parts[0]; + int numTickets = int.Parse(parts[1]); + bool isVip = parts.Length == 3 && parts[2] == "VIP"; + + if (isVip) + { + queue.AddFirst(new Tuple(customer, numTickets)); + } + else + { + queue.AddLast(new Tuple(customer, numTickets)); + } + } + + while (queue.Count > 0 && availableTickets > 0) + { + var firstCustomer = queue.First.Value; + queue.RemoveFirst(); + + string customer = firstCustomer.Item1; + int numTickets = firstCustomer.Item2; + int ticketsAllocated = Math.Min(numTickets, availableTickets); + availableTickets -= ticketsAllocated; + + if (ticketsAllocated > 0) + { + results.Add($"{customer} purchased {ticketsAllocated} tickets"); + } + else + { + results.Add($"{customer} was not served"); + } + } + + return results; + } + + static void Main() + { + var requests = new List + { + "Alice 3 VIP", + "Bob 2", + "Charlie 5 VIP", + "David 1" + }; + + var result = SmartTicketingSystem(5, requests); + foreach (var res in result) + { + Console.WriteLine(res); + } + } +} From 751e61e4e4e040bb11654b9a3d0268c7ddf1a866 Mon Sep 17 00:00:00 2001 From: Aswin Deivanayagam Subramanian <150608459+Ashprogrammer29@users.noreply.github.com> Date: Fri, 27 Dec 2024 22:16:11 +0530 Subject: [PATCH 19/37] Completed --- .../C#_Aswin_Deivanayagam_Subramanian_13.cs | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 December 13/C#_Aswin_Deivanayagam_Subramanian_13.cs diff --git a/December 13/C#_Aswin_Deivanayagam_Subramanian_13.cs b/December 13/C#_Aswin_Deivanayagam_Subramanian_13.cs new file mode 100644 index 0000000..86c3976 --- /dev/null +++ b/December 13/C#_Aswin_Deivanayagam_Subramanian_13.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; + +class Program +{ + static int MinSwaps(List nums) + { + var sortedNums = new List(nums); + sortedNums.Sort(); + var pos = new Dictionary(); + + for (int i = 0; i < sortedNums.Count; i++) + { + pos[sortedNums[i]] = i; + } + + int count = 0; + + for (int i = 0; i < nums.Count; i++) + { + if (pos[nums[i]] != i) + { + count++; + int temp = nums[i]; + nums[i] = nums[pos[nums[i]]]; + nums[pos[nums[i]]] = temp; + pos[nums[i]] = i; + } + } + + return count; + } + + static void Main() + { + var nums = new List { 4, 3, 2, 1 }; + Console.WriteLine(MinSwaps(nums)); // Example usage + } +} From 5a4e07dcd995b6c41ce6cd2797ff65500a1e08c1 Mon Sep 17 00:00:00 2001 From: Aswin Deivanayagam Subramanian <150608459+Ashprogrammer29@users.noreply.github.com> Date: Fri, 27 Dec 2024 22:16:43 +0530 Subject: [PATCH 20/37] Completed --- .../C#_Aswin_Deivanayagam_Subramanian_14.cs | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 December 14/C#_Aswin_Deivanayagam_Subramanian_14.cs diff --git a/December 14/C#_Aswin_Deivanayagam_Subramanian_14.cs b/December 14/C#_Aswin_Deivanayagam_Subramanian_14.cs new file mode 100644 index 0000000..034ed01 --- /dev/null +++ b/December 14/C#_Aswin_Deivanayagam_Subramanian_14.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +class Program +{ + static string CanSplitSquad(int N, int K, int D, List A) + { + var subjectCounts = A.GroupBy(x => x).ToDictionary(g => g.Key, g => g.Count()); + int uniqueSubjects = subjectCounts.Count; + + if (uniqueSubjects < K) + { + return "NO"; + } + + int maxTeamSize = (N + D) / 2; + int minTeamSize = (N - D) / 2; + + if (subjectCounts.Values.Count(count => count <= minTeamSize) < K) + { + return "NO"; + } + + return "YES"; + } + + static void Main() + { + var A = new List { 1, 2, 2, 3, 3, 4, 4 }; + Console.WriteLine(CanSplitSquad(7, 3, 2, A)); // Example usage + } +} From 52e23af759cd4fd58b91facb5e91a1223e161992 Mon Sep 17 00:00:00 2001 From: Aswin Deivanayagam Subramanian <150608459+Ashprogrammer29@users.noreply.github.com> Date: Fri, 27 Dec 2024 22:17:12 +0530 Subject: [PATCH 21/37] Completed --- .../C#_Aswin_Deivanayagam_Subramanian_15.cs | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 December 15/C#_Aswin_Deivanayagam_Subramanian_15.cs diff --git a/December 15/C#_Aswin_Deivanayagam_Subramanian_15.cs b/December 15/C#_Aswin_Deivanayagam_Subramanian_15.cs new file mode 100644 index 0000000..4d87c19 --- /dev/null +++ b/December 15/C#_Aswin_Deivanayagam_Subramanian_15.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; + +class Program +{ + static int MinTrips(List houses, int W) + { + int trips = 0; + int currentLoad = 0; + + foreach (int gifts in houses) + { + if (currentLoad + gifts > W) + { + trips++; + currentLoad = 0; + } + currentLoad += gifts; + } + + if (currentLoad > 0) + { + trips++; + } + + return trips; + } + + static void Main() + { + var houses = new List { 5, 10, 7, 3, 6 }; + Console.WriteLine(MinTrips(houses, 15)); // Example usage + } +} From f2cd977dd521cd80f3bd722903d905f473936dfb Mon Sep 17 00:00:00 2001 From: Aswin Deivanayagam Subramanian <150608459+Ashprogrammer29@users.noreply.github.com> Date: Fri, 27 Dec 2024 22:17:49 +0530 Subject: [PATCH 22/37] Completed --- .../C#_Aswin_Deivanayagam_Subramanian_16.cs | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 December 16/C#_Aswin_Deivanayagam_Subramanian_16.cs diff --git a/December 16/C#_Aswin_Deivanayagam_Subramanian_16.cs b/December 16/C#_Aswin_Deivanayagam_Subramanian_16.cs new file mode 100644 index 0000000..72496f5 --- /dev/null +++ b/December 16/C#_Aswin_Deivanayagam_Subramanian_16.cs @@ -0,0 +1,41 @@ +using System; +using System.Linq; + +class Program +{ + static int MinPlatforms(int[] arrivals, int[] departures) + { + Array.Sort(arrivals); + Array.Sort(departures); + + int platformsNeeded = 0; + int currentPlatforms = 0; + + int i = 0, j = 0; + + while (i < arrivals.Length) + { + if (arrivals[i] <= departures[j]) + { + currentPlatforms++; + i++; + } + else + { + currentPlatforms--; + j++; + } + + platformsNeeded = Math.Max(platformsNeeded, currentPlatforms); + } + + return platformsNeeded; + } + + static void Main() + { + int[] arrivals = { 100, 140, 150, 200 }; + int[] departures = { 110, 160, 170, 230 }; + Console.WriteLine(MinPlatforms(arrivals, departures)); // Example usage + } +} From 8c38c17735ae2fb3bc4d51230fb397a8d3e36b70 Mon Sep 17 00:00:00 2001 From: Aswin Deivanayagam Subramanian <150608459+Ashprogrammer29@users.noreply.github.com> Date: Fri, 27 Dec 2024 22:18:24 +0530 Subject: [PATCH 23/37] Completed --- .../C#_Aswin_Deivanayagam_Subramanian_17.cs | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 December 17/C#_Aswin_Deivanayagam_Subramanian_17.cs diff --git a/December 17/C#_Aswin_Deivanayagam_Subramanian_17.cs b/December 17/C#_Aswin_Deivanayagam_Subramanian_17.cs new file mode 100644 index 0000000..16edced --- /dev/null +++ b/December 17/C#_Aswin_Deivanayagam_Subramanian_17.cs @@ -0,0 +1,84 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +class AlertManager +{ + private Dictionary alerts; + private Dictionary lastSeen; + + public AlertManager() + { + alerts = new Dictionary(); + lastSeen = new Dictionary(); + } + + public void ProcessAlert(Dictionary alert) + { + string alertId = alert["id"].ToString(); + DateTime currentTime = DateTime.Now; + + // Check for duplicates within 30 seconds + if (lastSeen.ContainsKey(alertId) && lastSeen[alertId].HasValue && (currentTime - lastSeen[alertId].Value).TotalSeconds < 30) + { + return; + } + + // Update alert information + if (alerts.ContainsKey(alertId)) + { + int existingThreatLevel = alerts[alertId].threatLevel; + alerts[alertId] = (currentTime, Math.Max(existingThreatLevel, Convert.ToInt32(alert["threat_level"]))); + } + else + { + alerts[alertId] = (currentTime, Convert.ToInt32(alert["threat_level"])); + } + + lastSeen[alertId] = currentTime; + } + + public List<(DateTime timestamp, int threatLevel)> GetAlerts() + { + DateTime currentTime = DateTime.Now; + var validAlerts = new List<(DateTime timestamp, int threatLevel)>(); + + foreach (var alert in alerts) + { + if ((currentTime - alert.Value.timestamp).TotalMinutes < 5) + { + validAlerts.Add(alert.Value); + } + } + + return validAlerts; + } +} + +class Program +{ + static void Main() + { + var alertManager = new AlertManager(); + + var alerts = new List>() + { + new Dictionary { { "id", "A123" }, { "timestamp", "00:00:10" }, { "threat_level", 3 } }, + new Dictionary { { "id", "A123" }, { "timestamp", "00:00:15" }, { "threat_level", 3 } }, + new Dictionary { { "id", "B456" }, { "timestamp", "00:00:20" }, { "threat_level", 2 } }, + new Dictionary { { "id", "A123" }, { "timestamp", "00:00:30" }, { "threat_level", 5 } }, + new Dictionary { { "id", "B456" }, { "timestamp", "00:05:05" }, { "threat_level", 2 } } + }; + + foreach (var alert in alerts) + { + alertManager.ProcessAlert(alert); + } + + var storedAlerts = alertManager.GetAlerts(); + foreach (var alert in storedAlerts) + { + Console.WriteLine($"Timestamp: {alert.timestamp}, Threat Level: {alert.threatLevel}"); + } + } +} From 14d81216d996028d0581679e065359d5029be151 Mon Sep 17 00:00:00 2001 From: Aswin Deivanayagam Subramanian <150608459+Ashprogrammer29@users.noreply.github.com> Date: Fri, 27 Dec 2024 22:19:01 +0530 Subject: [PATCH 24/37] Completed --- .../C#_Aswin_Deivanayagam_Subramanian_18.cs | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 December 18/C#_Aswin_Deivanayagam_Subramanian_18.cs diff --git a/December 18/C#_Aswin_Deivanayagam_Subramanian_18.cs b/December 18/C#_Aswin_Deivanayagam_Subramanian_18.cs new file mode 100644 index 0000000..1a4d117 --- /dev/null +++ b/December 18/C#_Aswin_Deivanayagam_Subramanian_18.cs @@ -0,0 +1,70 @@ +using System; +using System.Linq; + +class Program +{ + static int GemValue(char gem) + { + switch (gem) + { + case 'D': return 500; + case 'R': return 250; + case 'E': return 100; + default: return 0; + } + } + + static int MaxPalindromicChainProfit(string chain) + { + int n = chain.Length; + if (n == 0) + return 0; + + string s = "@#" + string.Join("#", chain.Select(c => c.ToString())) + "#$"; + int[] p = new int[s.Length]; + int c = 0, r = 0; + + for (int i = 1; i < s.Length - 1; i++) + { + if (i < r) + p[i] = Math.Min(r - i, p[2 * c - i]); + while (s[i + p[i] + 1] == s[i - p[i] - 1]) + p[i]++; + if (i + p[i] > r) + { + c = i; + r = i + p[i]; + } + } + + int maxLength = 0; + int center = 0; + for (int i = 1; i < s.Length - 1; i++) + { + if (p[i] > maxLength) + { + maxLength = p[i]; + center = i; + } + } + + int start = (center - maxLength) / 2; + int end = (center + maxLength) / 2; + + int totalValue = 0; + for (int i = start; i < end; i++) + { + totalValue += GemValue(chain[i]); + } + + int profit = totalValue * (end - start + 1); + + return profit; + } + + static void Main() + { + string chain = "DRREED"; + Console.WriteLine(MaxPalindromicChainProfit(chain)); // Example usage + } +} From eb8d005cafd1260166351caf320a93260102e043 Mon Sep 17 00:00:00 2001 From: Aswin Deivanayagam Subramanian <150608459+Ashprogrammer29@users.noreply.github.com> Date: Fri, 27 Dec 2024 22:19:29 +0530 Subject: [PATCH 25/37] Completed --- .../C#_Aswin_Deivanayagam_Subramanian_19.cs | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 December 19/C#_Aswin_Deivanayagam_Subramanian_19.cs diff --git a/December 19/C#_Aswin_Deivanayagam_Subramanian_19.cs b/December 19/C#_Aswin_Deivanayagam_Subramanian_19.cs new file mode 100644 index 0000000..83e964d --- /dev/null +++ b/December 19/C#_Aswin_Deivanayagam_Subramanian_19.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; + +class Program +{ + static List> TowerOfHanoi(int n, string source, string destination, string auxiliary) + { + if (n == 0) + return new List>(); + + var moves = new List>(); + moves.AddRange(TowerOfHanoi(n - 1, source, auxiliary, destination)); + moves.Add(Tuple.Create(source, destination)); + moves.AddRange(TowerOfHanoi(n - 1, auxiliary, destination, source)); + + return moves; + } + + static void Main() + { + int numDisks = 4; + string start = "A"; + string destination = "C"; + string auxiliary = "B"; + + var moves = TowerOfHanoi(numDisks, start, destination, auxiliary); + + Console.WriteLine($"Minimum number of moves: {moves.Count}"); + Console.WriteLine("Sequence of moves:"); + for (int i = 0; i < moves.Count; i++) + { + Console.WriteLine($"{i + 1}. Move disk 1 from {moves[i].Item1} to {moves[i].Item2}"); + } + } +} From 1e406c656c1d1fdd460a0683b5a1b878b680eef2 Mon Sep 17 00:00:00 2001 From: Aswin Deivanayagam Subramanian <150608459+Ashprogrammer29@users.noreply.github.com> Date: Fri, 27 Dec 2024 22:19:57 +0530 Subject: [PATCH 26/37] Completed --- .../C#_Aswin_Deivanayagam_Subramanian_20.cs | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 December 20/C#_Aswin_Deivanayagam_Subramanian_20.cs diff --git a/December 20/C#_Aswin_Deivanayagam_Subramanian_20.cs b/December 20/C#_Aswin_Deivanayagam_Subramanian_20.cs new file mode 100644 index 0000000..120f12b --- /dev/null +++ b/December 20/C#_Aswin_Deivanayagam_Subramanian_20.cs @@ -0,0 +1,31 @@ +using System; + +class Program +{ + static int CountRobotPaths(int[] steps, int distance) + { + if (distance == 0) + return 1; + + int[] dp = new int[distance + 1]; + dp[0] = 1; + + for (int i = 1; i <= distance; i++) + { + foreach (int step in steps) + { + if (i - step >= 0) + dp[i] += dp[i - step]; + } + } + + return dp[distance]; + } + + static void Main() + { + int[] steps = { 1, 2, 3 }; + int distance = 4; + Console.WriteLine(CountRobotPaths(steps, distance)); // Example usage + } +} From 3da867b4adaa026e775223cb836f8bb5301b2381 Mon Sep 17 00:00:00 2001 From: Aswin Deivanayagam Subramanian <150608459+Ashprogrammer29@users.noreply.github.com> Date: Fri, 27 Dec 2024 22:20:39 +0530 Subject: [PATCH 27/37] Completed --- .../C#_Aswin_Deivanayagam_Subramanian_21.cs | 92 +++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 December 21/C#_Aswin_Deivanayagam_Subramanian_21.cs diff --git a/December 21/C#_Aswin_Deivanayagam_Subramanian_21.cs b/December 21/C#_Aswin_Deivanayagam_Subramanian_21.cs new file mode 100644 index 0000000..41f470e --- /dev/null +++ b/December 21/C#_Aswin_Deivanayagam_Subramanian_21.cs @@ -0,0 +1,92 @@ +using System; + +class Node +{ + public int Data; + public Node Next; + + public Node(int data) + { + Data = data; + Next = null; + } +} + +class Program +{ + static Node CreateLinkedList(int[] values) + { + Node head = null; + foreach (var value in values) + { + Node newNode = new Node(value); + if (head == null) + { + head = newNode; + } + else + { + Node current = head; + while (current.Next != null) + { + current = current.Next; + } + current.Next = newNode; + } + } + return head; + } + + static string FindIntersection(Node head1, Node head2, int intersectionPos) + { + if (intersectionPos == 0) + { + return "No intersection found."; + } + + Node current1 = head1; + for (int i = 1; i < intersectionPos; i++) + { + if (current1 == null) + { + return "Invalid intersection position"; + } + current1 = current1.Next; + } + + Node current2 = head2; + while (current1 != null) + { + if (current1 == current2) + { + return current1.Data.ToString(); + } + current1 = current1.Next; + current2 = current2.Next; + } + + return "No intersection found."; + } + + static void Main() + { + Console.Write("Enter the number of nodes in the first linked list: "); + int n1 = int.Parse(Console.ReadLine()); + Console.Write("Enter the node values: "); + int[] values1 = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); + + Console.Write("Enter the number of nodes in the second linked list: "); + int n2 = int.Parse(Console.ReadLine()); + Console.Write("Enter the node values: "); + int[] values2 = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); + + Console.Write("Enter the position of intersection: "); + int intersectionPos = int.Parse(Console.ReadLine()); + + Node head1 = CreateLinkedList(values1); + Node head2 = CreateLinkedList(values2); + + string intersectionValue = FindIntersection(head1, head2, intersectionPos); + Console.WriteLine(intersectionValue); + } +} From b2ee2bafcb97ba948355de53d9ac2a40be48ef21 Mon Sep 17 00:00:00 2001 From: Aswin Deivanayagam Subramanian <150608459+Ashprogrammer29@users.noreply.github.com> Date: Fri, 27 Dec 2024 22:21:11 +0530 Subject: [PATCH 28/37] Completed --- .../C#_Aswin_Deivanayagam_Subramanian_22.cs | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 December 22/C#_Aswin_Deivanayagam_Subramanian_22.cs diff --git a/December 22/C#_Aswin_Deivanayagam_Subramanian_22.cs b/December 22/C#_Aswin_Deivanayagam_Subramanian_22.cs new file mode 100644 index 0000000..115ffe6 --- /dev/null +++ b/December 22/C#_Aswin_Deivanayagam_Subramanian_22.cs @@ -0,0 +1,44 @@ +using System; + +class Program +{ + static double CalculateDistance(int x1, int y1, int x2, int y2) + { + return Math.Sqrt(Math.Pow(x1 - x2, 2) + Math.Pow(y1 - y2, 2)); + } + + static int EarthquakePropagation(int[,] buildings) + { + int maxAffected = 0; + + for (int i = 0; i < buildings.GetLength(0); i++) + { + int affected = 1; + for (int j = 0; j < buildings.GetLength(0); j++) + { + if (i != j) + { + double distance = CalculateDistance(buildings[i, 0], buildings[i, 1], buildings[j, 0], buildings[j, 1]); + if (distance <= buildings[i, 2]) + { + affected++; + } + } + } + maxAffected = Math.Max(maxAffected, affected); + } + + return maxAffected; + } + + static void Main() + { + int[,] buildings = { + { 2, 1, 3 }, + { 6, 1, 4 } + }; + + int maxAffected = EarthquakePropagation(buildings); + Console.WriteLine(maxAffected); + } +} From 6819f0d35c210a7930ef253eb236f3980437d440 Mon Sep 17 00:00:00 2001 From: Aswin Deivanayagam Subramanian <150608459+Ashprogrammer29@users.noreply.github.com> Date: Fri, 27 Dec 2024 22:21:49 +0530 Subject: [PATCH 29/37] Completed --- .../C#_Aswin_Deivanayagam_Subramanian_23.cs | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 December 23/C#_Aswin_Deivanayagam_Subramanian_23.cs diff --git a/December 23/C#_Aswin_Deivanayagam_Subramanian_23.cs b/December 23/C#_Aswin_Deivanayagam_Subramanian_23.cs new file mode 100644 index 0000000..6769298 --- /dev/null +++ b/December 23/C#_Aswin_Deivanayagam_Subramanian_23.cs @@ -0,0 +1,39 @@ +using System; + +class Program +{ + static int CrystalGridFinalResult(int[,] grid) + { + int n = grid.GetLength(0); + int primarySum = 0, secondarySum = 0, boundarySum = 0; + + for (int i = 0; i < n; i++) + { + primarySum += grid[i, i]; + secondarySum += grid[i, n - 1 - i]; + for (int j = 0; j < n; j++) + { + if (i == 0 || i == n - 1 || j == 0 || j == n - 1) + { + boundarySum += grid[i, j]; + } + } + } + + int diagonalEnergy = Math.Abs(primarySum - secondarySum); + int finalResult = diagonalEnergy + boundarySum; + return finalResult; + } + + static void Main() + { + int[,] grid = { + { 1, 2, 3 }, + { 4, 5, 6 }, + { 7, 8, 9 } + }; + + int result = CrystalGridFinalResult(grid); + Console.WriteLine(result); // Output: 40 + } +} From 8da6e051df3aa83e3f9c2f3d11fe84df75fb5453 Mon Sep 17 00:00:00 2001 From: Aswin Deivanayagam Subramanian <150608459+Ashprogrammer29@users.noreply.github.com> Date: Fri, 27 Dec 2024 22:25:35 +0530 Subject: [PATCH 30/37] Completed --- .../C#_Aswin_Deivanayagam_Subramanian_24.cs | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 December 24/C#_Aswin_Deivanayagam_Subramanian_24.cs diff --git a/December 24/C#_Aswin_Deivanayagam_Subramanian_24.cs b/December 24/C#_Aswin_Deivanayagam_Subramanian_24.cs new file mode 100644 index 0000000..711e147 --- /dev/null +++ b/December 24/C#_Aswin_Deivanayagam_Subramanian_24.cs @@ -0,0 +1,71 @@ +using System; +using System.Collections.Generic; + +public class StringPermutationGrouping +{ + public static Dictionary> GroupPermutations(string s) + { + var result = new Dictionary>(); + var uniquePermutations = GetUniquePermutations(s.ToCharArray(), 0, s.Length - 1); + + foreach (var perm in uniquePermutations) + { + char firstLetter = perm[0]; + if (!result.ContainsKey(firstLetter)) + { + result[firstLetter] = new List(); + } + result[firstLetter].Add(perm); + } + + foreach (var key in result.Keys) + { + result[key].Sort(); + } + + return result; + } + + private static HashSet GetUniquePermutations(char[] array, int start, int end) + { + var result = new HashSet(); + + if (start == end) + { + result.Add(new string(array)); + } + else + { + for (int i = start; i <= end; i++) + { + Swap(ref array[start], ref array[i]); + var permutations = GetUniquePermutations(array, start + 1, end); + foreach (var perm in permutations) + { + result.Add(perm); + } + Swap(ref array[start], ref array[i]); // Backtrack + } + } + + return result; + } + + private static void Swap(ref char a, ref char b) + { + char temp = a; + a = b; + b = temp; + } + + public static void Main(string[] args) + { + string input = "abc"; + var result = GroupPermutations(input); + + foreach (var group in result) + { + Console.WriteLine($"{group.Key}: {string.Join(", ", group.Value)}"); + } + } +} From 7a72978b562f3019e4338a31130cec1e6832e554 Mon Sep 17 00:00:00 2001 From: Aswin Deivanayagam Subramanian <150608459+Ashprogrammer29@users.noreply.github.com> Date: Fri, 27 Dec 2024 22:26:11 +0530 Subject: [PATCH 31/37] Completed --- .../C#_Aswin_Deivanayagam_Subramanian_25.cs | 165 ++++++++++++++++++ 1 file changed, 165 insertions(+) create mode 100644 December 25/C#_Aswin_Deivanayagam_Subramanian_25.cs diff --git a/December 25/C#_Aswin_Deivanayagam_Subramanian_25.cs b/December 25/C#_Aswin_Deivanayagam_Subramanian_25.cs new file mode 100644 index 0000000..4b1af03 --- /dev/null +++ b/December 25/C#_Aswin_Deivanayagam_Subramanian_25.cs @@ -0,0 +1,165 @@ +using System; +using System.Collections.Generic; +using System.IO; + +public class TaskScheduler +{ + private Dictionary tasks; // For constant time search (O(k)) + private SortedList> priorityQueue; // To maintain tasks sorted by priority + + public TaskScheduler() + { + tasks = new Dictionary(); + priorityQueue = new SortedList>(); + } + + public void AddTask(string description, int priority) + { + var task = new TaskNode(description, priority); + + if (!tasks.ContainsKey(description)) + { + tasks.Add(description, task); + if (!priorityQueue.ContainsKey(priority)) + { + priorityQueue[priority] = new LinkedList(); + } + priorityQueue[priority].AddLast(task); + SaveTasksToFile(); // Save to file after each task addition + } + else + { + Console.WriteLine("Task already exists."); + } + } + + public void RemoveTask(string description) + { + if (tasks.ContainsKey(description)) + { + var task = tasks[description]; + priorityQueue[task.Priority].Remove(task); + if (priorityQueue[task.Priority].Count == 0) + { + priorityQueue.Remove(task.Priority); + } + tasks.Remove(description); + SaveTasksToFile(); // Save after task removal + } + else + { + Console.WriteLine("Task not found."); + } + } + + public void SearchTask(string description) + { + if (tasks.ContainsKey(description)) + { + Console.WriteLine($"Task Found: ({description}, Priority {tasks[description].Priority})"); + } + else + { + Console.WriteLine("Task not found."); + } + } + + public void DisplayTasks() + { + foreach (var priority in priorityQueue.Reverse()) + { + foreach (var task in priority.Value) + { + Console.WriteLine($"({task.Description}, Priority {task.Priority})"); + } + } + } + + private void SaveTasksToFile() + { + using (StreamWriter writer = new StreamWriter("tasks.txt")) + { + foreach (var task in tasks.Values) + { + writer.WriteLine($"{task.Description},{task.Priority}"); + } + } + } + + private void LoadTasksFromFile() + { + if (File.Exists("tasks.txt")) + { + foreach (var line in File.ReadLines("tasks.txt")) + { + var parts = line.Split(','); + var description = parts[0]; + var priority = int.Parse(parts[1]); + AddTask(description, priority); + } + } + } + + public void Menu() + { + LoadTasksFromFile(); // Load tasks from file on startup + + while (true) + { + Console.WriteLine("1. Add Task"); + Console.WriteLine("2. Remove Task"); + Console.WriteLine("3. Search Task"); + Console.WriteLine("4. Display Tasks"); + Console.WriteLine("5. Exit"); + Console.Write("Choose an option: "); + var choice = Console.ReadLine(); + + switch (choice) + { + case "1": + Console.Write("Enter Task Description: "); + string description = Console.ReadLine(); + Console.Write("Enter Task Priority: "); + int priority = int.Parse(Console.ReadLine()); + AddTask(description, priority); + break; + case "2": + Console.Write("Enter Task Description to Remove: "); + description = Console.ReadLine(); + RemoveTask(description); + break; + case "3": + Console.Write("Enter Task Description to Search: "); + description = Console.ReadLine(); + SearchTask(description); + break; + case "4": + DisplayTasks(); + break; + case "5": + return; + default: + Console.WriteLine("Invalid choice."); + break; + } + } + } + + private class TaskNode + { + public string Description { get; } + public int Priority { get; } + + public TaskNode(string description, int priority) + { + Description = description; + Priority = priority; + } + } + + public static void Main(string[] args) + { + var scheduler = new TaskScheduler(); + scheduler.Menu(); + } +} From 086abe944d174e0b27f7bf6bc8321eee9b8d5f7d Mon Sep 17 00:00:00 2001 From: Aswin Deivanayagam Subramanian <150608459+Ashprogrammer29@users.noreply.github.com> Date: Fri, 27 Dec 2024 22:26:38 +0530 Subject: [PATCH 32/37] Completed --- .../C#_Aswin_Deivanayagam_Subramanian_26.cs | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 December 26/C#_Aswin_Deivanayagam_Subramanian_26.cs diff --git a/December 26/C#_Aswin_Deivanayagam_Subramanian_26.cs b/December 26/C#_Aswin_Deivanayagam_Subramanian_26.cs new file mode 100644 index 0000000..91b4dc6 --- /dev/null +++ b/December 26/C#_Aswin_Deivanayagam_Subramanian_26.cs @@ -0,0 +1,32 @@ +using System; + +public class LavaFieldEscape +{ + public static bool CanJump(int[] nums) + { + int maxReach = 0; + int n = nums.Length; + + for (int i = 0; i < n; i++) + { + if (i > maxReach) + return false; + + maxReach = Math.Max(maxReach, i + nums[i]); + + if (maxReach >= n - 1) + return true; + } + + return false; + } + + public static void Main(string[] args) + { + int[] nums1 = { 2, 3, 1, 0, 4 }; + int[] nums2 = { 3, 2, 1, 0, 4 }; + + Console.WriteLine(CanJump(nums1)); // Output: True + Console.WriteLine(CanJump(nums2)); // Output: False + } +} From 2fb16d36184edc28fc1fafb1e9bdc5f666c652f9 Mon Sep 17 00:00:00 2001 From: Aswin Deivanayagam Subramanian <150608459+Ashprogrammer29@users.noreply.github.com> Date: Fri, 27 Dec 2024 22:27:06 +0530 Subject: [PATCH 33/37] Completed --- .../C#_Aswin_Deivanayagam_Subramanian_27.cs | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 December 27/C#_Aswin_Deivanayagam_Subramanian_27.cs diff --git a/December 27/C#_Aswin_Deivanayagam_Subramanian_27.cs b/December 27/C#_Aswin_Deivanayagam_Subramanian_27.cs new file mode 100644 index 0000000..9b07fd4 --- /dev/null +++ b/December 27/C#_Aswin_Deivanayagam_Subramanian_27.cs @@ -0,0 +1,53 @@ +using System; + +public class TrappingRainWater +{ + public static int Trap(int[] height) + { + int n = height.Length; + if (n == 0) return 0; + + int leftMax = 0, rightMax = 0; + int left = 0, right = n - 1; + int waterTrapped = 0; + + while (left < right) + { + if (height[left] < height[right]) + { + if (height[left] >= leftMax) + { + leftMax = height[left]; + } + else + { + waterTrapped += leftMax - height[left]; + } + left++; + } + else + { + if (height[right] >= rightMax) + { + rightMax = height[right]; + } + else + { + waterTrapped += rightMax - height[right]; + } + right--; + } + } + + return waterTrapped; + } + + public static void Main(string[] args) + { + int[] height1 = { 0, 1, 0, 2, 1, 0, 1, 3, 2, 1, 2, 1 }; + int[] height2 = { 4, 2, 0, 3, 2, 5 }; + + Console.WriteLine(Trap(height1)); // Output: 6 + Console.WriteLine(Trap(height2)); // Output: 9 + } +} From ddbaa7b3b69de8991a2d51c4d623c8376f1526f1 Mon Sep 17 00:00:00 2001 From: Aswin Deivanayagam Subramanian <150608459+Ashprogrammer29@users.noreply.github.com> Date: Fri, 27 Dec 2024 22:27:37 +0530 Subject: [PATCH 34/37] Completed --- .../C#_Aswin_Deivanayagam_Subramanian_28.cs | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 December 28/C#_Aswin_Deivanayagam_Subramanian_28.cs diff --git a/December 28/C#_Aswin_Deivanayagam_Subramanian_28.cs b/December 28/C#_Aswin_Deivanayagam_Subramanian_28.cs new file mode 100644 index 0000000..805de2f --- /dev/null +++ b/December 28/C#_Aswin_Deivanayagam_Subramanian_28.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; + +public class BookshelfOrganizer +{ + public static bool CanOrganizeBooks(int[] books, int shelfSize) + { + if (books.Length % shelfSize != 0) + return false; + + Dictionary bookCount = new Dictionary(); + + foreach (var book in books) + { + if (bookCount.ContainsKey(book)) + bookCount[book]++; + else + bookCount[book] = 1; + } + + foreach (var book in bookCount.Keys) + { + if (bookCount[book] % shelfSize != 0) + return false; + } + + return true; + } + + public static void Main(string[] args) + { + int[] books1 = { 1, 2, 3, 6, 2, 3, 4, 7, 8 }; + int shelfSize1 = 3; + int[] books2 = { 1, 2, 3, 4, 5 }; + int shelfSize2 = 4; + + Console.WriteLine(CanOrganizeBooks(books1, shelfSize1)); // Output: True + Console.WriteLine(CanOrganizeBooks(books2, shelfSize2)); // Output: False + } +} From 8f25040a59f6a728ec8ce889b7c778914922cc46 Mon Sep 17 00:00:00 2001 From: Aswin Deivanayagam Subramanian <150608459+Ashprogrammer29@users.noreply.github.com> Date: Sat, 28 Dec 2024 22:52:03 +0530 Subject: [PATCH 35/37] Completed --- .../C#_Aswin_Deivanayagam_Subramanian_29.cs | 87 +++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 December 29/C#_Aswin_Deivanayagam_Subramanian_29.cs diff --git a/December 29/C#_Aswin_Deivanayagam_Subramanian_29.cs b/December 29/C#_Aswin_Deivanayagam_Subramanian_29.cs new file mode 100644 index 0000000..230deb7 --- /dev/null +++ b/December 29/C#_Aswin_Deivanayagam_Subramanian_29.cs @@ -0,0 +1,87 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +class Program +{ + static int MinWeightToExit(int N, int M, int P, List<(int, int, int, int, int)> portals) + { + var graph = new Dictionary<(int, int), List<((int, int), int)>>(); + + foreach (var portal in portals) + { + var (x1, y1, x2, y2, W) = portal; + if (!graph.ContainsKey((x1, y1))) + graph[(x1, y1)] = new List<((int, int), int)>(); + if (!graph.ContainsKey((x2, y2))) + graph[(x2, y2)] = new List<((int, int), int)>(); + + graph[(x1, y1)].Add(((x2, y2), W)); + graph[(x2, y2)].Add(((x1, y1), W)); + } + + var pq = new SortedSet<(int Weight, int X, int Y)>(Comparer<(int Weight, int X, int Y)>.Create((a, b) => + { + if (a.Weight != b.Weight) return a.Weight.CompareTo(b.Weight); + if (a.X != b.X) return a.X.CompareTo(b.X); + return a.Y.CompareTo(b.Y); + })); + + pq.Add((0, 1, 1)); + var visited = new HashSet<(int, int)>(); + + while (pq.Count > 0) + { + var current = pq.Min; + pq.Remove(current); + + var (currWeight, x, y) = current; + if (visited.Contains((x, y))) + continue; + + visited.Add((x, y)); + + if ((x, y) == (N, M)) + return currWeight; + + foreach (var (dx, dy) in new[] { (-1, 0), (1, 0), (0, -1), (0, 1) }) + { + int nx = x + dx, ny = y + dy; + if (nx >= 1 && nx <= N && ny >= 1 && ny <= M && !visited.Contains((nx, ny))) + { + pq.Add((currWeight, nx, ny)); + } + } + + if (graph.ContainsKey((x, y))) + { + foreach (var ((nx, ny), w) in graph[(x, y)]) + { + if (!visited.Contains((nx, ny))) + { + pq.Add((currWeight + w, nx, ny)); + } + } + } + } + + return -1; + } + + static void Main(string[] args) + { + var input = Console.ReadLine().Split(); + int N = int.Parse(input[0]); + int M = int.Parse(input[1]); + int P = int.Parse(Console.ReadLine()); + var portals = new List<(int, int, int, int, int)>(); + + for (int i = 0; i < P; i++) + { + var portalInput = Console.ReadLine().Split().Select(int.Parse).ToArray(); + portals.Add((portalInput[0], portalInput[1], portalInput[2], portalInput[3], portalInput[4])); + } + + Console.WriteLine(MinWeightToExit(N, M, P, portals)); + } +} From e3a02b8c736d3d5b6be2325046380602ea260966 Mon Sep 17 00:00:00 2001 From: Aswin Deivanayagam Subramanian <150608459+Ashprogrammer29@users.noreply.github.com> Date: Wed, 1 Jan 2025 23:30:07 +0530 Subject: [PATCH 36/37] Completed --- .../C#_Aswin_Deivanayagam_Subramanian_30.cs | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 December 30/C#_Aswin_Deivanayagam_Subramanian_30.cs diff --git a/December 30/C#_Aswin_Deivanayagam_Subramanian_30.cs b/December 30/C#_Aswin_Deivanayagam_Subramanian_30.cs new file mode 100644 index 0000000..21b73b4 --- /dev/null +++ b/December 30/C#_Aswin_Deivanayagam_Subramanian_30.cs @@ -0,0 +1,29 @@ +using System; + +class Program +{ + public static int SuperEggDrop(int k, int n) + { + int[,] dp = new int[k + 1, n + 1]; + + for (int moves = 1; moves <= n; moves++) + { + for (int eggs = 1; eggs <= k; eggs++) + { + dp[eggs, moves] = dp[eggs - 1, moves - 1] + dp[eggs, moves - 1] + 1; + if (dp[eggs, moves] >= n) + { + return moves; + } + } + } + + return 0; + } + + static void Main() + { + Console.WriteLine(SuperEggDrop(2, 6)); // Output: 3 + Console.WriteLine(SuperEggDrop(3, 14)); // Output: 4 + } +} From 38bcb80fe3f41caded8a561898158c07ef584922 Mon Sep 17 00:00:00 2001 From: Aswin Deivanayagam Subramanian <150608459+Ashprogrammer29@users.noreply.github.com> Date: Wed, 1 Jan 2025 23:31:06 +0530 Subject: [PATCH 37/37] Completed --- .../C#_Aswin_Deivanayagam_Subramanian_31.cs | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 December 31/C#_Aswin_Deivanayagam_Subramanian_31.cs diff --git a/December 31/C#_Aswin_Deivanayagam_Subramanian_31.cs b/December 31/C#_Aswin_Deivanayagam_Subramanian_31.cs new file mode 100644 index 0000000..c63382c --- /dev/null +++ b/December 31/C#_Aswin_Deivanayagam_Subramanian_31.cs @@ -0,0 +1,45 @@ +using System; + +class Program +{ + public static float FastInverseSqrt(float x) + { + float threeHalfs = 1.5f; + float x2 = x * 0.5f; + int i = BitConverter.ToInt32(BitConverter.GetBytes(x), 0); + i = 0x5f3759df - (i >> 1); + float y = BitConverter.ToSingle(BitConverter.GetBytes(i), 0); + y = y * (threeHalfs - (x2 * y * y)); + return y; + } + + public static (float, float, float)[] NormalizeVectors((float, float, float)[] vectors) + { + (float, float, float)[] result = new (float, float, float)[vectors.Length]; + for (int i = 0; i < vectors.Length; i++) + { + var vec = vectors[i]; + float x = vec.Item1, y = vec.Item2, z = vec.Item3; + float magnitudeSquared = x * x + y * y + z * z; + float invMagnitude = FastInverseSqrt(magnitudeSquared); + result[i] = (x * invMagnitude, y * invMagnitude, z * invMagnitude); + } + return result; + } + + static void Main() + { + var vectors = new (float, float, float)[] + { + (3, 4, 0), + (-6, 8, 0), + (5, 12, 0) + }; + + var normalizedVectors = NormalizeVectors(vectors); + foreach (var vec in normalizedVectors) + { + Console.WriteLine($"{vec.Item1:F6} {vec.Item2:F6} {vec.Item3:F6}"); + } + } +}