teleren/devto huggingface dataset:
Most Frequent Number Following Key In an Array
Tags: leetcode, dsa, theabbie
Published: 2022-06-03 07:00:46

You are given a **0-indexed** integer array `nums`. You are also given an integer `key`, which is present in `nums`.

For every unique integer `target` in `nums`, **count** the number of times `target` immediately follows an occurrence of `key` in `nums`. In other words, count the number of indices `i` such that:

*   `0 <= i <= nums.length - 2`,
*   `nums[i] == key` and,
*   `nums[i + 1] == target`.

Return _the_ `target` _with the **maximum** count_. The test cases will be generated such that the `target` with maximum count is unique.

**Example 1:**

**Input:** nums = \[1,100,200,1,100\], key = 1
**Output:** 100
**Explanation:** For target = 100, there are 2 occurrences at indices 1 and 4 which follow an occurrence of key.
No other integers follow an occurrence of key, so we return 100.

**Example 2:**

**Input:** nums = \[2,2,2,2,3\], key = 2
**Output:** 2
**Explanation:** For target = 2, there are 3 occurrences at indices 1, 2, and 3 which follow an occurrence of key.
For target = 3, there is only one occurrence at index 4 which follows an occurrence of key.
target = 2 has the maximum number of occurrences following an occurrence of key, so we return 2.

**Constraints:**

*   `2 <= nums.length <= 1000`
*   `1 <= nums[i] <= 1000`
*   The test cases will be generated such that the answer is unique.

**SOLUTION:**

    class Solution:
        def mostFrequent(self, nums: List[int], key: int) -> int:
            n = len(nums)
            ctr = {}
            for i in range(n):
                if nums[i] == key:
                    if i < n - 1:
                        ctr[nums[i + 1]] = ctr.get(nums[i + 1], 0) + 1
            return max((v, k) for k, v in ctr.items())[1]
Can Place Flowers
Tags: leetcode, dsa, theabbie
Published: 2022-06-03 08:00:44

You have a long flowerbed in which some of the plots are planted, and some are not. However, flowers cannot be planted in **adjacent** plots.

Given an integer array `flowerbed` containing `0`'s and `1`'s, where `0` means empty and `1` means not empty, and an integer `n`, return _if_ `n` new flowers can be planted in the `flowerbed` without violating the no-adjacent-flowers rule.

**Example 1:**

**Input:** flowerbed = \[1,0,0,0,1\], n = 1
**Output:** true

**Example 2:**

**Input:** flowerbed = \[1,0,0,0,1\], n = 2
**Output:** false

**Constraints:**

*   `1 <= flowerbed.length <= 2 * 104`
*   `flowerbed[i]` is `0` or `1`.
*   There are no two adjacent flowers in `flowerbed`.
*   `0 <= n <= flowerbed.length`

**SOLUTION:**

    class Solution:
        def canPlaceFlowers(self, flowerbed: List[int], n: int) -> bool:
            fn = len(flowerbed)
            for i in range(fn):
                if flowerbed[i] == 0:
                    isValid = True
                    if i > 0 and flowerbed[i - 1] == 1:
                        isValid = False
                    if i < fn - 1 and flowerbed[i + 1] == 1:
                        isValid = False
                    if isValid:
                        flowerbed[i] = 1
                        n = max(n - 1, 0)
            return n == 0
Enjoy Programming-Themed Humor? Here's today's daily developer joke!
Tags: jokes, dailydeveloperjokes
Published: 2022-06-03 08:00:05

---
title: "Enjoy Programming-Themed Humor? Here's today's daily developer joke!"
description: "Check out today's daily developer joke! (a project by Fred Adams at xtrp.io)"
series: "Daily Developer Jokes"
published: true
tags: #jokes, #dailydeveloperjokes
---

Hi there! Here's today's Daily Developer Joke. We hope you enjoy it; it's a good one.

![Joke Image](https://private.xtrp.io/projects/DailyDeveloperJokes/public_image_server/images/5e1258cecd22f.png)

---

For more jokes, and to submit your own joke to get featured, check out the [Daily Developer Jokes Website](https://dailydeveloperjokes.github.io/). We're also open sourced, so feel free to view [our GitHub Profile](https://github.com/dailydeveloperjokes).

### Leave this post a ❤️ if you liked today's joke, and stay tuned for tomorrow's joke too!

_This joke comes from [Dad-Jokes GitHub Repo by Wes Bos](https://github.com/wesbos/dad-jokes) (thank you!), whose owner has given me permission to use this joke with credit._

<!--
Joke text:
___Q:___ Why did the computer squeak?

___A:___ Because someone stepped on its mouse!
 -->
:is() pseudo class
Tags: webdev, css, javascript, programming
Published: 2022-06-03 07:53:14

**:is() CSS pseudo-class function** takes a selector list as its argument, and selects any element that can be selected by one of the selectors in that list. This is useful for writing large selectors in a more compact form.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qnq14rkwwlg907va7ki7.png)
 
All though it is not yet supported by all versions of browsers.
 
**fact :matches() renamed as :is()**
Migrate from PostgreSQL to MySQL using Slick (Scala)
Tags: scala, mysql, slick, postgres
Published: 2022-06-03 07:35:49

For my rather long engineering career, I did several migrations from one database to another. Usually, I dealt with cases like switching from SQL- to non-SQL or vice versa. This time I had an interesting case of migrating from Postgres to MySQL.

For a rather small database (of 14 GBs of size) where we do not use anything special from what PostgreSQL can provide, I did not expect to face any kind of issues. Sure, some SQL queries in Scala code must be adapted to follow the MySQL syntax, but other than that it was expected to run smoothly.

Even though, making the code producing correct data for MySQL was rather easy, I faced some difficulties with adopting it for be compatible with existing data and especially **timestamps**.

I was surprised to learn that timestamps produced by Slick in MySQL and PostreSQL have different format. In any case, we use [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format to store timestamps for both [MySQL](https://dev.mysql.com/doc/refman/8.0/en/datetime.html) and [PostreSQL](https://www.postgresql.org/docs/current/datatype-datetime.html). So, store such data in the default format like this:

```
2022-03-11 21:59:00
```

That means that after the migration, the MySQL compatible code must read and produce the same data, however that did not happen. Instead, the code produced this:

```
2022-03-11T21:59:00Z
```

After checking the [official Slick documentation](https://books.underscore.io/essential-slick/essential-slick-3.html#date-and-time-methods) regarding working with 'Date and Time' we can see, that Slick  saves data as `TIMESTAMP` for PostgreSQL and as `TEXT` for MySQL. In the end that should not be the issue. [Custom column mapping](https://books.underscore.io/essential-slick/essential-slick-3.html#custom-column-mappings) should help us convert the data from one type to another. Unfortunately that did not work out. Basically, it did not make any changes.

The answer and actually, the final solution, I found in the [migration guide from 3.2 to 3.3](https://scala-slick.org/doc/3.3.3/upgrade.html#support-for-java.time-columns) that states that custom mappind does not work for dates and suggests to adjust the `Profile` class directly. That was my way to go - create a new `Profile` class based on `slick.jdbc.MySQLProfile` and copy the logic regarding `instantType` from `PostgreSQLProfile`. This way I managed to be absolutely compatible with timestamps produced by MySQL version of Slick. The rest data types worked well out of the box.

Cheers.
Longest Word in Dictionary through Deleting
Tags: leetcode, dsa, theabbie
Published: 2022-06-03 07:30:41

Given a string `s` and a string array `dictionary`, return _the longest string in the dictionary that can be formed by deleting some of the given string characters_. If there is more than one possible result, return the longest word with the smallest lexicographical order. If there is no possible result, return the empty string.

**Example 1:**

**Input:** s = "abpcplea", dictionary = \["ale","apple","monkey","plea"\]
**Output:** "apple"

**Example 2:**

**Input:** s = "abpcplea", dictionary = \["a","b","c"\]
**Output:** "a"

**Constraints:**

*   `1 <= s.length <= 1000`
*   `1 <= dictionary.length <= 1000`
*   `1 <= dictionary[i].length <= 1000`
*   `s` and `dictionary[i]` consist of lowercase English letters.

**SOLUTION:**

    class Solution:
        def findLongestWord(self, s: str, dictionary: List[str]) -> str:
            words = {}
            for word in dictionary:
                if len(word) <= len(s):
                    i = 0
                    j = 0
                    while i < len(word) and j < len(s):
                        if word[i] == s[j]:
                            i += 1
                            j += 1
                        else:
                            j += 1
                    if i == len(word):
                        words[len(word)] = words.get(len(word), []) + [word]
            if len(words) == 0:
                return ""
            return min(words[max(words.keys())])
Rings and Rods | Leetcode Problem Solution Using Bit Manipulation
Tags: leetcode, competitiveprogramming, algorithms, cpp
Published: 2022-06-03 07:19:58

## Problem Statement
There are n rings and each ring is either red, green, or blue. The rings are distributed across ten rods labeled from 0 to 9.

You are given a string **rings** of length **2n** that describes the n rings that are placed onto the rods. Every two characters in rings forms a **color-position pair** that is used to describe each ring where:

- The **first character** of the ith pair denotes the ith ring's color ('R', 'G', 'B').
- The **second character** of the ith pair denotes the rod that the ith ring is placed on ('0' to '9').

For example, "R3G2B1" describes n == 3 rings: a red ring placed onto the rod labeled 3, a green ring placed onto the rod labeled 2, and a blue ring placed onto the rod labeled 1.

Return the **number of rods** that have all three colors of rings on them.

**Sample Input**
B0B6G0R6R0R6G9

**Sample Output**
1

**Explanation**

- The rod labeled 0 holds 3 rings with all colors: red, green, and blue.
- The rod labeled 6 holds 3 rings, but it only has red and blue.
- The rod labeled 9 holds only a green ring.
Thus, the number of rods with all three colors is 1.

**_Link to question:_** [https://leetcode.com/problems/rings-and-rods/](https://leetcode.com/problems/rings-and-rods/)

## Solution (C++)

```
class Solution {
    public int countPoints(String rings) {
        int count, n=rings.length();
        int rods[]=new int[10];
        Arrays.fill(rods, 0);
        for(int i=0; i<n; i+=2) {
            char color=rings.charAt(i);
            int rod=rings.charAt(i+1)-48;
            switch(color) {
                case 'R':
                    rods[rod]=rods[rod] | 1;
                    break;
                case 'G':
                    rods[rod]=rods[rod] | 2;
                    break;
                case 'B':
                    rods[rod]=rods[rod] | 4;
                    break;
            }
        }
        count=0;
        for(int item: rods)
            count+=item==7?1:0;
        return count;
    }
};
```
Project ideas!!! (Frustrated)
Tags: webdev, programming, react, python
Published: 2022-06-03 07:09:09

I'm pretty frustrated about this lately, I want to develop something out of the box, but all I see on the internet is the good old ToDo app or some clone. Please suggest some ideas I can start developing as a side project.


Edit - I got to thinking, and instead of going for a full-stack project, I thought of implementing a data structure Trie which I think is fairly complex; in JavaScript and by making an autocomplete feature with it. Tell me how you like this idea.
Linux interne communication
Tags: linux, programming, kernel, architecture
Published: 2022-06-03 06:32:50

Hi all,

After a little break here my new article. This time we go a step deeper in linux functionality with the pipe concept. Most of the linux user know this command | But did you know you can use this concept to create an internal process communication?

[blog page here](https://fredlagage.fr/pipe-linux-uname/)
Sort Integers by The Number of 1 Bits
Tags: leetcode, dsa, theabbie
Published: 2022-06-03 06:30:34

You are given an integer array `arr`. Sort the integers in the array in ascending order by the number of `1`'s in their binary representation and in case of two or more integers have the same number of `1`'s you have to sort them in ascending order.

Return _the array after sorting it_.

**Example 1:**

**Input:** arr = \[0,1,2,3,4,5,6,7,8\]
**Output:** \[0,1,2,4,8,3,5,6,7\]
**Explantion:** \[0\] is the only integer with 0 bits.
\[1,2,4,8\] all have 1 bit.
\[3,5,6\] have 2 bits.
\[7\] has 3 bits.
The sorted array by bits is \[0,1,2,4,8,3,5,6,7\]

**Example 2:**

**Input:** arr = \[1024,512,256,128,64,32,16,8,4,2,1\]
**Output:** \[1,2,4,8,16,32,64,128,256,512,1024\]
**Explantion:** All integers have 1 bit in the binary representation, you should just sort them in ascending order.

**Constraints:**

*   `1 <= arr.length <= 500`
*   `0 <= arr[i] <= 104`

**SOLUTION:**

    class Solution:
        def sortByBits(self, arr: List[int]) -> List[int]:
            p = 25
            buckets = [[] for i in range(p)]
            for num in arr:
                curr = num
                onebits = 0
                while curr > 0:
                    if curr % 2 == 1:
                        onebits += 1
                    curr //= 2
                buckets[onebits].append(num)
            op = []
            for b in buckets:
                op += sorted(b)
            return op
How to hide scrollbar on your element in TailwindCSS
Tags: tailwindcss, react, webdev, tutorial
Published: 2022-06-03 06:21:02

Hi there👋,

You don't want your UI to look like this?

![Before](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3tyntxlog752mkjr0an2.png)

Here are two steps to follow in order to hide a `scrollbar` in your HTML elements using TailwindCss.

## Step I
 Go to your `global.css` file `styles/global.css` and past this code:

```javascript
//global index.css
@tailwind base;
@tailwind components;
@tailwind utilities;

// add the code bellow
@layer utilities {
      /* Hide scrollbar for Chrome, Safari and Opera */
      .no-scrollbar::-webkit-scrollbar {
          display: none;
      }
     /* Hide scrollbar for IE, Edge and Firefox */
      .no-scrollbar {
          -ms-overflow-style: none;  /* IE and Edge */
          scrollbar-width: none;  /* Firefox */
    }
  }
```

> At this point we added `::-webkit-scrollbar` to target the scrollbar style in `Chrome`,` Safari`, `Edge` and `Opera`.
 
 
`no-scrollbar` is the class that we are going to use for hidding the scrollbar.

## Step II
Now use `no-scrollbar` to hide the scrollbar in your elements. Like this:
```javascript
<div className="w-full h-42 overflow-y-scroll no-scrollbar">...</div>
```

## Result
![After](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cz4vanzallca0k2pk5ya.png)

I hope you find this post useful.

Feel free to connect with me on [Twitter](https://twitter.com/Derickzihalirw5)
Seamless Integration with Remote Docker Hosts for Development
Tags: docker, mac, apple, engineering
Published: 2022-06-13 19:57:11

---
title: Seamless Integration with Remote Docker Hosts for Development
published: true
date: 2022-06-03 06:02:27 UTC
tags: docker,mac,apple,engineering
canonical_url: https://medium.com/geekculture/seamless-integration-with-remote-docker-hosts-for-development-7a369d94812f
---

[![](https://cdn-images-1.medium.com/max/917/1*ao4tbseGZYAKTYlny-QOWw.png)](https://medium.com/geekculture/seamless-integration-with-remote-docker-hosts-for-development-7a369d94812f?source=rss-299466747366------2)

Let’s go over the steps required to achieve seamless integration between your local environment and a remote Docker host!

This way of working can be extremely useful in scenarios where Docker performance is lackluster on the local OS (Docker works best on **Linux**), or even more so when we’re forced to work with images that are not natively compatible with the local CPU architecture (looking at you, **Macbook Pro M1**!).

[Continue reading on Geek Culture »](https://medium.com/geekculture/seamless-integration-with-remote-docker-hosts-for-development-7a369d94812f?source=rss-299466747366------2)
Minimum Depth of Binary Tree
Tags: leetcode, dsa, theabbie
Published: 2022-06-03 06:00:45

Given a binary tree, find its minimum depth.

The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.

**Note:** A leaf is a node with no children.

**Example 1:**

![](https://assets.leetcode.com/uploads/2020/10/12/ex_depth.jpg)

**Input:** root = \[3,9,20,null,null,15,7\]
**Output:** 2

**Example 2:**

**Input:** root = \[2,null,3,null,4,null,5,null,6\]
**Output:** 5

**Constraints:**

*   The number of nodes in the tree is in the range `[0, 105]`.
*   `-1000 <= Node.val <= 1000`

**SOLUTION:**

    # Definition for a binary tree node.
    # class TreeNode:
    #     def __init__(self, val=0, left=None, right=None):
    #         self.val = val
    #         self.left = left
    #         self.right = right
    class Solution:
        def minDepth(self, root: Optional[TreeNode]) -> int:
            if root:
                a = self.minDepth(root.left)
                b = self.minDepth(root.right)
                if a == 0 or b == 0:
                    return a + b + 1
                return 1 + min(a, b)
            return 0
How to hide content conditionally in js?
Published: 2022-06-03 05:50:13

I have two dropdowns.
First with A, B, C and second with D, E, F, G. Next only after selecting the options from first and second dropdowns I am able to select the content which is a list of checkboxes. 
Now I want to hide my content until user selects the option from first and second dropdown. Till now I have made it unselectable until user selects options from both the dropdowns, but now I want to hide it. As soon as the user selects options from first and second dropdowns the content should appear.

#reactjs #discuss
Longest Increasing Subsequence
Tags: leetcode, dsa, theabbie
Published: 2022-06-03 05:30:40

Given an integer array `nums`, return the length of the longest strictly increasing subsequence.

A **subsequence** is a sequence that can be derived from an array by deleting some or no elements without changing the order of the remaining elements. For example, `[3,6,2,7]` is a subsequence of the array `[0,3,1,6,2,2,7]`.

**Example 1:**

**Input:** nums = \[10,9,2,5,3,7,101,18\]
**Output:** 4
**Explanation:** The longest increasing subsequence is \[2,3,7,101\], therefore the length is 4.

**Example 2:**

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

**Example 3:**

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

**Constraints:**

*   `1 <= nums.length <= 2500`
*   `-104 <= nums[i] <= 104`

**Follow up:** Can you come up with an algorithm that runs in `O(n log(n))` time complexity?

**SOLUTION:**

    class Solution:
        def lis(self, nums, i):
            if i == 0:
                return 1
            if self.cache[i] != -1:
                return self.cache[i]
            mlen = 1
            for j in range(i):
                if nums[j] < nums[i]:
                    curr = 1 + self.lis(nums, j)
                    mlen = max(mlen, curr)
            self.cache[i] = mlen
            return mlen
        
        def lengthOfLIS(self, nums: List[int]) -> int:
            n = len(nums)
            self.cache = [-1] * n
            mlen = 1
            for i in range(n):
                curr = self.lis(nums, i)
                mlen = max(mlen, curr)
            return mlen
Perfect Number
Tags: leetcode, dsa, theabbie
Published: 2022-06-03 05:00:48

A [**perfect number**](https://en.wikipedia.org/wiki/Perfect_number) is a **positive integer** that is equal to the sum of its **positive divisors**, excluding the number itself. A **divisor** of an integer `x` is an integer that can divide `x` evenly.

Given an integer `n`, return `true` _if_ `n` _is a perfect number, otherwise return_ `false`.

**Example 1:**

**Input:** num = 28
**Output:** true
**Explanation:** 28 = 1 + 2 + 4 + 7 + 14
1, 2, 4, 7, and 14 are all divisors of 28.

**Example 2:**

**Input:** num = 7
**Output:** false

**Constraints:**

*   `1 <= num <= 108`

**SOLUTION:**

    class Solution:
        def getFactors(self, n, factors):
            for i in range(n - 1, 0, -1):
                if i not in factors and n % i == 0:
                    factors.update({i})
                    factors.update({n//i})
                    self.getFactors(i, factors)
        
        def checkPerfectNumber(self, num: int) -> bool:
            fsum = 1
            i = 2
            while i * i <= num:
                if num % i == 0:
                    fsum = fsum + i + num//i
                i += 1
            return (True if fsum == num and num!=1 else False)
Decompress Run-Length Encoded List
Tags: leetcode, dsa, theabbie
Published: 2022-06-03 04:30:41

We are given a list `nums` of integers representing a list compressed with run-length encoding.

Consider each adjacent pair of elements `[freq, val] = [nums[2*i], nums[2*i+1]]` (with `i >= 0`).  For each such pair, there are `freq` elements with value `val` concatenated in a sublist. Concatenate all the sublists from left to right to generate the decompressed list.

Return the decompressed list.

**Example 1:**

**Input:** nums = \[1,2,3,4\]
**Output:** \[2,4,4,4\]
**Explanation:** The first pair \[1,2\] means we have freq = 1 and val = 2 so we generate the array \[2\].
The second pair \[3,4\] means we have freq = 3 and val = 4 so we generate \[4,4,4\].
At the end the concatenation \[2\] + \[4,4,4\] is \[2,4,4,4\].

**Example 2:**

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

**Constraints:**

*   `2 <= nums.length <= 100`
*   `nums.length % 2 == 0`
*   `1 <= nums[i] <= 100`

**SOLUTION:**

    class Solution:
        def decompressRLElist(self, nums: List[int]) -> List[int]:
            n = len(nums)
            op = []
            for i in range(0, n, 2):
                op.extend([nums[i + 1]] * nums[i])
            return op
Google Dorks to make your search more effective
Published: 2022-06-03 04:39:22

Google search is one of the most commonly used internet services in our daily lives. You can filter down search results by using dorking. The following is a collection of frequent dork strings.
<br>

## site:
`<Search String> site:<Site Domain>`
To only show the result from that specific site.
![site:](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ma6m9nsz4plz0cpxj19f.png)
<br>

## allinurl: / inurl:
`site:<Site Domain> allinurl:<string>`
`site:<Site Domain> inurl:<keyword>`
Filter out results whose URL contains the specified characters
![inurl:](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cehrile7l7ge46kw5l4p.png)
<br>

## intext:
`site:<Site Domain> intext:<keyword>`
Sort Document with a specifict text in it from a specific site.
![intext:](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w7n7dvvo4zg4r7dovi49.png)

## intitle:
`site:<Site Domain> intitle:<keyword>`
Find webpage according to the title.
![intitle:](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a1v5x5c67fq783nsa2cn.png)

![intitle:](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dlc17a0piy83v59ujgzf.png) 
 
## filetype:
`site:<Site Domain> filetype:<keyword>`
![filetype:](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iyyk03178l1v7qb12ltc.png)

You can do a whole lot of thing with filetype: but careful.
![filetype:env](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ifhxr6gjsejdszkv70ta.png)

![filetype:log](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vvo3crbs21rume04nidt.png)

![filetype:reg](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3sx9wqdtxjqu6h6enur6.png)
 
You can find a whole lot of google dorks [here](https://www.exploit-db.com/google-hacking-database)