Wednesday, June 12, 2024

 This is a continuation of articles on IaC shortcomings and resolutions. As a recap of several articles, this section brings to light what has worked and what hasn’t across a diverse and complex set of deployments. 

1. Cloud is our friend in its ability to provide management free, elastic, performant and highly available resources that can be reached from around the world. Transition from on-premises while requiring migration and modernization concerns are not insurmountable and the final state as cloud native deployments is very appealing in the long run.

2. Resources transition from preview to general acceptance as various cloud services become more mainstream. Since they are developed and made generally available independent of each other, many mature and lower the users concerns in their usage. Leveraging these built-in features over customizations holds us in good stead as it is maintenance free.

3. Anything managed is good including networks, storage and compute if the resource or set of resources to be deployed give that option. Taking the example of an Azure Machine Learning Workspace over an Azure Databricks instance, storage accounts, key vaults, managed virtual network are tightly integrated with the managed option and eschews rediscovery by hands-on configuration.

4. Complex deployments have a significant number of configuration parameters that can quickly get out of hand and require a large test matrix. Capturing them in Infrastructure-as-code with source control is helpful to both repeatable deployments as well as curating best practices.

5. The final state of the resources on their deployment must meet all the criteria so instead of working through the order of various steps and getting lost in the choices, it is better to work backwards from the final state once that has gained deliberation and buy-ins from stakeholders.

6. Zonal redundancy and regional disaster recovery are aspects that must be considered as early as design and implementation. They are not an afterthought and must be judiciously chosen to conserver resources and costs without detriment to the business continuity

7. Most workspaces and resources with public ip connectivity grow feet in the form of private endpoints to gain private plane connectivity through virtual networks so that the connectivity and traffic are secured and there is less attack surface from the ubiquitous internet. Designating subnets for providing addresses to private endpoints from various resources is good practice. Only when private connectivity interferes with usage of resources via workspace notebooks or management views and requires jump hosts or Bastions, then both public and private connectivity might be required. For public connectivity alone, simple firewall rules to enumerate the source and destinations can thwart many attacks that might require otherwise have required costly setup like Defender

8. Cost is always a concern as they have a tendency to balloon with usage and keeping them nanageable requires attention to features that are used and those that aren’t and the process must be repeated at setup as well as an ongoing basis.

9. Just like built-in features, most resources come with diagnostics, troubleshooting and documentation as well as support, so leveraging them avoids lengthy investigations.

10. Naming convention is important to capture the variations possible to resources and do very weill with prefixes and suffixes that have well-known meanings.  Previous articles: https://1drv.ms/w/s!Ashlm-Nw-wnWhO8w-_97Fxz2IyBZog?e=R3wwt0 

Tuesday, June 11, 2024

 This is the summary of the book titled “Connectable” written by Steven Van Cohen and Ryan Jenkins and published by McGraw Hill in 2022.  The authors are speakers and consultants with their website lesslonely.com who talk about tech induced loneliness for individuals and teams in the workplace. Isolation’s negative consequences while poignant can be overcome by adjustments to daily behavior and human connection. The impact of loneliness goes beyond the workplace to include society’s foundation and technology with its priority for convenience over connection, has exacerbated it. Kindness is the perfect antidote for loneliness and it can be done in small measures to begin with.

Loneliness is a growing issue in the workforce, affecting employee productivity, loyalty, collaboration, and engagement. Loneliness reduces life expectancy by 15 years, with 70% of workers experiencing loneliness monthly and 55% weekly. Technology, such as ATMs and self-checkouts, often prioritizes convenience over connection, leading to a decline in social interaction. Researchers classify loneliness into three dimensions: intimate, relational, and collective. Intimate loneliness is characterized by the absence of significant support, while relational loneliness is characterized by the absence of friendships and family relationships. Collective loneliness is characterized by the lack of connection to a community or social network, with men playing a slightly larger role. Technology is not inherently evil, but it can be a tool for promoting loneliness and reducing social interaction.

Loneliness significantly impacts people's physical and mental health, increasing the chances of dying young by 45%. Around 60% of American adults report being lonely, up 7% since 2018. Gen Z, the younger generation, suffers the most from loneliness, with nearly 70% feeling significantly stressed about the future. Employers must prioritize psychological wellness and address crippling loneliness. Gen Z prefers face-to-face communication at work, and even brief interactions with others can reduce loneliness and create a greater sense of happiness.


Loneliness has doubled since the 1980s, and COVID-19 has exacerbated this trend. Surveys show that three times as many Americans have no close friends than in 1985. Loneliness spreads through social networks, and loneliness can manifest at work when a lonely colleague becomes more withdrawn and less approachable.


Kindness is the ideal remedy for loneliness, as it is contagious and can make an impression on others. Examples of kindness include Aaron Le Conte's free hugs in London, which have led to glowing smiles from onlookers.

Loneliness is a common issue that has emerged in recent years, with new causes such as being busy, technologically sabotaging, and relying on technology. People today face more distractions than in previous eras, with people rushing to meetings and appointments, sacrificing face-to-face interactions, and relying too much on social media. The rise of Google has also impacted human connections, as people can find helpful and convenient resources online, but it can chip away at human connections. People today are more impatient, prioritizing speedy transactions, which weakens social bonds. The growing remote work phenomenon, fueled by mobile technology and COVID-19, has led to a preference for working at home for a day per week. The no-stopping lane of work has also become more prevalent, with people constantly checking emails and texting at all hours. Leaders can address disconnection by understanding its components and addressing the challenges it presents.

The modern work environment has led to a lack of time for social connections and human interaction, resulting in feelings of loneliness and disconnection among employees. The "Less Loneliness Framework" suggests that leaders can address loneliness by making subtle adjustments that reinforce or reestablish the team's well-being. The framework has four steps: "Look at loneliness," "Invest in connection," "Narrow the focus," and "Kindle the momentum."


Loneliness is a natural part of human nature, and leaders can make adjustments to improve their connection with their team. By slowing down, recognizing signs of loneliness, investing in connection, narrowing the focus, and ensuring shared meaning among team members, leaders can create a more supportive and productive work environment. By implementing these strategies, leaders can help their employees feel better and boost their organization's overall quality.

Previous book summaries: https://1drv.ms/w/s!Ashlm-Nw-wnWhO84QQt9vMkqdWZL_w?e=gdStFw

Summarizing Software: SummarizerCodeSnippets.docx  



Monday, June 10, 2024

 Problem Statement: Given an integer array arr, in one move you can select a palindromic subsequence arr[i], ..., arr[j] where 0 <= i <= j < arr.length, and remove that subsequence from the given array. Note that after removing a subarray, the elements move to remove the gap between them.

 

Return the minimum number of moves needed to remove all numbers from the array.

 

Solution:

import java.util.*;

class Solution {

    public int minimumMoves(int[] arr) {

        int N = arr.length;

        int max = 1;

        int min = Integer.MAX_VALUE;

        List<Integer> A = new ArrayList<>();

        for (int i = 0; i < arr.length; i++) A.add(arr[i]);

        int count = 0;

        while(A.size() > 0) {

           boolean hasPalindrome = false; 

           List<Integer> elements = new ArrayList<>();

           for (int i = 0; i < (1<<N); i++) { 

               

               List<Integer> combination = new ArrayList<>(); 

                for (int j = 0; j < A.size(); j++) { 

                  if ((i & (1 << j)) > 0) { 

                    combination.add(j); 

                  } 

                } 

                if (isPalindrome(A, combination) && (combination.size() > max) && getCharactersToRemove(A, combination) < min) {

                      hasPalindrome = true;

                      max = combination.size();

                      min = getCharactersToRemove(A, combination);

                      elements = new ArrayList<>(combination);                

                      if (getCharactersToRemove(A, combination) == 0) { break;}

                } else {

                    // System.out.println("A: " + print(A) + " Elements: " + print(elements) + " Combination: " + print(combination) + "isPalindrome=" + String.valueOf(isPalindrome(A, combination)) + " getCharsToRemove=" + getCharactersToRemove(A, combination) + " min = " + min);

                }

           }            

           if (!hasPalindrome) {

               count += 1;

               A.remove(A.size() - 1);

           } else {

               count += getCharactersToRemove(A, elements) + 1;

               A = removeCharacters(A, elements);

               // System.out.println("Removing " + count + " characters at indices:" + print(elements) + " and remaining elements: " + print(A));

               // elements = new ArrayList<>();

               max = 1;

               min = Integer.MAX_VALUE;

           }

        }

        return count;

    }

    public boolean isPalindrome(List<Integer> A, List<Integer> combination) {

        int start = 0;

        int end = combination.size()-1;

        while (start <= end) {

            if (A.get(combination.get(start)) != A.get(combination.get(end))) {

                return false;

            }

            start++;

            end--;

        }

        return true;

    }

    public int getCharactersToRemove(List<Integer> A, List<Integer> combination){

        if (combination.size() < 2) return 0;

        List<Integer> clone = new ArrayList<>(A); 

        return removeCharacters(clone, combination).size();

    }

    public List<Integer> removeCharacters(List<Integer> A, List<Integer> combination) {

     int start = 0;

     int end = combinations.size()-1;

     int last = 0;

     while (start <= end) {

             for (int i = last; i< A.size(); i++) {

                    if (A.get(i) == combination.get(start)) {

                          A.set(I, Integer.MAX_VALUE);

                          last = i+1;

                          start++;

                    }

             }

     }

    List<Integer> result = new ArrayList<>();

    For (int I = 0; I < A.size(); i++) {

         if (A.get(i) != Integer.MAX_VALUE) {

               result.add(A.get(i));

          }

    }

    return result;

    }

    public List<Integer> removeCharacters(List<Integer> A, List<Integer> combination) {

        int start = combination.get(0);

        int end = combination.get(combination.size()-1);

        List<Integer> result = new ArrayList<>();

        if (start > 0){

            result.addAll(A.subList(0, start));

        }

        if (end < A.size() - 1) {

            result.addAll(A.subList(end + 1,A.size()));

        }

        return result;

    }

    public String print(List<Integer> elements){

        StringBuilder sb = new StringBuilder();

        for (int i = 0; i < elements.size(); i++) {

            sb.append(elements.get(i) + " ");

        }

        return sb.toString();

    }

}


Examples:

A = [-1,0,1]           => 3

A = [-1,0,-1]          => 1

A = [-1]                    => 1

A = [-1,0]                => 2

A = [0,0]                 => 1

A = [1,0,1,2,3]     => 3

A = [-2,-1,0,1,0]   => 3


Sunday, June 9, 2024

 Drone Formation Commercial Software:

This is an addendum to the discussion about Drone Formation Commercial Software as described in this document. In this section, we describe the infrastructure for various businesses operating on the software-as-a-service platform described in the document. Each business gets a deployment stamp that comprises of various resources in standard format that can be scaled or customized according to the size and requirements of the business but begin with a standard edition of set of resources. The SaaS offering comes with a high-availability architecture for the businesses by virtue of its performance, scalability and availability. This multi-instance architecture will meet and exceed stringent requirements surrounding data sovereignty, availability and performance. Each stamp comes with redundant components and multiple network paths to avoid single points of failure. The platform itself has a multi-homed network with multiple connections to the internet and comes with pairs of components that maintain continuous replication between replicas. These digital twins can withstand failures and support the combined production loads providing business continuity and disaster recovery. Operations can be transferred from one component of the stamp to another seamlessly. With these assurances, the business operations will never experience a downtime, and transfers will always be successful. A multi-tenant architecture for the platform ensures isolation for each business hosted on the infrastructure. Each business gets its own dashboard to monitor ongoing usage and for troubleshooting. Measurement and billing will make use of tags and labels for the underlying cloud resources. Wherever appropriate, deep monitoring will be involved to provide recommendations above and beyond those available from the public cloud.

Tens of billions of transactions can be expected to come from various drones of different tenants and the databases including the provisioned configuration management database will handle that load. A follow-the-sun model provides continual security, operational monitoring and support of various resources. Traditional data backup and recovery will be supported so that inadvertent deletes can be mitigated with restoration. Full and deferential backups will augment the aging and tiering best practices of the data management. Failovers will not only be planned but also routinely performed or tested. The current passive system is designated as active during the failover and mapping and name resolutions will automatically work out.

Most customers will appreciate the importance of querying abilities provided with this platform from its read-only stack that will serve the position, location and health information of drones in near real-time basis. The querying language will seamlessly integrate with the resource graph queries available on the public cloud for enhanced visibility into decision-making logic and cloud-resource consumption corresponding to a drone or a set of drones. The platform is uniquely positioned to offer both operational as well as management information on the drones for all the businesses.


Saturday, June 8, 2024

  Problem::

Make Array Zero by Subtracting Equal Amounts

You are given a non-negative integer array nums. In one operation, you must:

Choose a positive integer x such that x is less than or equal to the smallest non-zero element in nums.

Subtract x from every positive element in nums.

Return the minimum number of operations to make every element in nums equal to 0.

 

Example 1:

Input: nums = [1,5,0,3,5]

Output: 3

Explanation:

In the first operation, choose x = 1. Now, nums = [0,4,0,2,4].

In the second operation, choose x = 2. Now, nums = [0,2,0,0,2].

In the third operation, choose x = 2. Now, nums = [0,0,0,0,0].

Example 2:

Input: nums = [0]

Output: 0

Explanation: Each element in nums is already 0 so no operations are needed.

 

Constraints:

1 <= nums.length <= 100

0 <= nums[i] <= 100


import java.util.*;

import java.util.stream.*;

class Solution {

    public int minimumOperations(int[] nums) {

        List<Integer> list = Arrays.stream(nums).boxed().collect(Collectors.toList());

        var nonZero = list.stream().filter(x -> x > 0).collect(Collectors.toList());

        int count = 0;

        while(nonZero.size() > 0) {

            var min = nonZero.stream().mapToInt(x -> x).min().getAsInt();

            nonZero = nonZero.stream().map(x -> x - min).filter(x -> x > 0).collect(Collectors.toList());

            count++;

        }

        return count;

    }

}


Input

nums =

[1,5,0,3,5]

Output

3

Expected

3


Input

nums =

[0]

Output

0

Expected

0


Friday, June 7, 2024

 Problem Statement: Given an integer array arr, in one move you can select a palindromic subsequence arr[i], ..., arr[j] where 0 <= i <= j < arr.length, and remove that subsequence from the given array. Note that after removing a subarray, the elements move to remove the gap between them.

 

Return the minimum number of moves needed to remove all numbers from the array.

 

Solution:

import java.util.*;

class Solution {

    public int minimumMoves(int[] arr) {

        int N = arr.length;

        int max = 1;

        int min = Integer.MAX_VALUE;

        List<Integer> A = new ArrayList<>();

        for (int i = 0; i < arr.length; i++) A.add(arr[i]);

        int count = 0;

        while(A.size() > 0) {

           boolean hasPalindrome = false; 

           List<Integer> elements = new ArrayList<>();

           for (int i = 0; i < (1<<N); i++) { 

               

               List<Integer> combination = new ArrayList<>(); 

                for (int j = 0; j < A.size(); j++) { 

                  if ((i & (1 << j)) > 0) { 

                    combination.add(j); 

                  } 

                } 

                if (isPalindrome(A, combination) && (combination.size() > max) && getCharactersToRemove(A, combination) < min) {

                      hasPalindrome = true;

                      max = combination.size();

                      min = getCharactersToRemove(A, combination);

                      elements = new ArrayList<>(combination);                

                      if (getCharactersToRemove(A, combination) == 0) { break;}

                } else {

                    // System.out.println("A: " + print(A) + " Elements: " + print(elements) + " Combination: " + print(combination) + "isPalindrome=" + String.valueOf(isPalindrome(A, combination)) + " getCharsToRemove=" + getCharactersToRemove(A, combination) + " min = " + min);

                }

           }            

           if (!hasPalindrome) {

               count += 1;

               A.remove(A.size() - 1);

           } else {

               count += getCharactersToRemove(A, elements) + 1;

               A = removeCharacters(A, elements);

               // System.out.println("Removing " + count + " characters at indices:" + print(elements) + " and remaining elements: " + print(A));

               // elements = new ArrayList<>();

               max = 1;

               min = Integer.MAX_VALUE;

           }

        }

        return count;

    }

    public boolean isPalindrome(List<Integer> A, List<Integer> combination) {

        int start = 0;

        int end = combination.size()-1;

        while (start <= end) {

            if (A.get(combination.get(start)) != A.get(combination.get(end))) {

                return false;

            }

            start++;

            end--;

        }

        return true;

    }

    public int getCharactersToRemove(List<Integer> A, List<Integer> combination){

        if (combination.size() < 2) return 0;

        List<Integer> clone = new ArrayList<>(A); 

        return removeCharacters(clone, combination).size();

    }

    public List<Integer> removeCharacters(List<Integer> A, List<Integer> combination) {

     int start = 0;

     int end = combinations.size()-1;

     int last = 0;

     while (start <= end) {

             for (int i = last; i< A.size(); i++) {

                    if (A.get(i) == combination.get(start)) {

                          A.set(I, Integer.MAX_VALUE);

                          last = i+1;

                          start++;

                    }

             }

     }

    List<Integer> result = new ArrayList<>();

    For (int I = 0; I < A.size(); i++) {

         if (A.get(i) != Integer.MAX_VALUE) {

               result.add(A.get(i));

          }

    }

    return result;

    }

    public List<Integer> removeCharacters(List<Integer> A, List<Integer> combination) {

        int start = combination.get(0);

        int end = combination.get(combination.size()-1);

        List<Integer> result = new ArrayList<>();

        if (start > 0){

            result.addAll(A.subList(0, start));

        }

        if (end < A.size() - 1) {

            result.addAll(A.subList(end + 1,A.size()));

        }

        return result;

    }

    public String print(List<Integer> elements){

        StringBuilder sb = new StringBuilder();

        for (int i = 0; i < elements.size(); i++) {

            sb.append(elements.get(i) + " ");

        }

        return sb.toString();

    }

}


Examples:

A = [-1,0,1]           => 3

A = [-1,0,-1]          => 1

A = [-1]                    => 1

A = [-1,0]                => 2

A = [0,0]                 => 1

A = [1,0,1,2,3]     => 3

A = [-2,-1,0,1,0]   => 3


Thursday, June 6, 2024

 


Problem::

Make Array Zero by Subtracting Equal Amounts

You are given a non-negative integer array nums. In one operation, you must:

Choose a positive integer x such that x is less than or equal to the smallest non-zero element in nums.

Subtract x from every positive element in nums.

Return the minimum number of operations to make every element in nums equal to 0.

 

Example 1:

Input: nums = [1,5,0,3,5]

Output: 3

Explanation:

In the first operation, choose x = 1. Now, nums = [0,4,0,2,4].

In the second operation, choose x = 2. Now, nums = [0,2,0,0,2].

In the third operation, choose x = 2. Now, nums = [0,0,0,0,0].

Example 2:

Input: nums = [0]

Output: 0

Explanation: Each element in nums is already 0 so no operations are needed.

 

Constraints:

1 <= nums.length <= 100

0 <= nums[i] <= 100


import java.util.*;

import java.util.stream.*;

class Solution {

    public int minimumOperations(int[] nums) {

        List<Integer> list = Arrays.stream(nums).boxed().collect(Collectors.toList());

        var nonZero = list.stream().filter(x -> x > 0).collect(Collectors.toList());

        int count = 0;

        while(nonZero.size() > 0) {

            var min = nonZero.stream().mapToInt(x -> x).min().getAsInt();

            nonZero = nonZero.stream().map(x -> x - min).filter(x -> x > 0).collect(Collectors.toList());

            count++;

        }

        return count;

    }

}


Input

nums =

[1,5,0,3,5]

Output

3

Expected

3


Input

nums =

[0]

Output

0

Expected

0




SQL Schema

 

Table: Books

+----------------+---------+

| Column Name    | Type    |

+----------------+---------+

| book_id        | int     |

| name           | varchar |

| available_from | date    |

+----------------+---------+

book_id is the primary key of this table.

 

Table: Orders

+----------------+---------+

| Column Name    | Type    |

+----------------+---------+

| order_id       | int     |

| book_id        | int     |

| quantity       | int     |

| dispatch_date  | date    |

+----------------+---------+

order_id is the primary key of this table.

book_id is a foreign key to the Books table.

 

Write an SQL query that reports the books that have sold less than 10 copies in the last year, excluding books that have been available for less than one month from today. Assume today is 2019-06-23.

Return the result table in any order.

The query result format is in the following example.

 

Example 1:

Input: 

Books table:

+---------+--------------------+----------------+

| book_id | name               | available_from |

+---------+--------------------+----------------+

| 1       | "Kalila And Demna" | 2010-01-01     |

| 2       | "28 Letters"       | 2012-05-12     |

| 3       | "The Hobbit"       | 2019-06-10     |

| 4       | "13 Reasons Why"   | 2019-06-01     |

| 5       | "The Hunger Games" | 2008-09-21     |

+---------+--------------------+----------------+

Orders table:

+----------+---------+----------+---------------+

| order_id | book_id | quantity | dispatch_date |

+----------+---------+----------+---------------+

| 1        | 1       | 2        | 2018-07-26    |

| 2        | 1       | 1        | 2018-11-05    |

| 3        | 3       | 8        | 2019-06-11    |

| 4        | 4       | 6        | 2019-06-05    |

| 5        | 4       | 5        | 2019-06-20    |

| 6        | 5       | 9        | 2009-02-02    |

| 7        | 5       | 8        | 2010-04-13    |

+----------+---------+----------+---------------+

Output: 

+-----------+--------------------+

| book_id   | name               |

+-----------+--------------------+

| 1         | "Kalila And Demna" |

| 2         | "28 Letters"       |

| 5         | "The Hunger Games" |

+-----------+--------------------+



SELECT DISTINCT b.book_id, b.name

FROM books b 

LEFT JOIN Orders o on b.book_id = o.book_id

GROUP BY b.book_id, b.name, 

DATEDIFF(day, DATEADD(year, -1, '2019-06-23'), o.dispatch_date),  

DATEDIFF(day,  b.available_from, DATEADD(month, -1, '2019-06-23')) 

HAVING SUM(o.quantity) IS NULL OR 

DATEDIFF(day, DATEADD(year, -1, '2019-06-23'), o.dispatch_date) < 0 OR 

(DATEDIFF(day, DATEADD(year, -1, '2019-06-23'), o.dispatch_date) > 0 AND DATEDIFF(day,  b.available_from, DATEADD(month, -1, '2019-06-23')) > 0 AND SUM(o.quantity) < 10);



Case 1

Input

Books =

| book_id | name | available_from |

| ------- | ---------------- | -------------- |

| 1 | Kalila And Demna | 2010-01-01 |

| 2 | 28 Letters | 2012-05-12 |

| 3 | The Hobbit | 2019-06-10 |

| 4 | 13 Reasons Why | 2019-06-01 |

| 5 | The Hunger Games | 2008-09-21 |

Orders =

| order_id | book_id | quantity | dispatch_date |

| -------- | ------- | -------- | ------------- |

| 1 | 1 | 2 | 2018-07-26 |

| 2 | 1 | 1 | 2018-11-05 |

| 3 | 3 | 8 | 2019-06-11 |

| 4 | 4 | 6 | 2019-06-05 |

| 5 | 4 | 5 | 2019-06-20 |

| 6 | 5 | 9 | 2009-02-02 |

| 7 | 5 | 8 | 2010-04-13 |

Output

| book_id | name |

| ------- | ---------------- |

| 2 | 28 Letters |

| 1 | Kalila And Demna |

| 5 | The Hunger Games |

Expected

| book_id | name |

| ------- | ---------------- |

| 1 | Kalila And Demna |

| 2 | 28 Letters |

| 5 | The Hunger Games |