Monday, June 17, 2024

 This is a summary of the book “Never say whatever: How small decisions make a big difference?” written by Richard A. Moran and published by McGraw-Hill in 2023. The author hosts a CBS syndicated radio program and is a venture capitalist. He contends that indifference is a waste and often loses its essence and purpose. He calls this writing an “anti-whatever workbook” and advocates empathy saying that we must be social and not just need-based like creatures. Detachment has a high correlation with losing direction and caring while making intelligent choices makes us better and even minor decisions are vital. Among the highlights of the book, one can find wisdom such as starting early with even high school students who are rarely taught how to make decisions. Smart decision makers are self-aware and trust their guts. Saying whatever is not only self-damaging, but also damaging the workplace we are in. Entrepreneurs just cannot have a “whatever” attitude and people with such attitude aggravate everyone. Often indifferent people come to regret their careless attitude. Good advisors can help us make sound decisions. Our choices shape our future so we must be decisive.

"Whatever" is a common term used by Americans to express disengagement and dismissal, affecting not only the speaker but also others around them. This attitude is risk-averse and hinders decision-making, as decisions and actions make life meaningful. Intentional people understand that even minor decisions can be vital, and they make choices with forethought, intention, and purpose. Decision-making can be simplified by sticking with the status quo, making minor adjustments, or doing a complete about-face. Intentions always point the way to actions and results, and a clear intention leads to sound choices. For example, if you want to secure a raise or a promotion, you must ask for it, practice it, and establish a deliberative process that makes the most of your strengths. A "whatever" attitude does not ensure the same number of planes take off and land each day.

High school students often lack the skills to make intelligent decisions, which are crucial for making major choices such as college, career, and marriage. To teach students the basics of intelligent decision-making, schools should teach them the importance of "whatever" and frame options as "if/then" scenarios. A 10-year study by Bain & Company found that organizations that make timely, intelligent decisions outperform those that appear indecisive. The "two-minute rule" demonstrates the power of quick, effective decision-making when there are small choices, but the appropriate amount of time and consideration should be given to all major decisions. Smart decision-makers are self-aware and trust their guts, knowing their strengths and weaknesses and their emotions. They recognize the consequences of their decisions and actions and are willing to make "gut" decisions under the right circumstances. A "whatever" attitude can damage careers and organizations, as it can undermine a company's direction and undermine employees' sense of purpose.

Entrepreneurs must not have a "whatever" attitude to succeed, as they must be nonstop decision-makers who can make timely and cost-effective choices. They often use pattern recognition to clarify their decision-making and draw analogies between challenges and past ones. "Whatever" people can aggravate everyone, leading to trouble and strife at work and home. Housemates who struggle with making decisions can be troublemakers.

Regret often arises from careless attitudes, as long-term regrets often stem from decisions we did not make. What we choose to do today often affects what is possible in the future. Small but bad choices can snowball. It is important to remember that every choice creates a "ripple effect" that affects other aspects of life in positive and negative ways. Every decision involves some degree of risk, and it is better to make a good decision than to do nothing. Consulting with trusted advisors can help make sound decisions and creating a "personal board of directors" with wise people can provide numerous expert perspectives. Finally, the author recommends us to be decisive and avoid using the word "whatever" to indicate that we do not care. This will ensure that our choices shape our future. Sam Alemayhu, a respected businessman, and investor grew up in an impoverished village in Ethiopia and emigrated to America. His accomplishments inspire others to be decisive, care about their choices, and never say "whatever."


#codingexercise

Find minimum in a rotated sorted array:

class Solution {

public int findMin(int[] A) {

If (A == null || A.length == 0) { return Integer.MIN_VALUE; }

int start = 0;

int end = A.length -1;

while (start < end) {

int mid = (start + end) / 2;

// check monotonically increasing series

if (A[start] <= A[end] && A[start] <= A[mid] && A[mid] <= A[end]]) { return A[start];};

// check if only [start, end]

if (mid == start || mid == end) { if (A[start] < A[end]) return A[start]; else return A[end];}

// detect rotation point

if (A[start] > A[mid]){

end = mid;

} else {

if (A[mid] > A[mid+1]) return A[mid+1];

start = mid + 1;

}

}

return A[0];

}

}

Works for:

[0 1 4 4 5 6 7]

[7 0 1 4 4 5 6]

[6 7 0 1 4 4 5]

[5 6 7 0 1 4 4]

[4 5 6 7 0 1 4]

[4 4 5 6 7 0 1]

[1 4 4 5 6 7 0]

[1 0 0 0 0 0 1]

Sunday, June 16, 2024

 This is a continuation of a study involving a software application that responds to a chat like query on the data contained in the ten-year collection of my blog posts from https://ravinote.blogspot.com. Each article collected on the blog post is a daily routine and contains mostly unstructured text on quality explanations of software engineering practices and code samples from personal, enterprise and cloud computing. The earlier part of the study referred to leveraging Azure OpenAI search service to perform a semantic search based on the chat like query to create a generated response. This part of the study follows up on taking the data completely private so that the model built to respond to the query can be hosted on any lightweight compute including handheld devices using mobile browsers. The lessons learned in this section now follows:

First, a brief introduction of the comparison of the search methodologies between the two: 

1. Azure AI Toolkit for VS Code:

o Approach: This simplifies generative AI app development by bringing together AI tools and models from Azure AI catalog. We specifically use the Phi-2 small language model. It also helps to fine-tune and deploy models to the cloud.

o Matching: It matches based on similarity between query vectors and content vectors. This enables matching across semantic or conceptual likeness (e.g., “dog” and “canine”). Phi-2 is a 2.7 billion-parameter language model not the order of trillions in large language model but sufficiently compact to demonstrate outstanding reasoning and language understanding capabilities. Phi-2 is a Transformer based model with a next-word prediction objective that was originally trained on a large mixture of synthetic datasets for NLP and coding. 

o Scenarios Supported: 

Find a supported model from the Model Catalog.

Test model inference in the Model Playground.

Fine-Tune model locally or remotely in Model Fine-tuning

Deploy fine-tuned models to cloud via command-palette for AI Toolkit.

o Integration: Works seamlessly with other Azure services.

2. Azure OpenAI Service-Based Search:

o Approach: Uses the Azure OpenAI embedding model such as GPT-models to convert queries into vector embeddings. GPT-models are large language models while Phi-2 models are small language models. The dataset can include the web for the Chat Completions API from Azure OpenAI service. 

o Matching: Performs vector similarity search using the query vector in the vector database usually based on the top k-matching content based on a defined similarity threshold.

o Scenarios supported: 

Similarity search: Encode text using embedding models (e.g., OpenAI embeddings) and retrieve documents with encoded queries.

Hybrid search: Execute vector and keyword queries in the same request, merging results.

Filtered vector search: Combine vector queries with filter expressions.

o Cost:

increases linearly even for infrequent use at the rate of few-hundred dollars per month. The earlier application leveraging completion API had to be taken down for this reason.

Both approaches leverage vector embeddings for search, but toolkit and Phi-2 model are better for customizations while Azure OpenAI Completions API is useful for streamlined applications and quick chatbots.

And now the learnings follow:

- Fine-Tuning: A pretrained transformer can be put to different use during fine-tuning such as question-answering, language generation, sentiment analysis, summarization, and others. Fine-tuning adapts the model to different domains. Phi-2 behaves remarkably well in this regard. Fine-tuning LLMs are so cost prohibitive that it can be avoided. On the other hand, small language models are susceptible to overfitting where the model learns specifics of the training data that cannot be applied to the query.

- Parameter-Efficient Fine-tuning: This is called out here only for rigor. Costs for tuning LLMs can be reduced by fine-tuning only a subset of the model’s parameter but it might result in “catastrophic forgetting”. These techniques include LoRA, prefix tuning and prompt tuning. The Azure Toolkit leverages QLoRA. LoRA stands for Low-Rank Adaptation of Large Language Models and introduces trainable rank decomposition matrices into each layer of transformer architecture. It also reduces trainable parameters for downstream tasks while keeping the pre-trained weights frozen. QLoRA combines quantization with LORA with quantization data types to use as one of nf4 (4-bit normal float) or fp4 and adjustable batch size for training and evaluation per GPU. The data type is for compression to 4-bit precision as opposed to native floating-point-32-bit precision.

- Problem with outliers:  As with all neural networks that create embeddings, outliers are significant because while model weights are normally distributed, the inclusion of outliers directly affects the quality of the model. Iterative study involving different range of inclusions was too expensive to include in the study.

- Dequantization – this is the process of taking quantized weights which are frozen and not trained to be dequantized back to 32-bit precision. It is helpful to inference when quantized values and quantization constant can be used to backpropagate calculated gradients.

- Paged optimizers are necessary to manage memory usage during training of the language models. Azure NC4AS_T4_v3 family VMs handle this well but choice of sku is in initial decision not something that we can change during flight.

- BlobFuseV2 to load all the data stored in private storage accounts as local filesystem is incredibly slow for read over this entire dataset. Toolkit is more helpful to run on notebooks and laptops with VS Code, GPU, and customized local Windows Sub-system for Linux.


Saturday, June 15, 2024

 

Drone Formation Commercial Software:

This is another addendum to the discussion about Drone Formation Commercial Software as described in this document. In this section, we describe surface detection. Drones can help with surface detection by using an encompassing space around the surface to detect. Let us assume that an object, say saucer like, needs to be surrounded by drones. The points of reference along the object as positions around which the drones must organize themselves can be easily determined by the drones themselves. We further assume each drone can detect the distance to the object by themselves or passed to each drone from some central sensor in real-time. If the scouts can figure out the overall matrix of X-Y-Z coordinates that is sufficiently large enough to encompass the object, then the rest of the drones can make use of this initial grid to spread themselves out before each converges to a point of reference closest to it and independent of others as long as it safe and not colliding with other drones.

The scouts do a two-pass flyover the objects while the distance remains within a range. If the range is exceeded, the boundary of the encompassing grid is known. With the initial pass determining the grid a subsequent pass to converge as close as possible to the surface of the object while maintaining a distance from each other, helps the drone to determine the points of reference on the surface. With the full strength of the drone formation then spreading over and distributing themselves against the points of reference will help to cover the surface.

When the number of drones is in excess of those required to cover the surface, they can form ever-increasing layers over the underlying points of reference. These points adjust to be on one layer for the layer above and the logic remains the same for additional drones to work out the new positions to occupy. Wave propagation and Fourier transform can predict how soon the drones can cover the object or the number of layers to form and the rate or duration for full coverage by all the drones.

Distance from each other as well as to a point of reference is sensor-specific and merely translates as an input for the drone to determine the actual position to occupy as the output. This works for all stationary objects in an outward-grid-enclosing-on-to-the-surface-of-the-object manner for the drone formation. Selection of the initial number and identities of the drones for the scouts can be determined by a threshold for the maximum distance allowed for a scout. After a scout reaches this threshold, another scout covers the next interval to the allowed threshold.

Moving objects have the characteristics that their shape remains constant during the flight and if the end points for the object can be tracked as distinct positions over time, then they the frame of reference can be adjusted to include the initial and final positions for a given time slice.

Friday, June 14, 2024

 This is the summary of the book titled “The art of explanation” written by Ros Atkins and published by Headline Publishing in 2023. He has been serving as the analysis editor for BBC and contends that the ability to explain oneself well is a necessary art. To be clear and concise at once takes practice and one that can be worked on each day. It applies to relationships. job interviews, email writing, teaching children and engaging any audience and is thus immeasurably useful and fortunately learnable. Crafting a quality explanation starts with the right questions, a certain degree of familiarity with the audience and their needs, preparations for controlled environments, and even training for impromptu speeches. Verbalizing and memorizing ahead of time helps. Anticipating and soliciting feedback helps to refine. Short form is preferable but the ability to delve in depth on demand is also important. Practice in everyday life can be transformational.

Explanation is a crucial skill that many people lack, as it can significantly impact how they communicate and achieve their goals. It is essential to convey our message clearly and impactfully, as it increases the likelihood of being understood and achieving desired results. For example, entrepreneurs can attract investors by explaining their business models, teachers can enhance students' enjoyment by explaining complex information, patients can stick to diet plans by explaining their benefits, and government agencies can gain interest in their services by explaining how to access them. To craft a quality explanation, we must start with the right questions and master the art of explanation by addressing 10 key features: simplicity, essential detail, complexity, efficiency, precision, context, no distractions, engaging, useful, and clarity of purpose.

To create a memorable and engaging message, it is essential to understand our audience and our needs. This involves understanding demographics, age ranges, and what they already know and want to know. Crafting a bespoke message that resonates with our audience and applying oour knowledge to engage them are essential. Lastly, communicating our credibility on the subject matter wraps it up.


Preparation is crucial for effective explanations. In controlled scenarios, these seven steps can be followed:

1. Set-up: Clarify our audience and the purpose of our explanation.

2. Find the information: Gather information, including a summary, questions, research areas, and subject matter.

3. Distill the information: Filter out irrelevant elements and evaluate the data.

4. Organize the information: Divide it into strands or sections, focusing on high-impact elements or stories.

5. Link the information: Write down our first draft to ensure smooth flow and authenticity.

6. Tighten the explanation: Eliminate unnecessary elements and practice thoroughly.

7. Deliver the explanation: Rehearse our explanation thoroughly, using methods like reading from a script, flashcards, or memorizing. Record ourselves running through the explanation and address any gaps.

In uncontrolled situations also, it is essential to prepare and communicate clearly. Following the same steps as for controlled settings, including setting up, finding information, and distilling the information helps. In dynamic settings, organizing our information differently, with no more than five strands. Each strand should have a primary point, three supporting facts, and relevant context. Verbalizing and memorizing our dynamic explanation ahead of time, using bridging phrases to connect different elements and communicating our desired information seamlessly will have a tremendous impact. Practicing using memory techniques, such as creating a "memory palace" to visualize different strands of our explanation aids our retention. Anticipating questions or feedback others might have regarding our explanation, as people tend to be predictable and pattern-based, helps cover our base. Preparing for the worst-case scenario by imagining how we might respond if the roles were reversed is good preparation. We could preemptively formulate answers and research the situation before giving our explanation. This will help us prepare for both what we hope will happen and what may surprise us.

We must prepare for short-form explanations in just a couple of minutes by asking ourselves three questions before an interaction that requires an explanation. This will help us include the right details and make the conversation more engaging. Even with short emails, it's good for everyone to understand our message clearly. We must make your first sentence and subject line engaging and use formatting to highlight important details. We must avoid adding recipients who don't need to be included in the conversation. The art of explanation is a multifaceted process that must be adaptable to our unique circumstances. It's like a home chef testing recipes from a cookbook, and we can choose which aspects of our life to transform first with the art of explanation.

Previous book summary: BookSummary107.docx

Summarizing Software: SummarizerCodeSnippets.docx  



Thursday, June 13, 2024

 This is a continuation of articles on IaC shortcomings and resolutions. The following article describes how data scientists leveraging the cloud infrastructure tend to think about individual files and archives rather than filesystems. Most data used by data scientists to train their models either lives in a remote blob store, filestore or some form of data store such as structured and unstructured databases and virtual data warehouses. Distributed file systems in operating systems and intercompatibility protocols between heterogeneous operating systems such as Linux and Windows have long addressed the problem of viewing remote file systems as local paths via mounts and mapped drives, yet the diligence to setup and tear down entire filesystems on local compute instances and clusters is often ignored. 

Part of the reason for such limited use of files and archives has been the popularity of signed URIs for remote files that facilitate sharing on a file-by-file basis as well as the adoption of new file formats like parquet and zip archives for convenient data transfer. When changes are made to these files, they often require unpacking and packing and one-time update at the remote location. 

With the convenience of BlobFuse2 technology, mounted file systems can persist changes to remote location near instantaneously and are available for blob stores just as much as the technology is available for file stores. BlobFuse is a virtual system driver for Azure Blob Storage. It can be used to access existing blob data through the Linux File system. Page blobs are not supported. It uses libfuse open-source library to connect to the Linux FUSE kernel module. It implements filesystem operations by using Azure Storage REST APIs. Local file caching improves subsequent access times. An azure blob container on a remote Azure Data Lake Storage Gen 2 file system is mounted on Linux and its activities and resource usage can be monitored. The version 2 provides more management support through the Command-Line Interface  

On the other hand, the Azure File Storage offers fileshares in the cloud using the standard SMB protocol. Enterprise applications that rely on fileservers can find this transition easier. File shares can be mounted even from virtual machines running in Azure and on-premises applications that support SMB 3.0.

To mount the file share from a virtual machine running Linux, an SMB/CIFS client needs to be installed and if the distribution does not have a built-in client, it can be installed with the cifs-utils package. Then a mount command can be specified to make a mount point by giving the type, remote location, options, and local path as parameters. Mount shares can be persisted across reboots by adding a setting in the /etc/fstab file.

Lastly, as with all cloud resources and operations, all activities can be logged and monitored. They come with role-based access control for one-time setup and control plane operations can be automated with command-line interface, REST API calls, user-interface automations, and Software Development Kits in various languages.

Previous write-up: IaCResolutionsPart135.docx


Wednesday, June 12, 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 |




 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 |




 This is a continuation of previous articles on IaC shortcomings and resolutions. 

As with all automation, it is important to register them in source control so that their maintenance can become easy. It is also important to secure the credentials with which these scripts run. Finally, lockdown of all resources in terms of network access and private planes is just as important as their accessibility for automation.  

Many organizations don’t invest in Azure DevOps  for a variety of reasons, with attachments to on-premises based automation technology or avoiding public cloud automations for misplaced cost concerns. Other reasons can be genuine though. For example, one of the most common tasks is to download and run an executable instead of calling an API. This is convenient for portability and the same executable can be run using various Azure accounts or subscriptions. But if we take an automation account or runbook, then the downloaded executable might not run because the execution policy cannot be changed. The same goes for hybrid worker and the only way to overcome the limitation is to spin up a dedicated compute and modify it  to allow execution. It might be noteworthy to add that compute instance or cluster created on a databricks workspace or Azure machine learning workspace might also not work.  Their pass-through active directory authentication works only for notebooks but not the shell on the compute. This kind of limitation extends to other data oriented automations because they in turn leverage the workspaces and do not allow any activity on the scripts or notebooks that these workspaces cannot run.

Such a limitation, on the other hand, does not hold on the GitOps which has been one of the favorites for code delivery pipelines. In the GitOps, it is not only easy to download the executable from say an object repository such as Artifactory but also easy to pass command line parameters whose values are already known to the pipeline. Organizing the automation in GitOps is also fairly straightforward as pipelines become scoped to the code they push. 

Finally, there is a lot of maintenance work required  with scripts and automations and the use of source control becomes inevitable. Keeping the automations and the code they service as repositories enable them to be shared as appropriate.

These are some of the examples where a cloud native approach might not be straight. When organizations do enable Azure DevOps, they enhance their capabilities which gives them a  more secure, manageable and futuristic platform albeit one that dictates rewriting or rehosting the legacy scripts.


Wednesday, June 5, 2024

 This is  a summary of the book “Grace Under Pressure: Leading through change and crisis” written by John Baldoni and published by Savio Republic in 2023. The author teaches how to maintain composure in stressful situations. The first priority when pressure hits is to make sure our people are okay. Then, make sure we are okay and take a deep breath. We must look as wisely into the future and consider how to prevent today’s stress from compounding.  Any decision must not harm our people. He also stresses the importance of courage, compassion, empathy, hope, resilience and selflessness into our lives.

Grace serves us and our stakeholders. We must practice astute situational assessment and intelligent follow-up.  Leaders with grace under pressure  plan ahead and take care.

Logic helps to find the truth. Our values help to answer the “why” but grace helps to answer “how”. Control what we can. Instead of focusing on “winner takes all” and “winner shares all”. Those who practice this remain resolute.

"Grace under pressure" is a leadership concept that emphasizes maintaining one's coolness in challenging situations. It originated from the words of Ernest Hemingway, who described it as a dependable, composed leader directing a firefight. Grace is a mysterious, spiritual, and magical force that can appear unexpectedly and propel people towards their higher aspirations. High-quality leaders must objectively assess their teams, units, departments, or organizations to plan and implement actions to help their people succeed. They should ask three crucial questions: "What is happening?", "What is not happening?", and "What can I do to influence the outcome?" By designing their investigation to help them and their team take the best steps going forward, leaders can help their teams succeed in challenging situations. However, it is important to remember that sometimes the best group action might be no action at all.

Grace under pressure is a key leadership trait that involves taking care of one's people, taking care of oneself, and planning for the future. These leaders are able to adapt to change and adapt to it, demonstrating integrity, courage, and logical reasoning. They are also humilent, reason-driven, courageous, humorous, and loving.


Grace is essential for leading a meaningful life, as it fuels purpose and becomes the "how" to achieve goals. It enriches connections and creates a sense of community among employees. Leaders who can muster grace under pressure can take their organization in a different direction, fostering connections among their people and building internal cohesion.


Corporate cultures that foster a sense of community can foster connections among their people, helping organizations become a setting for connected communities. Transformations require grace, which involves listening before talking, solving problems, encouraging open communication, instilling hope, banishing fear, and acting forthrightly and with courage.

We must focus on the present, recharge or renew, orient yourself to the future, anchor yourself, and have humility. Leaders must be flexible and adaptable to the unpredictable world they face. We must be careful, deliberate, measured, and reflective in our thoughts and actions, making "mutuality" our watchword. Orienting ourselves to the goal of making things better for those we lead, coaching them to benefit from our values and long-range thinking.

Leaders should also walk behind their people, as stress resilience expert Dr. Sharon Melnick believes leaders don't have time to not do this. Many business-school students are afraid to come across as friendly and civil once they gain authority at work, but a leader with grace knows that they can overcome challenges and become better people. By following these ground rules, leaders can control their actions and achieve success in their organizations.

Grace under pressure leaders maintain resoluteness despite challenges, focusing on dignity and creating a workplace where people feel valued and want to contribute. They communicate effectively, avoid anxiety and fear, remain positive, stress mental health, and engage with team members. To exhibit grace under pressure, leaders should ask three questions: what to do, how to effectively engage with their team, and how their leadership will be portrayed during a crisis.

 

Summarizing Software: SummarizerCodeSnippets.docx  



Tuesday, June 4, 2024

 Subarray Sum equals K 

Given an array of integers nums and an integer k, return the total number of subarrays whose sum equals to k. 

A subarray is a contiguous non-empty sequence of elements within an array. 

Example 1: 

Input: nums = [1,1,1], k = 2 

Output: 2 

Example 2: 

Input: nums = [1,2,3], k = 3 

Output: 2 

Constraints: 

1 <= nums.length <= 2 * 104 

-1000 <= nums[i] <= 1000 

-107 <= k <= 107 

 

class Solution { 

    public int subarraySum(int[] nums, int k) { 

        if (nums == null || nums.length == 0) return -1; 

        int[] sums = new int[nums.length];    

        int sum = 0; 

        for (int i = 0; i < nums.length; i++){ 

            sum += nums[i]; 

            sums[i] = sum; 

        } 

        int count = 0; 

        for (int i = 0; i < nums.length; i++) { 

            for (int j = i; j < nums.length; j++) { 

                int current = nums[i] + (sums[j] - sums[i]); 

                if (current == k){ 

                    count += 1; 

                } 

            } 

        } 

        return count; 

    } 

 

[1,3], k=1 => 1 

[1,3], k=3 => 1 

[1,3], k=4 => 1 

[2,2], k=4 => 1 

[2,2], k=2 => 2 

[2,0,2], k=2 => 4 

[0,0,1], k=1=> 3 

[0,1,0], k=1=> 2 

[0,1,1], k=1=> 3 

[1,0,0], k=1=> 3 

[1,0,1], k=1=> 4 

[1,1,0], k=1=> 2 

[1,1,1], k=1=> 3 

[-1,0,1], k=0 => 2 

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

[1,0,-1], k=0 => 2 

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

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

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

 

 

 



Monday, June 3, 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


 


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 |




Sunday, June 2, 2024

 This is a continuation of several articles on openai search for Drone formation organization using elements as reference locations and nodes as predicted positions for drones. The elements can be stored in any non-proprietary vector database and a sample implementation would look something as follows and also called out in: https://github.com/ravibeta/semantic_search  

The first step would be to install all the required packages and libraries. We use Python in this sample:

import warnings 

warnings.filterwarnings(‘ignore’) 

from datasets import load_dataset 

from pinecone import Pinecone, ServerlessSpec 

from DLAIUtils import Utils 

import DLAIUtils  

import os 

import time 

import torch 

From tqdm.auto import tqdm 

We assume the elements are mapped as embeddings in a 384-dimensional dense vector space. 

A sample query would appear like this: 

query = `what is node nearest this element?` 

xq = model.encode(query) 

xq.shape 

(384,) 

The next step is to set up the Pinecone vector database to upsert embeddings into it. These database index vectors make search and retrieval easy by comparing values and finding those that are most like one-another 

utils = Utils() 

PINECONE_API_KEY = utils.get_pinecone_api_key() 

if INDEX_NAME in [index.name for index in pinecone.list_indexes()]: 

       pinecone.delete_index(INDEX_NAME) 

print(INDEX_NAME) 

pinecone.create_index(name=INDEX_NAME, dimension=model.get_sentence_embedding_dimension(), metric=’cosine’,spec=ServerlessSpec(cloud=’aws’, region=’us-west-2’)) 

index = pinecone.Index(INDEX_NAME) 

print(index) 

Then, the next step is to create embeddings for all the elements in the sample space and upsert them to Pinecone. 

batch_size=200 

vector_limit=10000 

elements=element[:vector_limit] 

import json 

for i in tqdm(range(0, len(elements), batch_size)): 

        i_end = min(i+batch_size, len(elements)) 

        ids = [str(x) for x in range(i, i_end)] 

        metadata = [{‘text’: text} for text in elements[i:i_end]] 

        xc = model.encode(elements[i:i_end]) 

        records = zip(ids, xc, metadata) 

        index.upsert(vectors=records) 

index.describe_index_stats() 

Then the query can be run on the embeddings and the top matches can be returned. 

def run_query(query): 

        embedding = model.encode(query).tolist() 

        results = index.query(top_k=10, vector=embedding, include_metadata=True, include_value) 

        for result in results[‘matches’]: 

                print(f”{round(result[‘score’], 2)}: {result[‘metadata’][‘node’]}”) 

run_query(“what is node nearest this element?”) 

With this, the embeddings-based search over elements is ready. In Azure, cosmos DB offers a similar semantic search and works as a similar vector database. 

The following code outlines the steps using Azure AI Search 

# configure the vector store settings, vector name is in the index of the search

endpoint: str = "<AzureSearchEndpoint>"

key: str = "<AzureSearchKey>"

index_name: str = "<VectorName>"

credential = AzureKeyCredential(key)

client = SearchClient(endpoint=endpoint,

                      index_name=index_name,

                      credential=credential)


# create embeddings 

embeddings: AzureOpenAIEmbeddings = AzureOpenAIEmbeddings(

    azure_deployment=azure_deployment,

    openai_api_version=azure_openai_api_version,

    azure_endpoint=azure_endpoint,

    api_key=azure_openai_api_key,

)

# create vector store

vector_store = AzureSearch(

    azure_search_endpoint=endpoint,

    azure_search_key=key,

    index_name=index_name,

    embedding_function=embeddings.embed_query,

)

# create a query

docs = vector_store.similarity_search(

    query=userQuery,

    k=3,

    search_type="similarity",

)

collections.insert_many(docs)


Saturday, June 1, 2024

 Automation can also be achieved with Azure Data Factory aka ADF and a self-hosted integration runtime that comprises of a vm hosted on-premises and a Script activity. While typically associated with Data Transformation activities, a self-hosted integration runtime  can participate in running any scripts and its invocation from ADF guarantees human and programmatic access from anywhere that has cloud connectivity. A self-hosted integration runtime is a component that connects data sources on-premises/ on Azure VM with cloud services in a secure and managed way

The Json syntax for defining a script looks something like this:

   "name": "<activity name>", 

   "type": "Script", 

   "linkedServiceName": { 

      "referenceName": "<name>", 

      "type": "LinkedServiceReference" 

    }, 

   "typeProperties": { 

      "scripts" : [ 

         { 

            "text": "<Script Block>", 

            "type": "<Query> or <NonQuery>", 

            "parameters":[ 

               { 

                  "name": "<name>", 

                  "value": "<value>", 

                  "type": "<type>", 

                  "direction": "<Input> or <Output> or <InputOutput>", 

                  "size": 256 

               }, 

               ... 

            ] 

         }, 

         ... 

      ],     

         ... 

         ] 

      }, 

      "scriptBlockExecutionTimeout": "<time>",  

      "logSettings": { 

         "logDestination": "<ActivityOutput> or <ExternalStore>", 

         "logLocationSettings":{ 

            "linkedServiceName":{ 

               "referenceName": "<name>", 

               "type": "<LinkedServiceReference>" 

            }, 

            "path": "<folder path>" 

         } 

      } 

    } 

}

The output can be collected everytime a script block is executed. There is a 5000 rows/4MB size limit but this is sufficient for most purposes.


A sample curl call would be something like this:

##! /usr/bin/python

import requests


# Set your ADF details

subscription_id = '<subscription_id>'

resource_group = '<resource_group>'

factory_name = '<factory_name>'


# Set the pipeline name you want to trigger

pipeline_name = 'your_pipeline_name'


# Construct the API URL

api_url = f"https://management.azure.com/subscriptions/{subscription_id}/resourceGroups/{resource_group}/providers/Microsoft.DataFactory/factories/{factory_name}/pipelines/{pipeline_name}/createRun?api-version=2017-03-01-preview"


# Make the POST request

response = requests.post(api_url)


# Check the response status

if response.status_code == 200:

    print("Pipeline triggered successfully!")

else:

    print(f"Error triggering pipeline. Status code: {response.status_code}")

## EOF