static void Main(string[] args) { // Fixed Window Size // https://www.educative.io/courses/grokking-the-coding-interview/7D5NNZWQ8Wr Console.WriteLine("Given an array, find the average of all contiguous subarrays of size ‘K’ in it."); AverageOfContiguousSubarray avg = new AverageOfContiguousSubarray(); avg.AverageOfSubarrayOfSizeK(5, new int[] { 1, 3, 2, 6, -1, 4, 1, 8, 2 }); // https://www.educative.io/courses/grokking-the-coding-interview/JPKr0kqLGNP Console.WriteLine("Given an array of positive numbers and a positive number ‘k’, find the maximum sum of any contiguous subarray of size ‘k’."); MaxSumOfContiguousSubArray maxSum = new MaxSumOfContiguousSubArray(); Console.Write(maxSum.MaxSumOfSubArrayOfSizeK(3, new int[] { 2, 1, 5, 1, 3, 2 })); // https://leetcode.com/problems/maximum-average-subarray-i/ Console.WriteLine("Given an array consisting of n integers, find the contiguous subarray of given length k that has the maximum average value. And you need to output the maximum average value."); MaxAverage maxAvg = new MaxAverage(); maxAvg.FindMaxAverage(new int[] { 1, 12, -5, -6, 50, 3 }, 4); // Window size is not fixed // https://www.educative.io/courses/grokking-the-coding-interview/7XMlMEQPnnQ // https://leetcode.com/problems/minimum-size-subarray-sum/ Console.WriteLine("Given an array of positive numbers and a positive number ‘S’, find the length of the smallest contiguous subarray whose sum is greater than or equal to" + " ‘S’. Return 0, if no such subarray exists."); SmallestSubArray sm = new SmallestSubArray(); Console.Write(sm.MinSizeSubArray(7, new int[] { 2, 1, 5, 2, 3, 2 })); // https://www.educative.io/courses/grokking-the-coding-interview/YQQwQMWLx80 Console.WriteLine("Given a string, find the length of the longest substring in it with no more than K distinct characters."); LongestSubstringK ls = new LongestSubstringK(); // https://leetcode.com/problems/longest-substring-without-repeating-characters/ Console.WriteLine("Given a string, find the length of the longest substring in it with no more than K distinct characters."); LongestSubstring sub = new LongestSubstring(); Console.Write(sub.LengthOfLongestSubstring("abcabcbb")); // https://leetcode.com/problems/fruit-into-baskets/ // Substring with K distinct, K here is 2 Console.WriteLine("Fruits into baskets"); FruitsIntoBaskets fruits = new FruitsIntoBaskets(); Console.Write(fruits.TotalFruit(new int[] { 1, 2, 1 })); Anagrams an = new Anagrams(); string[] strs = new string[] { "eat", "tea", "tan", "ate", "nat", "bat" }; an.GroupAnagrams(strs); }
static void Main(string[] args) { Console.WriteLine("Hello World!"); var brute = AverageOfSubarrayOfSizeK.FindAveragesBruteForce(5, new int[] { 1, 3, 2, 6, -1, 4, 1, 8, 2 }); foreach (var number in brute) { Console.Write($"{number} "); } Console.WriteLine(); var window = AverageOfSubarrayOfSizeK.FindAveragesBruteForce(5, new int[] { 1, 3, 2, 6, -1, 4, 1, 8, 2 }); foreach (var number in window) { Console.Write($"{number} "); } Console.WriteLine(); var windowSum = SmallestSubarray.SmallestSubarrayGreaterThanS(8, new int[] { 3, 4, 1, 1, 6 }); Console.Write($"WindowSum: {windowSum}"); Console.WriteLine(); var distinct = LongestSubstring.LongestSubstringWithNoMoreThanKDistinctChars("cbbbebi", 1); Console.WriteLine($"Longest Substring: {distinct}"); Console.WriteLine(); var fruits = FruitTree.MaxNoOfFruits(new char[] { 'A', 'B', 'C', 'B', 'B', 'C' }); Console.WriteLine($"Fruits: {fruits}"); Console.WriteLine(); var maxNoRepeats = NoRepeatChars.NoRepeatCharsInASubstring("abccde"); Console.WriteLine($"Max No Repeats: {maxNoRepeats}"); Console.WriteLine(); var longestSubstring = ReplaceToFindLongest.ReplaceKCharsToFindLongestSubString("aabccbb", 2); Console.WriteLine($"Replace to find longest: {longestSubstring}"); Console.WriteLine(); var replaceBits = BitArrayReplace.ReplaceK1sInBitArray(new List <int>() { 0, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0, 1, 1 }, 3); Console.WriteLine($"Longest Replaced 0s: {replaceBits}"); Console.WriteLine(); var isPermutation = ContainsPermuations.DoesContainPermutation("oidbcaf", "abc"); Console.WriteLine($"Is Permutation: {isPermutation}"); Console.WriteLine(); var isEducativePermutation = ContainsPermuations.EducativeVersion("oidbcaf", "abc"); Console.WriteLine($"Is Permutation: {isEducativePermutation}"); Console.WriteLine(); List <List <int> > sixBySixList = new List <List <int> >() { new List <int>() { 1, 1, 1, 0, 0, 0 }, new List <int>() { 0, 1, 0, 0, 0, 0 }, new List <int>() { 1, 1, 1, 0, 0, 0 }, new List <int>() { 0, 9, 2, -4, -4, 0 }, new List <int>() { 0, 0, 0, -2, 0, 0 }, new List <int>() { 0, 0, -1, -2, -4, 0 }, }; var largestHourGlass = HourGlass.HourglassSum(sixBySixList); Console.WriteLine($"Hour Glass Max: {largestHourGlass}"); Console.WriteLine(); }