teleren/devto huggingface dataset:
Grid Game
Tags: leetcode, dsa, theabbie
Published: 2022-06-16 20:30:47

You are given a **0-indexed** 2D array `grid` of size `2 x n`, where `grid[r][c]` represents the number of points at position `(r, c)` on the matrix. Two robots are playing a game on this matrix.

Both robots initially start at `(0, 0)` and want to reach `(1, n-1)`. Each robot may only move to the **right** (`(r, c)` to `(r, c + 1)`) or **down** (`(r, c)` to `(r + 1, c)`).

At the start of the game, the **first** robot moves from `(0, 0)` to `(1, n-1)`, collecting all the points from the cells on its path. For all cells `(r, c)` traversed on the path, `grid[r][c]` is set to `0`. Then, the **second** robot moves from `(0, 0)` to `(1, n-1)`, collecting the points on its path. Note that their paths may intersect with one another.

The **first** robot wants to **minimize** the number of points collected by the **second** robot. In contrast, the **second** robot wants to **maximize** the number of points it collects. If both robots play **optimally**, return _the **number of points** collected by the **second** robot._

**Example 1:**

![](https://assets.leetcode.com/uploads/2021/09/08/a1.png)

**Input:** grid = \[\[2,5,4\],\[1,5,1\]\]
**Output:** 4
**Explanation:** The optimal path taken by the first robot is shown in red, and the optimal path taken by the second robot is shown in blue.
The cells visited by the first robot are set to 0.
The second robot will collect 0 + 0 + 4 + 0 = 4 points.

**Example 2:**

![](https://assets.leetcode.com/uploads/2021/09/08/a2.png)

**Input:** grid = \[\[3,3,1\],\[8,5,2\]\]
**Output:** 4
**Explanation:** The optimal path taken by the first robot is shown in red, and the optimal path taken by the second robot is shown in blue.
The cells visited by the first robot are set to 0.
The second robot will collect 0 + 3 + 1 + 0 = 4 points.

**Example 3:**

![](https://assets.leetcode.com/uploads/2021/09/08/a3.png)

**Input:** grid = \[\[1,3,1,15\],\[1,3,3,1\]\]
**Output:** 7
**Explanation:** The optimal path taken by the first robot is shown in red, and the optimal path taken by the second robot is shown in blue.
The cells visited by the first robot are set to 0.
The second robot will collect 0 + 1 + 3 + 3 + 0 = 7 points.

**Constraints:**

*   `grid.length == 2`
*   `n == grid[r].length`
*   `1 <= n <= 5 * 104`
*   `1 <= grid[r][c] <= 105`

**SOLUTION:**

    class Solution:
        def gridGame(self, grid: List[List[int]]) -> int:
            n = len(grid[0])
            top = [0]
            bottom = [0]
            for el in grid[0]:
                top.append(top[-1] + el)
            for el in grid[1]:
                bottom.append(bottom[-1] + el)
            opponent = float('inf')
            mindex = None
            for i in range(n):
                curropp = max(top[-1] - top[i + 1], bottom[i])
                if curropp <= opponent:
                    opponent = curropp
                    mindex = i
            return max(top[-1] - top[mindex + 1], bottom[mindex])
What do red, blue, green functions mean in software development?
Published: 2022-06-16 20:25:02

In a PHP developer discussion group red, blue, green functions were often mentioned. To be honest, I never heard this before and didn't know what it meant. I did a search for "what mean green red blue functions". I did not find a simple explanation. The best I found was a blog article from a game developer. Unfortunately I did not understand his text. I hope there is a short and simple explanation of what is meant by this. Thank you!
Permutations
Tags: leetcode, dsa, theabbie
Published: 2022-06-16 20:00:53

Given an array `nums` of distinct integers, return _all the possible permutations_. You can return the answer in **any order**.

**Example 1:**

**Input:** nums = \[1,2,3\]
**Output:** \[\[1,2,3\],\[1,3,2\],\[2,1,3\],\[2,3,1\],\[3,1,2\],\[3,2,1\]\]

**Example 2:**

**Input:** nums = \[0,1\]
**Output:** \[\[0,1\],\[1,0\]\]

**Example 3:**

**Input:** nums = \[1\]
**Output:** \[\[1\]\]

**Constraints:**

*   `1 <= nums.length <= 6`
*   `-10 <= nums[i] <= 10`
*   All the integers of `nums` are **unique**.

**SOLUTION:**

    class Solution:
        def permute(self, nums: List[int]) -> List[List[int]]:
            n = len(nums)
            paths = [([num], {num}, 1) for num in nums]
            while paths[0][2] < n:
                curr, currSet, l = paths.pop(0)
                for num in nums:
                    if num not in currSet:
                        paths.append((curr + [num], currSet.union({num}), l + 1))
            return [perm[0] for perm in paths]
Best Interview Complement Ever
Tags: discuss, interview, jobsearch
Published: 2022-06-16 19:33:12

---
title: Best Interview Complement Ever
published: true
description: As an interviewee what's the best comment an interviewer has said to you?
tags: discuss, interview, jobsearch
# cover_image: https://direct_url_to_image.jpg
# Use a ratio of 100:42 for best results.
---

As an interviewee what's the kindest or most encouraging comment an interviewer has said to you?
Fizz Buzz
Tags: leetcode, dsa, theabbie
Published: 2022-06-16 19:30:41

Given an integer `n`, return _a string array_ `answer` _(**1-indexed**) where_:

*   `answer[i] == "FizzBuzz"` if `i` is divisible by `3` and `5`.
*   `answer[i] == "Fizz"` if `i` is divisible by `3`.
*   `answer[i] == "Buzz"` if `i` is divisible by `5`.
*   `answer[i] == i` (as a string) if none of the above conditions are true.

**Example 1:**

**Input:** n = 3
**Output:** \["1","2","Fizz"\]

**Example 2:**

**Input:** n = 5
**Output:** \["1","2","Fizz","4","Buzz"\]

**Example 3:**

**Input:** n = 15
**Output:** \["1","2","Fizz","4","Buzz","Fizz","7","8","Fizz","Buzz","11","Fizz","13","14","FizzBuzz"\]

**Constraints:**

*   `1 <= n <= 104`

**SOLUTION:**

    class Solution:
        def fizzBuzz(self, n: int) -> List[str]:
            return [[str(i), "Fizz", "Buzz", "FizzBuzz"][2 * int(i % 5 == 0) + int(i % 3 == 0)] for i in range(1, n + 1)]
Cracking a hashed password with hashcat
Tags: security, hacking
Published: 2022-06-16 19:16:58

### ... through a simple example of how this process works
Given a hashed password `$2y$12$Dwt1BZj6pcyc3Dy1FWZ5ieeUznr71EeNkJkUlypTsgbX1H68wsRom`, we have only one hint: **the password has four letters, all lowercase.**

### Let's start: finding the hash type
There are **a lot** of hashes out there. A good way to start guessing is to look at the hashed pass and try to find some kind of pattern. Here, the key is the first 4 characters of the hash.
There is a page where you can look at example hashes: https://hashcat.net/wiki/doku.php?id=example_hashes
**Noticed something?** We are looking for the _bcrypt $2*$, Blowfish (Unix)_. Our `$2y$` matches this pattern. So we are looking for a bcrypt hash. We also can grasp that the hash was generated using a factor of 12 (it is the number that comes after the first four characters).

### Let's crack!
First, it is important to know how the process works. Hashing is a process essentially different from encryption - you can only do it once. It means that we cannot _really_ recover the plaintext of a hashed password; instead, we can only compare its hash with our guesses. So, it's like hashing several words and seeing which of them matches exaclty our hash. Then, it must be the password.
We can automatize this process with two tools: `hashcat` and a dictionary of potential passwords. This kind of dictionary is easy to find on internet, so we are going to use [rock you](https://github.com/brannondorsey/naive-hashcat/releases/download/data/rockyou.txt).

Ok, so our dictionary is _very large_ and checking for each password, one by one, would be an expensive operation. But we already know how our password looks like, right? (four letters, all lowercase).
So, let's filter our dictionary a little bit by creating a file containing all the passwords that match our condition: 

`grep -x -E '[a-z][^0-9]{4}' rockyou.txt > candidates.txt`

Here we are using `grep` along with a regex expression to filter our potential passwords to only four-letters words without digits. The -x flag applies this expression to the whole line (our file contains one password per line), whereas the -E flag is needed because we are using an extended expression (due to the `{4}` part).

Now, we are ready to crack it with hashcat:

`hashcat -a 0 -m 3200 pass.txt candidates.txt --force`

Here, the code 3200 stands for the `bcrypt` hash, and our hashed pass is stored in pass.txt whereas the potential passwords are stored in candidates.txt.

After a few seconds (depending on your computer), we have the result:
`$2y$12$Dwt1BZj6pcyc3Dy1FWZ5ieeUznr71EeNkJkUlypTsgbX1H68wsRom:bleh`

Where the "bleh" is the password we were looking for.

~~_In sum: use a password manager :)_~~
Find Common Characters
Tags: leetcode, dsa, theabbie
Published: 2022-06-16 19:00:46

Given a string array `words`, return _an array of all characters that show up in all strings within the_ `words` _(including duplicates)_. You may return the answer in **any order**.

**Example 1:**

**Input:** words = \["bella","label","roller"\]
**Output:** \["e","l","l"\]

**Example 2:**

**Input:** words = \["cool","lock","cook"\]
**Output:** \["c","o"\]

**Constraints:**

*   `1 <= words.length <= 100`
*   `1 <= words[i].length <= 100`
*   `words[i]` consists of lowercase English letters.

**SOLUTION:**

    from collections import Counter
    
    class Solution:
        def commonChars(self, words: List[str]) -> List[str]:
            common = set.intersection(*[set(w) for w in words])
            ctrs = [Counter(w) for w in words]
            ans = []
            for c in common:
                ans += [c] * min([ctr[c] for ctr in ctrs])
            return ans
Go 1.19 beta1
Tags: go
Published: 2022-06-16 18:46:11

Compared to 1.18, 1.19 is not a big release, but something still catches my eye. 

## Memory Model
> The Go memory model has been revised to align Go with the memory model used by C, C++, Java, JavaScript, Rust, and Swift. Go only provides sequentially consistent atomics, not any of the more relaxed forms found in other languages

## Doc Comments
> support for links, lists, and clearer headings in doc comments

## Go runtime
### file descriptor
> automatically increase the open file limit (RLIMIT_NOFILE) to the maximum allowed value

### new env: GOMEMLIMIT 
> The runtime now includes support for a soft memory limit. This memory limit includes the Go heap and all other memory managed by the runtime, and excludes external memory sources such as mappings of the binary itself, memory managed in other languages, and memory held by the operating system on behalf of the Go program

it's possible to avoid/reduce OOM kill of golang app by env. Looking forward to reading [the GC guide](https://tip.golang.org/doc/gc-guide)
### self-adaptive initial stack size( before is fixed 2KB): 
    
> allocate initial goroutine stacks based on the historic average stack usage of goroutines 

   
## Compiler
> jump table for large integer and string switch statements. Performance improvements for the switch statement vary but can be on the order of 20% faster. (GOARCH=amd64 and GOARCH=arm64 only) 

modern CPUs do branch prediction for performance, but instead when the prediction fails too often, the performance becomes worse, introduce branchless(jump table) to avoid branch prediction to get better performance. 


IMHO go memory model and the GC guide worth to spend some time to read.
vcluster Becomes First Certified Kubernetes Distribution for Virtual
Tags: kubernetes, vcluster, devspace, loft
Published: 2022-06-16 18:32:05

By [Joseph Eckert](https://twitter.com/JeckertNY)

San Francisco - [Loft Labs](https://loft.sh/), which enables any organization to scale self-service access to Kubernetes to hundreds or even thousands of engineers, today announced that the latest version v0.3 of their open-source technology vcluster is now a certified Kubernetes distribution that [passes 100% of Kubernetes conformance tests](https://github.com/cncf/k8s-conformance/pull/1491#issuecomment-861816325).

[vcluster](https://vcluster.com) allows engineers to spin up lightweight, virtual Kubernetes clusters that run inside the namespaces of an underlying Kubernetes cluster. This approach reduces cluster sprawl, allows for more secure and better maintainable multi-tenancy, and aims for more efficient resource sharing, which ultimately saves a lot of infrastructure cost.

“Virtualizing Kubernetes is a very challenging technical problem,” said Fabian Kramm, CTO of Loft Labs. “And passing 100% of all Kubernetes conformance tests and getting certified is an additional challenge. Our goal is that virtual clusters are as close to real clusters as possible and users won’t even notice that they are running inside a virtual cluster. I like to think of it like trying to pass the [Turing Test](https://en.wikipedia.org/wiki/Turing_test) for Kubernetes.”

vcluster is stepping into the footsteps of an earlier project called k3v, which was a first proof-of-concept for virtualizing Kubernetes based on the popular k3s distribution. Both projects have been initiated by Darren Shepherd, Chief Architect at SUSE and former CTO of Rancher Labs.

Originally developed as a feature for Loft’s commercial product for self-service Kubernetes development environments, Loft Labs has open-sourced vcluster as a separate project in April 2021 to make it easier for other organizations to join the vision to virtualize Kubernetes. Since then, vcluster has gained considerable attention in the cloud-native community and gained the trust of large enterprises and thought leaders in the space.

“Being able to demonstrate Kubernetes compliance for virtual clusters is an important signal for existing and prospective users of vcluster because it ensures that users can seamlessly use all their favorite cloud-native tools with vcluster just like with any other certified Kubernetes distribution,” said Lukas Gentele, CEO of Loft Labs. “Since the launch of vcluster, we have seen users deploy virtual clusters and gain trust in our technology. Now with vcluster becoming a certified Kubernetes distro, organizations get another data point that will reinforce their confidence that virtual clusters are a technology they can use to deploy software at scale.”

David McKay from Equinix will be hosting the live session “[Hands-on Introduction to vcluster](https://www.youtube.com/watch?v=IMdMvn2_LeI)” today (Tuesday, June 22) at 1 pm Eastern time with Lukas Gentele and Rich Burroughs, senior developer advocate at Loft Labs.
Technology Operations Veteran Rich Burroughs Joins Loft Labs as Senior
Tags: kubernetes, vcluster, devspace, loft
Published: 2022-06-16 18:31:57

By [Joseph Eckert](https://twitter.com/JeckertNY)

Berkeley, California - Loft Labs, which makes Kubernetes easily accessible to developers, today announced that Rich Burroughs has joined the team as senior developer advocate.

With Loft, any Kubernetes cluster becomes a self-service platform where engineers can create namespaces and virtual clusters whenever they need them. At the same time, Loft's sleep mode and cluster sharing technologies help eliminate idle workloads and save cloud computing costs.

“I’m blown away by how much the Loft Labs team has built in a short period of time with just a few engineers,” said Burroughs. “What impresses me most is that the tools they’ve built help solve the real-world needs of developers in the enterprise while at the same time helping with demands placed on the operations and platform teams. That’s what really motivated me to join the team. When I saw what Loft is building, I recognized the potential to transform how organizations use Kubernetes: Today, in most organizations, only a hand-full of people have access to Kubernetes but with Loft, platform teams can give thousands of developers their own piece of Kubernetes while Loft securely isolates these users and their workloads.”

Burroughs brings extensive experience in technology operations and engineering and has spent the past few years in developer advocacy and community management. In his role as senior developer advocate, Burroughs will expand Loft’s existing user community and interact with the broader Kubernetes ecosystem to advocate for the need to advance the state of Kubernetes multi-tenancy and to improve the developer experience on top of Kubernetes.

Read Burroughs’ *[blog post](https://loft-sh.medium.com/meet-rich-burroughs-2d9c9d10146b)* for more information.

Loft is used by platform teams in enterprises to create internal Kubernetes platforms for developing cloud-native software, executing continuous integration/continuous delivery (CI/CD) pipelines, or running artificial intelligence (AI) and machine learning (ML) experiments. It is also valuable in production use cases, where IT teams use Loft’s virtual clusters to surpass the scalability limits of regular Kubernetes clusters and where companies need to provision full-blown demo environments or securely-isolated instances of their managed software products.

“Rich brings hands-on experience in building developer-focused user communities,” said Lukas Gentele, co-founder and CEO of Loft. “Like many other Kubernetes enthusiasts, I have been following Rich on [Twitter](https://twitter.com/richburroughs) myself and besides being a proven expert in the space, Rich also has this genuinely likable and empathetic way to interact with people. He will be the perfect person to expand our efforts in the areas of user education and community engagement around Loft as well as around our open-source projects [kiosk](https://kiosk.sh) and [DevSpace](https://devspace.sh).”
Implement Rand10() Using Rand7()
Tags: leetcode, dsa, theabbie
Published: 2022-06-16 18:30:35

Given the **API** `rand7()` that generates a uniform random integer in the range `[1, 7]`, write a function `rand10()` that generates a uniform random integer in the range `[1, 10]`. You can only call the API `rand7()`, and you shouldn't call any other API. Please **do not** use a language's built-in random API.

Each test case will have one **internal** argument `n`, the number of times that your implemented function `rand10()` will be called while testing. Note that this is **not an argument** passed to `rand10()`.

**Example 1:**

**Input:** n = 1
**Output:** \[2\]

**Example 2:**

**Input:** n = 2
**Output:** \[2,8\]

**Example 3:**

**Input:** n = 3
**Output:** \[3,8,10\]

**Constraints:**

*   `1 <= n <= 105`

**Follow up:**

*   What is the [expected value](https://en.wikipedia.org/wiki/Expected_value) for the number of calls to `rand7()` function?
*   Could you minimize the number of calls to `rand7()`?

**SOLUTION:**

    # The rand7() API is already defined for you.
    # def rand7():
    # @return a random integer in the range 1 to 7
    
    class Solution:
        def rand10(self):
            total = 0
            for _ in range(10):
                total += rand7()
            return 1 + total % 10
Guessing game code in Java
Tags: java, android, programming, biplob
Published: 2022-06-16 18:29:23

how to code java guessing game step by step

```
package com.java_android.android;
import java.util.Random;
import java.util.Scanner;

public class Android {
    public static void main(String[] args) {
//start from here
        System.out.println("welcome to our wonderland");
        System.out.println("Enter your name");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.next();
        System.out.println("Hello dear "+ name);

        System.out.println("Shall we start");
        System.out.println("\t yes");
        System.out.println("\t no");

        String answer = scanner.next();
//start game
        while(!(answer.equals("yes"))){
            System.out.println("Shall we start");
            System.out.println("\t1. yes");
            System.out.println("\t1. no");

             answer = scanner.next();
        }
        System.out.println("Let's get started");
        Random random = new Random();
        int number = random.nextInt(20);
        System.out.println("enter your guessing number");
        int guessNumber =  scanner.nextInt();

        int count = 0;
        boolean hasWon = false;
        boolean guessStop = false;
        while(!guessStop){
            count++;
            if(count<5){
                if(guessNumber == number){
                    hasWon = true;
                    guessStop = true;
                }else if(guessNumber>number){
                    System.out.println("Your nubmer is greater than the number, try again");
                     guessNumber =  scanner.nextInt();
                }
                else{
                    System.out.println("Your number is less than the number,try again");
                     guessNumber =  scanner.nextInt();
                }
            }else{
                guessStop = true;
            }
        }
        if(hasWon){
            System.out.println("congratulations! your timestamp is " + count);

        }else {
            System.out.println("game over! you have tried "+ count + " times");
        }
    }
}

```
Kubernetes 1.22 Release
Tags: kubernetes, vcluster, devspace, loft
Published: 2022-06-16 18:28:40

By [Rich Burroughs](https://twitter.com/richburroughs)

Today the [1.22 version of Kubernetes](https://kubernetes.io/blog/2021/08/04/kubernetes-1-22-release-announcement/) ships. As always, hats off to the members of [SIG Release](https://github.com/kubernetes/sig-release) for all of their hard work.

There are many changes, but the top one to note is the API deprecations included in the release. There’s a [great post on the Kubernetes blog](https://kubernetes.io/blog/2021/07/14/upcoming-changes-in-kubernetes-1-22/) from Krishna Kilari and Tim Bannister that explains which APIs are deprecated. The post also lays out some great strategies for navigating those changes, including advice on testing the upgrade. There’s also a handy [Kubernetes Deprecated API Migration Guide](https://kubernetes.io/docs/reference/using-api/deprecation-guide/#migrate-to-non-deprecated-apis). Even if you’re not upgrading to 1.22 right away, you’ll likely need to deal with these API changes at some point, so it’s good to start thinking about it. I learned about `kubectl convert` from Krishna and Tim’s post, which is super cool.

There are lots of other chages in 1.22, including: enabling seccomp by default (yay security!), a new alpha feature that allows running the kubeadm control plane as a non-root user, a new memory management alpha feature that uses cgroups v2, and an alpha feature to use swap on nodes. I’m especially excited about the change enabling seccomp. It’s one of the things people typically do when they harden clusters, but by making the defaults more secure, we make things a lot better for newer folks who are using Kubernetes.

You can read the full [release notes here](https://github.com/kubernetes/kubernetes/blob/master/CHANGELOG/CHANGELOG-1.22.md). Víctor Jiménez Cerrada and the team at Sysdig also did a [great writeup of the release](https://sysdig.com/blog/kubernetes-1-22-whats-new/), including their favorite new features. And there's a [very cool Twitter thread](https://twitter.com/jrrickard/status/1422921901408546820?s=20) that Jeremy Rickard started to shout out folks who contributed to the release.

Thanks to everyone who contributed, and to the many folks who work to keep the Kubernetes project moving forward.
[Solved] GitLab Runner : ERROR: Job failed: prepare environment: Process exited with status 1. Check...
Tags: gitlab, ci, runner, jobs
Published: 2022-06-16 18:12:58

If you are getting following error in your when running gitlab ci/cd job via `gitlab-runner`:


```
ERROR: Job failed: prepare environment: Process exited with status 1. 
Check https://docs.gitlab.com/runner/shells/index.html#shell-profile-loading 
for more information
```

**Solution**

Run following command:
```
find / -name .bash_logout
```

and delete following files if exist

```
sudo rm -r /home/gitlab-runner/.bash_logout
sudo rm -r /home/<username>/.bash_logout
```

Try to re-run the jobs it should be working.


**Read More at: [Common Gitlab Runner errors and solutions](https://dev.to/themodernpk/gitlab-runner-errors-and-solutions-158d)**