We were discussing System Center Managers such as from AWS. It's a cloud service that helps you automatically collect software inventory, apply OS patches, create system images, and configure windows and Linux operating systems. It enables to seamlessly bridge the existing infrastructure with AWS. In other words, it can help manage both EC2 and on-premise resources. It works with the help of an agent installed on each of the computing resource and an iam role with system manager permissions that give it visibility in the AWS EC2 console. Even on premise instances now appear in the EC2 console with the 'mi-' prefix. This is a huge win for private cloud providers because they no longer need legacy, custom or proprietary server management software.
We were looking at remote administration techniques and saw an example by specifying the RunCommand.
A specific advantage of using AWS System manager is Inventory Management. It collects metadata from all EC2 instances, on-premise servers and virtual machines giving a holistic view of all instances from outside in. And since the metadata includes OS and application data, we can gather which instances are running the software configurations required by the software policy of the organization We can even update the SSM agent using the Amazon EC2 RunCommand.
Thus it provides a consistent and secure way to remotely manage on-premises and cloud workloads
It centralizes access control for actions that can be performed on the servers and VMs using AWS Identity and access management.
It centralizes auditing and viewing because it records events with CloudTrail.
By the same token, it helps with centralized monitoring because we can configure CloudWatch Events with Amazon SNS for notifications.
Find the smallest substring length in a string that has all the characters from another string
Solution:
build a frequency table of the second string.
scan the first string for the first occurrence of a match in the frequency table. this is the start of the window.
increase the window size until all characters in the frequency table are accounted for and note the length.
if the first character of the window is encountered more than its count, move the window start to the next match and update the minimum length of the window found so far. proceed till the end of the string and return the minimum found. This
is based on the idea that the minimum window containing the second substring is contiguous in the original string and each match is the potential start of a new run.
static int GetMinSubStringLen(String A, String pattern)
{
if (String.IsNullOrEmpty(A) || String.IsNullOrEmpty(pattern)) return int.MaxValue;
var hash = new Dictionary<char, int>();
var current = new Dictionary<char, int>();
for (int i = 0; i < pattern.Length; i++)
{
if (hash.ContainsKey(pattern[i]))
hash[pattern[i]]++;
else
hash.Add(pattern[i], 1);
if (current.ContainsKey(pattern[i]))
current[pattern[i]]++;
else
current.Add(pattern[i], 1);
}
int start = 0;
int end = -1;
int min = int.MaxValue;
if (current.Count == 0) return 0;
for (int i = 0; i < A.Length; i++)
{
if (hash.Keys.Contains(A[i]))
{
if (end < start)
{
start = i;
end = start;
}
if (start < i)
{
end = i;
if (A[start] == A[i])
{
if (end - start + 1 < min)
min = end - start + 1;
current[A[start]]++;
start++;
while (start <= i && hash.Keys.Contains(A[start]) == false)
start++;
}
}
current[A[i]]--;
if (current.Values.All(x => x == 0))
{
if (end - start + 1 < min)
min = end - start + 1;
}
}
}
return min;
}
Console.WriteLine("Expected=int.MaxValue, Actual={0}", GetMinSubStringLen("", ""));
Console.WriteLine("Expected=int.MaxValue, Actual={0}", GetMinSubStringLen("", "A"));
Console.WriteLine("Expected=int.MaxValue, Actual={0}", GetMinSubStringLen("A", ""));
Console.WriteLine("Expected=int.MaxValue, Actual={0}", GetMinSubStringLen(null, ""));
Console.WriteLine("Expected=int.MaxValue, Actual={0}", GetMinSubStringLen("", null));
Console.WriteLine("Expected=1, Actual={0}", GetMinSubStringLen("AA", "A"));
Console.WriteLine("Expected=1, Actual={0}", GetMinSubStringLen("AB", "A"));
Console.WriteLine("Expected=1, Actual={0}", GetMinSubStringLen("BA", "A"));
Console.WriteLine("Expected=1, Actual={0}", GetMinSubStringLen("BAB", "A"));
Console.WriteLine("Expected=1, Actual={0}", GetMinSubStringLen("BBA", "A"));
Console.WriteLine("Expected=1, Actual={0}", GetMinSubStringLen("ABB", "A"));
Console.WriteLine("Expected=2, Actual={0}", GetMinSubStringLen("AABAA", "AA"));
Console.WriteLine("Expected=2, Actual={0}", GetMinSubStringLen("ABAA", "AA"));
Console.WriteLine("Expected=2, Actual={0}", GetMinSubStringLen("AABA", "AA"));
Console.WriteLine("Expected=2, Actual={0}", GetMinSubStringLen("AABAA", "BA"));
Console.WriteLine("Expected=4, Actual={0}", GetMinSubStringLen("AABAAD", "BD"));
Console.WriteLine("Expected=3, Actual={0}", GetMinSubStringLen("AABCAD", "CD"));
Console.WriteLine("Expected=4, Actual={0}", GetMinSubStringLen("AZBACD", "ZC"));
//Expected=int.MaxValue, Actual=2147483647
//Expected=int.MaxValue, Actual=2147483647
//Expected=int.MaxValue, Actual=2147483647
//Expected=int.MaxValue, Actual=2147483647
//Expected=int.MaxValue, Actual=2147483647
//Expected=1, Actual=1
//Expected=1, Actual=1
//Expected=1, Actual=1
//Expected=1, Actual=1
//Expected=1, Actual=1
//Expected=1, Actual=1
//Expected=2, Actual=2
//Expected=2, Actual=2
//Expected=2, Actual=2
//Expected=2, Actual=2
//Expected=4, Actual=4
//Expected=3, Actual=3
//Expected=4, Actual=4
# the above code is O(N) time complexity
We were looking at remote administration techniques and saw an example by specifying the RunCommand.
A specific advantage of using AWS System manager is Inventory Management. It collects metadata from all EC2 instances, on-premise servers and virtual machines giving a holistic view of all instances from outside in. And since the metadata includes OS and application data, we can gather which instances are running the software configurations required by the software policy of the organization We can even update the SSM agent using the Amazon EC2 RunCommand.
Thus it provides a consistent and secure way to remotely manage on-premises and cloud workloads
It centralizes access control for actions that can be performed on the servers and VMs using AWS Identity and access management.
It centralizes auditing and viewing because it records events with CloudTrail.
By the same token, it helps with centralized monitoring because we can configure CloudWatch Events with Amazon SNS for notifications.
Find the smallest substring length in a string that has all the characters from another string
Solution:
build a frequency table of the second string.
scan the first string for the first occurrence of a match in the frequency table. this is the start of the window.
increase the window size until all characters in the frequency table are accounted for and note the length.
if the first character of the window is encountered more than its count, move the window start to the next match and update the minimum length of the window found so far. proceed till the end of the string and return the minimum found. This
is based on the idea that the minimum window containing the second substring is contiguous in the original string and each match is the potential start of a new run.
static int GetMinSubStringLen(String A, String pattern)
{
if (String.IsNullOrEmpty(A) || String.IsNullOrEmpty(pattern)) return int.MaxValue;
var hash = new Dictionary<char, int>();
var current = new Dictionary<char, int>();
for (int i = 0; i < pattern.Length; i++)
{
if (hash.ContainsKey(pattern[i]))
hash[pattern[i]]++;
else
hash.Add(pattern[i], 1);
if (current.ContainsKey(pattern[i]))
current[pattern[i]]++;
else
current.Add(pattern[i], 1);
}
int start = 0;
int end = -1;
int min = int.MaxValue;
if (current.Count == 0) return 0;
for (int i = 0; i < A.Length; i++)
{
if (hash.Keys.Contains(A[i]))
{
if (end < start)
{
start = i;
end = start;
}
if (start < i)
{
end = i;
if (A[start] == A[i])
{
if (end - start + 1 < min)
min = end - start + 1;
current[A[start]]++;
start++;
while (start <= i && hash.Keys.Contains(A[start]) == false)
start++;
}
}
current[A[i]]--;
if (current.Values.All(x => x == 0))
{
if (end - start + 1 < min)
min = end - start + 1;
}
}
}
return min;
}
Console.WriteLine("Expected=int.MaxValue, Actual={0}", GetMinSubStringLen("", ""));
Console.WriteLine("Expected=int.MaxValue, Actual={0}", GetMinSubStringLen("", "A"));
Console.WriteLine("Expected=int.MaxValue, Actual={0}", GetMinSubStringLen("A", ""));
Console.WriteLine("Expected=int.MaxValue, Actual={0}", GetMinSubStringLen(null, ""));
Console.WriteLine("Expected=int.MaxValue, Actual={0}", GetMinSubStringLen("", null));
Console.WriteLine("Expected=1, Actual={0}", GetMinSubStringLen("AA", "A"));
Console.WriteLine("Expected=1, Actual={0}", GetMinSubStringLen("AB", "A"));
Console.WriteLine("Expected=1, Actual={0}", GetMinSubStringLen("BA", "A"));
Console.WriteLine("Expected=1, Actual={0}", GetMinSubStringLen("BAB", "A"));
Console.WriteLine("Expected=1, Actual={0}", GetMinSubStringLen("BBA", "A"));
Console.WriteLine("Expected=1, Actual={0}", GetMinSubStringLen("ABB", "A"));
Console.WriteLine("Expected=2, Actual={0}", GetMinSubStringLen("AABAA", "AA"));
Console.WriteLine("Expected=2, Actual={0}", GetMinSubStringLen("ABAA", "AA"));
Console.WriteLine("Expected=2, Actual={0}", GetMinSubStringLen("AABA", "AA"));
Console.WriteLine("Expected=2, Actual={0}", GetMinSubStringLen("AABAA", "BA"));
Console.WriteLine("Expected=4, Actual={0}", GetMinSubStringLen("AABAAD", "BD"));
Console.WriteLine("Expected=3, Actual={0}", GetMinSubStringLen("AABCAD", "CD"));
Console.WriteLine("Expected=4, Actual={0}", GetMinSubStringLen("AZBACD", "ZC"));
//Expected=int.MaxValue, Actual=2147483647
//Expected=int.MaxValue, Actual=2147483647
//Expected=int.MaxValue, Actual=2147483647
//Expected=int.MaxValue, Actual=2147483647
//Expected=int.MaxValue, Actual=2147483647
//Expected=1, Actual=1
//Expected=1, Actual=1
//Expected=1, Actual=1
//Expected=1, Actual=1
//Expected=1, Actual=1
//Expected=1, Actual=1
//Expected=2, Actual=2
//Expected=2, Actual=2
//Expected=2, Actual=2
//Expected=2, Actual=2
//Expected=4, Actual=4
//Expected=3, Actual=3
//Expected=4, Actual=4
# the above code is O(N) time complexity
No comments:
Post a Comment