Sunday, December 3, 2023

 

Maximum Sum With Exactly K Elements

0-indexed integer array nums and an integer k are given. The task is to perform the following operation exactly k times in order to maximize your score:

  1. Select an element m from nums.
  2. Remove the selected element m from the array.
  3. Add a new element with a value of m + 1 to the array.
  4. Increase your score by m.

The maximum score that can be achieved after performing the operation exactly k times must be returned.

 

Example 1:

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

Output: 18

Explanation: We need to choose exactly 3 elements from nums to maximize the sum.

For the first iteration, we choose 5. Then sum is 5 and nums = [1,2,3,4,6]

For the second iteration, we choose 6. Then sum is 5 + 6 and nums = [1,2,3,4,7]

For the third iteration, we choose 7. Then sum is 5 + 6 + 7 = 18 and nums = [1,2,3,4,8]

So, we will return 18.

It can be proven, that 18 is the maximum answer that we can achieve.

Example 2:

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

Output: 11

Explanation: We need to choose exactly 2 elements from nums to maximize the sum.

For the first iteration, we choose 5. Then sum is 5 and nums = [5,5,6]

For the second iteration, we choose 6. Then sum is 5 + 6 = 11 and nums = [5,5,7]

So, we will return 11.

It can be proven, that 11 is the maximum answer that we can achieve.

 

Constraints:

  • 1 <= nums.length <= 100
  • 1 <= nums[i] <= 100
  • 1 <= k <= 100

 

class Solution {

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

        if (nums == null || nums.length == 0 || k <= 0) return 0;

        Arrays.sort(nums);

        int sum = 0;

        int val = nums[nums.length-1];

        for (int i = 0; i < k; i++){

            sum += val;

            val += 1;

        }

        return sum;

    }

}

 

Nums = [3], k = 3 => sum = 12

Nums = [1,2,3], k = 3 => sum = 12

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

Nums = [-1,0,1], k = 1 => sum = 1 

 

Saturday, December 2, 2023

 This is a continuation of previous articles on IaC shortcomings and resolutions. The networking resources for private plane connectivity are ubiquitous and several within any deployment. As the deployment grows with age, the versions of the toolset and definitions also change. New properties are added while the old ones are deprecated. Subnets, for instance, can be created with different definitions and property values but with the same module. By nature of subnets delegated to a resource type, there will be several within a virtual network used with a deployment. When the new properties are added to the definition, many of the existing properties might require an opposite value with these new properties while the others might work with the default value. The same goes for different environments where the module is applied. Changing the definitions might pose a risk across many resources that are hosted on the subnets. If there are disruptions, they could manifest in different scenarios,

This could be overcome by staging the changes progressively and in an incremental manner such that the round of tests is minimized and only applies to the changes made. The first step should be to update the toolset before any changes are made  Many of the existing resource types might need adjustments with new toolsets although backward compatibility if a standard feature as toolset versions is incremented. Once this is done, the existing definitions must be assigned to a reference for their source before a new definition is used. If they do not have a reference, they will likely point to the latest and updating the source to a new definition will affect more resources than intended. Next, the common definition must be updated, and a new tag must be generated so that it can be referenced only from those callers that require the new definition. One the reference is available, all the resources in the deployment that require the new definition must point to the new reference. Then their properties must be replaced with new properties in such a way that there is no change to the current infrastructure. Some of this might be counterintuitive in terms of say Boolean values assigned to certain properties but the goal must be to have no changes to the infrastructure after complying with the new syntax. This way there will not be a need to test all the resources attached to the subnets, which is quite a daunting task. Finally, changes must be made on a case-by-case basis so that those cases can be tested independent of the overall infrastructure. When all the changes have been made to revise the infrastructure, the definitions, the resource properties, and the fine tunings to individual resources, then a closure can be applied by setting up alerts and notifications as the resource-types demand. 

One of the advantages of making selective changes is that the business can weigh in on their priorities and release dates. It does not need to be done all at once and it might even be beneficial to get their acceptance after each change. The requirements from the business usually affect one or more environments, so prioritizing by environment is a natural order. It is also possible to include the changes compare resources from different scenarios which will inevitably help with troubleshooting unexpected behaviors from deployed resources. Together with the scenarios and infrastructure, it would be easier to narrow down the potential issues and determine the course of action for their resolutions. Similarly, we can leverage the compiler planning and execution stages to spot errors before they are caught by actual testing. 

In this way, changes affect several dozens of resources can be made in a safe and efficient manner.


Friday, December 1, 2023

 

This is a summary of a book titled “The Leader’s checklist – 16 mission critical principles” written by Michael Useem and published by the Wharton School Press 2021. He is a is a professor of management and the faculty director of the Center for Leadership and Change Management and the McNulty Leadership Program at the Wharton School of the University of Pennsylvania. Everybody draws up a list of tasks they need to get to. Leadership is also best served by a checklist only that it varies for the level of leadership.

A team leader’s checklist might include these items:

Educate – Build your team members’ knowledge and cognitive skills.

Plan – Establish specific goals and defined, varied tasks for your team members.

Energize – Encourage team members to be flexible and evolve as demands change.

Foster diversity and be inclusive – Seed your teams with people from a variety of backgrounds.

A board member’s leadership checklist could include:

Strategize – Board members must make sure their company’s executives generate well-developed strategic plans to create organizational value and increase competitive advantage.

Set a tone – To collaborate effectively, board members must show restraint and be diplomatic.

Mentor others – Board members must teach future leaders.

Advise – Board members serve in partnership with their company’s CEO who should be able to trust them to provide their best counsel.

The team of teams’ leader needs a checklist that includes these priorities: 

Unify – Champion a “common mind-set” and collaborative culture. 

Structure – Team-of-teams leaders organize around a “cohesive inner circle.” Each member shares a particular vision and offers the group relevant expertise.

Bonding – Team-of-teams leaders foster “strong lateral” bonds across divisional boundaries to develop a unified perspective among their team members.

Collaborate – In the team-of-teams framework, leaders of individual groups work toward their goals in collaboration with other teams.

Along with a wealth of stories, anecdotes and  research findings, this book provides preparation for the future while staying focused and organized.`

The guiding principles for the checklists both published and customized are mentioned by these sixteen principles: articulate a vision, think and act strategically, honor the room, take charge and lead change, act decisively, communicate persuasively, motivate the workforce, embrace the front lines, build leadership in others, manage relations, identify personal implications, convey your character, dampen over-optimism and excessive pessimism, build a diverse top team, place common interest first, and think like a CEO.

Wednesday, November 29, 2023

NAT Gateway

 

Azure provides customers with the resources to establish public and private plane network connectivity. By placing resources in a virtual network with subnets each for different address ranges, an organization can secure inbound and outbound access to those resources. As resources are assigned to subnets, traffic can be contained within the virtual network. By providing inbound and outbound access only to the virtual network, resources eliminate their accessibility from the internet. This improves security but sometimes there is a need for resources to access targets on the internet. One way to provide internet access is with the use of a NAT Gateway.

Azure Network Address Translation (NAT) Gateway is a fully managed and highly resilient NAT service that provides outbound connectivity to the internet through the deployment of a NAT gateway resource. A NAT gateway can be used so that instances in a private subnet can connect to services outside the VPC, but external services cannot initiate a connection with those instances. A NAT gateway can be attached to multiple subnets within a virtual network to provide outbound connectivity to the internet.  Some benefits of NAT include the reuse of private IP addresses, enhancing of security for private networks by keeping internal addressing private from the external network, and connecting many hosts to the global Internet using a smaller number of public (external) IP address, thereby conserving IP address space.

If the virtual network address space has multiple address ranges defined, Azure creates an individual route for each address range. Azure automatically routes traffic between subnets using the routes created for each address range. Gateways don’t need to be defined for Azure to route traffic between subnets.

The system default route specifies the 0.0.0.0/0 address prefix. If Azure’s default routes are not overridden, Azure routes traffic for any address not specified by an address range within a virtual network to the Internet. There's one exception to this routing. If the destination address is for one of Azure's services, Azure routes the traffic directly to the service over Azure's backbone network, rather than routing the traffic to the Internet. Traffic between Azure services doesn't traverse the Internet, regardless of which Azure region the virtual network exists in, or which Azure region an instance of the Azure service is deployed in. Azure's default system route for the 0.0.0.0/0 address prefix can be overridden with a custom route.

An Azure NAT Gateway in a subnet can provide outbound connectivity for all private resources in that subnet. This includes traffic from other subnets within the same virtual network but they must be associated. A NAT gateway can be attached to multiple subnets for outbound connectivity. It can be assigned up to 16 public IP addresses or a /28 size public IP prefix. It takes precedence over a load balancer with or without outbound rules. It becomes the next hop type for all internet destined traffic. A NAT gateway can't span beyond a single virtual network. It provides source network address translation (SNAT) for private instances within subnets of an Azure virtual network.

Tuesday, November 28, 2023

ADF Programmability

Sample invocations with responses:

PUT https://management.azure.com/subscriptions/656e67c6-f810-4ea6-8b89-636dd0b6774c/resourceGroups/rg-temp/providers/Microsoft.DataFactory/factories/rajamadf1/linkedservices/AmazonS3LinkedService?api-version=2018-06-01?factoryName=rajamadf1&linkedServiceName=AmazonS3LinkedService&resourceGroupName=rg-temp&subscriptionId=656e67c6-f810-4ea6-8b89-636dd0b6774c&api-version=2018-06-01

Headers:

Content-Type: application/json

Authorization: Bearer

RequestBody:

{

              properties: {

          "type": "AmazonS3",

          "typeProperties": {

             "connectionString": {

                 "type": "SecureString",

                 "value": "https://b67.s3.us-east-1.amazonaws.com/20231114_183657.jpg?response-content-disposition=inline&X-Amz-Security-Token=Token1&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20231127T011622Z&X-Amz-SignedHeaders=host&X-Amz-Expires=43200&X-Amz-Credential=ASIAWBUSJVLECCOOMERM%2F20231127%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Signature=29874c234eab5d9416e1158d3e5ba8513f163227b538258a295f78a35bcae1ee"

             }

          }

        }

}

 

Response:

Code: 200

Headers:

cache-control: no-cache

content-type: application/json; charset=utf-8

date: Mon, 27 Nov 2023 01:17:16 GMT

expires: -1

pragma: no-cache

server: Kestrel

x-ms-correlation-request-id: 235732c1-d0b1-402a-a3ee-d64366b8207d

x-ms-ratelimit-remaining-subscription-writes: 1199

x-ms-request-id: 235732c1-d0b1-402a-a3ee-d64366b8207d

x-ms-routing-request-id: WESTUS2:20231127T011716Z:235732c1-d0b1-402a-a3ee-d64366b8207d

 

Body:

{

  "id": "/subscriptions/656e67c6-f810-4ea6-8b89-636dd0b6774c/resourceGroups/rg-temp/providers/Microsoft.DataFactory/factories/rajamadf1/linkedservices/AmazonS3LinkedService",

  "name": "AmazonS3LinkedService",

  "type": "Microsoft.DataFactory/factories/linkedservices",

  "properties": {

    "type": "AmazonS3",

    "typeProperties": {

      "connectionString": {

        "type": "SecureString",

        "value": "**********"

      }

    }

  },

  "etag": "9e06116d-0000-0100-0000-6563ee1c0000"

}

 

Sample REST call to trigger a run:

POST https://management.azure.com/subscriptions/656e67c6-f810-4ea6-8b89-636dd0b6774c/resourceGroups/rg-temp/providers/Microsoft.DataFactory/factories/rajamadf1/pipelines/pipeline1/createRun?api-version=2018-06-01

Authorization: Bearer <token>

Content-type: application/json

 

Response:

Code: 200

Headers

cache-control: no-cache

content-type: application/json; charset=utf-8

date: Mon, 27 Nov 2023 01:56:03 GMT

expires: -1

pragma: no-cache

server: Kestrel

x-ms-correlation-request-id: cd5087fd-a9e9-4997-8ccc-d896788dc19f

x-ms-ratelimit-remaining-subscription-writes: 1199

x-ms-request-id: cd5087fd-a9e9-4997-8ccc-d896788dc19f

x-ms-routing-request-id: WESTUS2:20231127T015604Z:cd5087fd-a9e9-4997-8ccc-d896788dc19f

 

Body:

{

  "runId": "e62d495e-cadb-4294-b466-619ec7e5961f"

}

 

 

These sample REST calls are also available via CLI command usages when viewed with the –debug and –verbose option.

For example,

az datafactory dataset create --factory-name rajamadf1 --name AmazonS3SourceDataset1 --linked-service-name AmazonS3LinkedService1 --type AmazonS3Object --schema "{ \"type\": \"object\", \"properties\": { \"fileName\": { \"type\": \"string\" } } }" --structure "{ \"type\": \"object\", \"properties\": { \"fileName\": { \"type\": \"string\" } } }" --debug --verbose

 

Monday, November 27, 2023

 

This is a summary of the book titled “Coachability – the Leadership Superpower” by Kevin Wilde written in 2022. He is an executive leadership fellow at the University of Minnesota and has worked as senior talent development executive at General Mills and General Electric for seventeen years each.

In this book, Kevin convinces us that accepting feedback as a leader is far more valuable than learning how to deliver it and he calls this trait “coachability”. No matter the background, age, sex or any other forms of discrimination, it applies across the board, and anyone can do it.

Age, however, can be called out as one of the leading contributors to the decline of receptivity to coaching. Firms want leaders to coach so they promote coaching skills, but they overlook the importance of coachability. This causes leaders to lose their effectiveness and their ability to continually develop, which is critical.

Instead of indirect skills, coachability is a direct skill because clear feedback can accelerate us in the right direction. Even keeping a coachability notebook and starting to record can be a helpful practice

Some resistance to coachability is both genuine and natural. When leaders are put through a game to meet with each other and explain their weaknesses, they might resist behaving so vulnerably but they end up participating with gusto. An aversion to vulnerability, desire to maintain control or fear of the unknown can get in the way. Coachability requires openness and a commitment to learn continuously.

Other factors that hinder coachability include arrogance as demonstrated by those who feel they have reached the finish line, façade of strength which appears to hide ignorance or fear, susceptibility to flattery when leaders want yes men, isolation when promoted leaders can find themselves removed from their peer, and deprioritizing feedback because leaders can choose to procrastinate.

Highly coachable leaders, on the other hand, stand apart and people recognize their trait. They inspire higher levels of motivation and engagement and lead to greater productivity, sales, and satisfaction.

Coachability depends on practice and mindset more than innate traits. These leaders don’t just remain open to feedback but they seek it out, and listen carefully. They reflect on what they have heard, assessing its value and relevance to make their own determination about what to embrace or discard.

Seven strategies that can help us to be more coachable include being specific by asking clear questions, asking two questions on what went well and what could be done better, holding after-action reviews on why it happened and how to improve next time, making a plan for our own learning and development, asking a truth-teller, looking for signs that can be direct and indirect and seeking clarification whenever doubtful.

The truth is that our experience of receiving the so-called gift of feedback is not all that pleasant. Like a good actor, rather than get defensive, we can tell ourselves to take a note.

Reference:

Previous Book Summaries: BookSummary20.docx

 

Sunday, November 26, 2023

 

This is a summary of a fun-read-book titled “The Everyday Warrior” - A no hack practical approach to life written by Mike Sarraille in 2022. He talks about life holding valuable lessons as we go along the way to achieving our goals. He even calls out failures to find encouragement not discouragement. Using military terminology, he teaches soft skills such as drive, resilience, and a positive attitude. He says maintaining a balance between physical, mental, and emotional needs is important. Finally, he talks about why shortcuts disappoint and the journey is often its own reward.

The main take-aways are that the “Everyday warrior” uses failure as a teacher and motivator. Mentally fit people treat the brain as a muscle they condition, exercise and rest. Time constraints, fear, doubt and weak initiative prevent people from committing to achieving their goals. Instant gratification must be avoided and instead a step-by-step technique can be adopted to pursue one’s goals. People yearn for connection via a social circle or tribe. Time must be taken to rest and reflect.

Maintaining a balance when striving towards goals is an art and a science. We cannot let anxiety, depression, social isolation, apathy and frustration deter us. The Everyday warrior’s traits are instead resilience, confidence, positive attitude, and a drive to achieve and improve. This mindset makes us accountable, disciplined, pragmatic, vulnerable, humble and capable of honest self-assessment.

Consider that Michael Phelps, the Olympian swimmer won 23 gold medals and constantly sought to achieve success in Olympics at the cost of a balanced boyhood and resulting in subsequent struggles with alcohol and drug abuse. The “whole person concept”, on the other hand, practiced by Army Green Berets and Navy Seal recruiters who excel in volatile, uncertain, complex and ambiguous aka VUCA situations.

An everyday warrior knows when to rest and care for oneself is as important as fighting the battle. Acquiring self-knowledge is challenging because media, school, families, and “external influences” shape what people think they want. Comparing oneself with others or choosing goals based on how others will perceive them is not the right approach. Instead, we must determine our own definition of success. An example of this is that Marine Rob Jones lost both his legs in Afghanistan tour to an IED but when he returned he made it his goal to raise funds for veterans. As part of one of his campaigns, he ran 31 marathons in 31 days. There is even a famous saying attributed to stoic king Marcus Aurelius who said that we cannot control events but we can control our mind. We must shift away from a victim mind-set. People only fail to reach their goal out of doubt, fear, time-constraints, and unwillingness to make the required effort.

The five steps to succeed are 1. To set a smart goal, 2. Develop a plan of sequential tasks aka “small victories”, 3. Taking actions that disrupt the comfort of old habits, 4. Making time for introspection, and 5. And repeating the process until we are “more accomplished and capable.”

We must avoid shortcuts in pursuing our goals. Building resistance to instant gratification by showing gratitude and training oneself to avoid instant rewards will help us in the long run.

Previous book summaries: BookSummary17.docx