Beth  Nabimanya

Beth Nabimanya

1624874940

Leetcodes Algorithm Series: Contains Duplicate

Hello, hello! As I continue my job search, I am practicing my algorithm questions on Leetcode. So, I thought I would blog about some Leetcode problems as I solve them.

As a Bootcamp graduate, I did not get much practice in algorithms, so it has been a very fun and sometimes frustrating trial and error in recognizing patterns, optimizing my code to be faster (looking at you Big-O), learning how to break down a problem, and sometimes implementing neat math tricks to solve these algorithm problems. I have been practicing them using JavaScript.

As I’m relatively new to algorithm problems, I’ve started out with their Easy Collection of Top Interview Questions. So in Contains Duplicate:

Given an integer array nums, return true if any value appears at least twice in the array, and return false if every element is distinct.

Examples:

Input: nums = [1,2,3,1]
Output: true

Input: nums = [1,2,3,4]
Output: false
Input: nums = [1,1,1,3,3,4,3,2,4,2]
Output: true

Simply, if any numbers in the array appear more than once in the array, I need to return true . Now, I will definitely need to figure out a way to compare a number to the other numbers. Additionally, I will most likely need to loop through the array so I have access to each number to then compare it to others.

First, I thought that I could iterate through the array, and at each instance, I iterate through another loop of the remaining integers and compare them to see if any are equal (===). However, per my beginner understanding of Big-O, this would yield me an unfavorable time complexity of O(n²).

Then, I thought that I could create an object and count how many times a number in the array appears. By doing this, I could then check to see if any of the numbers had a count greater than 1. If so, then I could return true else I would return false .

#computer-science #leetcode #javascript #programming #algorithms #leetcodes algorithm

What is GEEK

Buddha Community

Leetcodes Algorithm Series: Contains Duplicate
Beth  Nabimanya

Beth Nabimanya

1624874940

Leetcodes Algorithm Series: Contains Duplicate

Hello, hello! As I continue my job search, I am practicing my algorithm questions on Leetcode. So, I thought I would blog about some Leetcode problems as I solve them.

As a Bootcamp graduate, I did not get much practice in algorithms, so it has been a very fun and sometimes frustrating trial and error in recognizing patterns, optimizing my code to be faster (looking at you Big-O), learning how to break down a problem, and sometimes implementing neat math tricks to solve these algorithm problems. I have been practicing them using JavaScript.

As I’m relatively new to algorithm problems, I’ve started out with their Easy Collection of Top Interview Questions. So in Contains Duplicate:

Given an integer array nums, return true if any value appears at least twice in the array, and return false if every element is distinct.

Examples:

Input: nums = [1,2,3,1]
Output: true

Input: nums = [1,2,3,4]
Output: false
Input: nums = [1,1,1,3,3,4,3,2,4,2]
Output: true

Simply, if any numbers in the array appear more than once in the array, I need to return true . Now, I will definitely need to figure out a way to compare a number to the other numbers. Additionally, I will most likely need to loop through the array so I have access to each number to then compare it to others.

First, I thought that I could iterate through the array, and at each instance, I iterate through another loop of the remaining integers and compare them to see if any are equal (===). However, per my beginner understanding of Big-O, this would yield me an unfavorable time complexity of O(n²).

Then, I thought that I could create an object and count how many times a number in the array appears. By doing this, I could then check to see if any of the numbers had a count greater than 1. If so, then I could return true else I would return false .

#computer-science #leetcode #javascript #programming #algorithms #leetcodes algorithm

LeetCode: Longest Palindromic Substring With Manachar’s Algorithm

What is a Palindrome?

A palindrome is a word that reads the same forwards and backwards. In my universe, there are two kinds of palindrome: “Odd Pal” and “Even Pal”.

Even Pal

Even Pal is a palindrome which has an even length, for example: “ZYXXYZ”. In the visualization below you can see how we can split it into 2 parts that have size 3: “ZYX” and “XYZ” . This palindrome will always have two centres called Left Center” at index2 and “Right Center” at index3.

Even Pals

“Even Pal”

Notice that:

  • character at index2 = character at index3 (mirror 1)
  • character at index1 = character at index4 (mirror 2)
  • character at index0 = character at index5 (mirror 3)

It is because of the above equality of characters at their respective indexes that the string is a palindrome and the two parts look like a sequence of 3 mirrors.

Odd Pal

Odd Pal is a palindrome which has an odd length, example: “ZYXWXYZ”. In the visualization below you can see how we can split the string into 2 parts that have size 3: “ZYX” and “XYZ”, while “W” at index3 becomes the center.

Image for post

“Odd Pal”

Notice that:

  • character at index2 = character at index4 (mirror 1)
  • character at index1 = character at index5 (mirror 2)
  • character at index0 = character at index6 (mirror 3)

Notice how again the two parts look like a sequence of 3 mirrors.

Problem

The problem states that we have to find the longest substring that is a palindrome in the string. A substring is a section of a string that consists of contiguous elements. Some examples are:

Input1: “BABAD” | Output1: “BAB” or “ABA”

Input2: “CBBD” | Output2: “BB”

Input3: “A” | Output3: “A”

Solutions

O(n²) Complexity

The simplest way to solve for this is to take every index as 1) a center 2) a Left Center and expand outwards to make character comparisons and find mirrors. The sequence with the maximum number of mirrors would be returned. Seems very simple and intuitive but the complexity is O(n²) because expanding a palindrome around a center could take O(n) time and we will explore every index in the string to be a center and left center, so O(n²) would be the time complexity.

O(n) Complexity

We can improve this runtime if we think of a way where we can leverage the previous palindromes found (as we navigate through the string) and reduce the “expanding outwards” part. Luckily, this is possible with “Manachar’s algorithm”.

Manachar’s algorithm

Before diving into the algorithm itself, we need to learn a few things first. For simplicity we will be focusing on Odd Pals for the most part. So let’s learn a few things in order:

#palindrome #leetcode #algorithms #substring #coding #algorithms

Christa  Stehr

Christa Stehr

1602964260

50+ Useful Kubernetes Tools for 2020 - Part 2

Introduction

Last year, we provided a list of Kubernetes tools that proved so popular we have decided to curate another list of some useful additions for working with the platform—among which are many tools that we personally use here at Caylent. Check out the original tools list here in case you missed it.

According to a recent survey done by Stackrox, the dominance Kubernetes enjoys in the market continues to be reinforced, with 86% of respondents using it for container orchestration.

(State of Kubernetes and Container Security, 2020)

And as you can see below, more and more companies are jumping into containerization for their apps. If you’re among them, here are some tools to aid you going forward as Kubernetes continues its rapid growth.

(State of Kubernetes and Container Security, 2020)

#blog #tools #amazon elastic kubernetes service #application security #aws kms #botkube #caylent #cli #container monitoring #container orchestration tools #container security #containers #continuous delivery #continuous deployment #continuous integration #contour #developers #development #developments #draft #eksctl #firewall #gcp #github #harbor #helm #helm charts #helm-2to3 #helm-aws-secret-plugin #helm-docs #helm-operator-get-started #helm-secrets #iam #json #k-rail #k3s #k3sup #k8s #keel.sh #keycloak #kiali #kiam #klum #knative #krew #ksniff #kube #kube-prod-runtime #kube-ps1 #kube-scan #kube-state-metrics #kube2iam #kubeapps #kubebuilder #kubeconfig #kubectl #kubectl-aws-secrets #kubefwd #kubernetes #kubernetes command line tool #kubernetes configuration #kubernetes deployment #kubernetes in development #kubernetes in production #kubernetes ingress #kubernetes interfaces #kubernetes monitoring #kubernetes networking #kubernetes observability #kubernetes plugins #kubernetes secrets #kubernetes security #kubernetes security best practices #kubernetes security vendors #kubernetes service discovery #kubernetic #kubesec #kubeterminal #kubeval #kudo #kuma #microsoft azure key vault #mozilla sops #octant #octarine #open source #palo alto kubernetes security #permission-manager #pgp #rafay #rakess #rancher #rook #secrets operations #serverless function #service mesh #shell-operator #snyk #snyk container #sonobuoy #strongdm #tcpdump #tenkai #testing #tigera #tilt #vert.x #wireshark #yaml

Agnes  Sauer

Agnes Sauer

1596487260

Graduating from Leetcode

What is LeetCode.com?

It’s a website where people–mostly software engineers–practice their coding skills. It’s pretty similar to sites like HackerRank & Topcoder which will rank your code written for a particular problem against the ones submitted by other users

People who use them

Leetcode gets primarily used for two use cases:

Purpose of this post

I never had a clear understanding when it comes to data structures and algorithms, so being a software engineer for the last 12 years, I thought it’s not a bad idea to at least start now. So as of Dec 2019, I became a premium member in Leetcode and committed myself to get as much value out of 150$ that I spent on the membership fees. Leetcode is like an ocean; it has closer to 2000+ questions, which keeps growing day by day.

In fact, this was my exact reaction when I open the website for the first time after looking at the number of questions and categories it had

Image for post

In this post, let me explain some of the methods I developed over some time, which helped me to understand and learn about these data structures & algorithms.

Get the basics right — Don’t run too fast

Image for post

Most people new to Leetcode directly jump into solving the problems without getting a proper understanding of the underlying data structures like a linked liststack, queue, tree, etc. Trust me this is a bad idea

I would recommend spending some time understanding these data structures, which are the building blocks for solving any problems.

Even if you are not able to go through all the data structures, at least get a strong understanding of the linked list and _binary trees. _Fortunately, there are some excellent materials created by Standford, which can help you with this:

Linked List:

Binary tree

Method to madness

Leetcode has many categories and a whole lot of questions in each of them, so it’s essential to come up with a method that could help you to understand these concepts. Learning with LeetCode is a long process, and it will take time, so one thing that I clearly understood is you have to keep the enthusiasm and eagerness to learn high if you want to go through the journey.

If you are a beginner, then use the below flowchart to learn things and gradually increase the complexity of the problems that you solve. It also helps in understanding the concepts well so you can reapply those techniques in the subsequent problems.

Image for post

Sequence for solving problems

Stages are numbers in red circles, and dotted lines are entirely optional for proceeding to the next stage. When you are done with stage 3 depending upon your motivation, you will end up either doing “Monthly coding challenges” or “attending interviews” (both are fun)

#coding #leetcode #data-structures #problem-solving #algorithms #algorithms

Lindsey  Koepp

Lindsey Koepp

1603763460

AWS Bottlerocket vs. Google Container-Optimized OS: Which Should You Use and When

What’s the difference between popular Container-Centric OS choices, Google’s Container-Optimized OS, and AWS’s Bottlerocket? The concepts underlying containers have been around for many years. Container technologies like Docker, Kubernetes, and an entire ecosystem of products, as well as best practices, have emerged in the last few years. This has enabled different kinds of applications to be containerized.

Web service providers like Amazon AWS and Google are giving a further boost to container innovation, for enterprises to adopt and use containers at scale. This will help them to reap the benefits containers bring, including increased portability and greater efficiency.

Linux-based OS, AWS Bottlerocket is a new option, designed for running containers on virtual machines (VMs) or bare-metal hosts. In this article, you will learn the core uses and differences between the two open-source OS.

**AWS Bottlerocket **

It is an open-source, stripped-down Linux distribution that’s similar to projects like Google’s Container-Optimized OS. This single-step update process helps reduce management overhead.

_It makes OS updates easy to automate using container orchestration services such as Amazon Elastic Container Service (ECS) and Amazon Elastic Kubernetes Service (EKS). _

**Google Container-Optimized OS **

It’s an OS image for Google Compute Engine VMs that’s optimized for running Docker containers. It allows you to bring up your Docker containers on Google Cloud Platform securely, and quickly. It is based on the open-source Chromium OS project and is maintained by Google.

But before diving into the core differences, let us give you a basic overview of containers, VMs, and container-optimized OS, and its underlying challenges to better understand the differences.

If you are already aware of all the underlying processes of containers, then you can skip to the main differences for AWS Bottlerocket vs Google Container-Optimized OS.

#containers #amazon-aws #google-cloud #container-optimized-os #aws-containers #docker-containers #linux-based-os #orchestration