teleren/devto huggingface dataset:
Maximum Erasure Value
Tags: leetcode, dsa, theabbie
Published: 2022-06-19 02:00:46

You are given an array of positive integers `nums` and want to erase a subarray containing **unique elements**. The **score** you get by erasing the subarray is equal to the **sum** of its elements.

Return _the **maximum score** you can get by erasing **exactly one** subarray._

An array `b` is called to be a subarray of `a` if it forms a contiguous subsequence of `a`, that is, if it is equal to `a[l],a[l+1],...,a[r]` for some `(l,r)`.

**Example 1:**

**Input:** nums = \[4,2,4,5,6\]
**Output:** 17
**Explanation:** The optimal subarray here is \[2,4,5,6\].

**Example 2:**

**Input:** nums = \[5,2,1,2,5,2,1,2,5\]
**Output:** 8
**Explanation:** The optimal subarray here is \[5,2,1\] or \[1,2,5\].

**Constraints:**

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

**SOLUTION:**

    class Solution:
        def maximumUniqueSubarray(self, nums: List[int]) -> int:
            n = len(nums)
            msum = 0
            p = [0]
            for el in nums:
                p.append(p[-1] + el)
            prev = {}
            i = 0
            for j in range(n):
                if nums[j] in prev:
                    i = max(i, prev[nums[j]] + 1)
                msum = max(msum, p[j + 1] - p[i])
                prev[nums[j]] = j
            return msum
Balance a Binary Search Tree
Tags: leetcode, dsa, theabbie
Published: 2022-06-19 01:30:42

Given the `root` of a binary search tree, return _a **balanced** binary search tree with the same node values_. If there is more than one answer, return **any of them**.

A binary search tree is **balanced** if the depth of the two subtrees of every node never differs by more than `1`.

**Example 1:**

![](https://assets.leetcode.com/uploads/2021/08/10/balance1-tree.jpg)

**Input:** root = \[1,null,2,null,3,null,4,null,null\]
**Output:** \[2,1,3,null,null,null,4\]
**Explanation:** This is not the only correct answer, \[3,1,4,null,2\] is also correct.

**Example 2:**

![](https://assets.leetcode.com/uploads/2021/08/10/balanced2-tree.jpg)

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

**Constraints:**

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

**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 inorder(self, root):
            if root:
                self.inorder(root.left)
                self.tree.append(root.val)
                self.inorder(root.right)
                
        def arrToTree(self, arr, i, j):
            if i <= j - 1:
                root = TreeNode()
                mid = (i + j) // 2
                root.val = arr[mid]
                root.left = self.arrToTree(arr, i, mid)
                root.right = self.arrToTree(arr, mid + 1, j)
                return root
            return None
        
        def balanceBST(self, root: TreeNode) -> TreeNode:
            self.tree = []
            self.inorder(root)
            return self.arrToTree(self.tree, 0, len(self.tree))
Smallest String With Swaps
Tags: leetcode, dsa, theabbie
Published: 2022-06-19 01:00:46

You are given a string `s`, and an array of pairs of indices in the string `pairs` where `pairs[i] = [a, b]` indicates 2 indices(0-indexed) of the string.

You can swap the characters at any pair of indices in the given `pairs` **any number of times**.

Return the lexicographically smallest string that `s` can be changed to after using the swaps.

**Example 1:**

**Input:** s = "dcab", pairs = \[\[0,3\],\[1,2\]\]
**Output:** "bacd"
**Explaination:** 
Swap s\[0\] and s\[3\], s = "bcad"
Swap s\[1\] and s\[2\], s = "bacd"

**Example 2:**

**Input:** s = "dcab", pairs = \[\[0,3\],\[1,2\],\[0,2\]\]
**Output:** "abcd"
**Explaination:** 
Swap s\[0\] and s\[3\], s = "bcad"
Swap s\[0\] and s\[2\], s = "acbd"
Swap s\[1\] and s\[2\], s = "abcd"

**Example 3:**

**Input:** s = "cba", pairs = \[\[0,1\],\[1,2\]\]
**Output:** "abc"
**Explaination:** 
Swap s\[0\] and s\[1\], s = "bca"
Swap s\[1\] and s\[2\], s = "bac"
Swap s\[0\] and s\[1\], s = "abc"

**Constraints:**

*   `1 <= s.length <= 10^5`
*   `0 <= pairs.length <= 10^5`
*   `0 <= pairs[i][0], pairs[i][1] < s.length`
*   `s` only contains lower case English letters.

**SOLUTION:**

    from collections import defaultdict
    
    class Solution:
        def dfs(self, graph, node, visited):
            for j in graph[node]:
                if j not in visited:
                    visited.add(j)
                    self.dfs(graph, j, visited)
        
        def smallestStringWithSwaps(self, s: str, pairs: List[List[int]]) -> str:
            op = list(s)
            graph = defaultdict(list)
            for a, b in pairs:
                graph[a].append(b)
                graph[b].append(a)
            globalvisited = set()
            for x in graph:
                if x not in globalvisited:
                    currvisited = {x}
                    self.dfs(graph, x, currvisited)
                    indexes = sorted(currvisited)
                    indexes_asc = sorted(currvisited, key = lambda p: s[p])
                    n = len(indexes)
                    for i in range(n):
                        op[indexes[i]] = s[indexes_asc[i]]
                    globalvisited.update(currvisited)
            return "".join(op)
MakeMeFamous🤩.md
Tags: beginners, javascript, productivity, career
Published: 2022-06-19 00:20:55

Hi 👋, If you have opened this post, for sure the word **FAMOUS** must have caught your attention.
I know, you want to be get recognize on the internet 🌐 and wants to be famous like me 😁. Everybody wants to be...


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pmnv2ygjuzv7jk1szbva.gif)
So today, I will discuss two things which definitely gonna make your work more enjoyable and will answer you for what you came here.

But wait 🤚, before starting I want to first make you understand what I meant by **Famous**.

```text
Getting recognize in your community by SHARING your work COSISTENTLY 🔥.
```
SOo...

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n83cpo2j9p68gmqk5cbj.gif)

This blog will not tell you the recipe to become famous but will give you enough reasons to share your work consistently.

## 🤔 Why you should care about getting recognize❓

1. 🔗 Opportunity to build more connections : It's very organic way to connect with like minded geeks 😉.
2. 💰  Earning while learning
3. 🧠 Helps you to learn better
4. 💡 Better clarity on your ideas
5. 🔥  Always motivated to learn new 



## 🛠 How you can be recognized❓

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pexxlbe3ukvvc1x34a8z.gif)

#### 1. ✏️ Share what you are learning: 

It's normal if you are not perfect. Your are gonna enjoy if you keep recording your mistakes and look back at in future.
#### 2. ❌ Never let your though get waste: 

In entire day we get lots of thoughts. Like when I sit idle. My mind always comes across thoughts like 📈 Opening a Codding Channel on YouTube and hitting million subscribers,  ✍ Writing blogs everyday,  💰 Earning millions by doing freelancing,  🦸‍♂️ Saving life of everyone, specially girls 😅. When terrorist attacks 💣 the college,  🐱‍💻 Hacking Google and Nasa 🚀 just using my left hand.

I know some of the  are  crazy but there are also billion dollars among them. So never let your thought get waste. You can use Google Keep Extension to store every thought 💭. 
#### 3. 🔃 Always work on the feedback: 

Never ignore feedback.. Those who give feedback are the most loyal and trustworthy people among all in the community. Even if they are criticizing your work... be humble and thankful to them, as they are spending their time on you.
#### 4. 🙃 Be honest with your work

Even nobody is watching your work... be honest with your self. Remember if you studied entire year and worked hard then enjoying last night will not gonna change the result but if you didn't studied entire year and waking whole night for preparing the exam... it still not gonna change the result.


Now since you have came so far... let others know, What you think about getting "Famous" ? Is it good to think about it begin a developer, or just I am not behaving normal 😂? **Comments your View 👇**

[![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sbsr5llaa28txqia1ah3.png)](https://bio.link/heydrdev)
Como remover arquivos de um repositório no git - linha de comando
Tags: womenintech, braziliandevs, git
Published: 2022-06-19 00:19:33

Vamos imaginar que na hora de você subir alguma alteração no seu git, sem querer, subiu algum arquivo que não precisava!

Como faz pra tirar ele depois que já está no seu repositório?

Vamos dizer você quer retirar o _arquivo3.db_ do seu repositório, basta você executar o comando:

```
git rm arquivo3.db --cached
```

No terminal, ficará mais ou menos assim:

![No terminal temos o comando git rm arquivo3.db --cached e depois um git status e aparece que o arquivo3.db está como deleted em staging](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6jngt1xjkl2qxx3946s8.png)
 
A partir daí, você pode dar o git add, commit, push.. Como geralmente fazemos..
Mas caso queira deixar o seu histórico de commit "menos bagunçado" podemos usar o amend.
Segue exemplo dos comandos:

```
git add .

git commit --amend --no-edit

git push --force
```


Na imagem a baixo, ilustro melhor para entender sobre o histórico:

![No terminal temos o comando git log --oneline que aparece 2 commits, logo em seguida temos o git add . , depois git commit --amend --no-edit e depois git push --force , depois temos o git log --oneline novamente que mostra que as alterações foram atualizadas mas sem adicionar um novo commit ao nosso histórico](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qbnvwvvy8smjbxzgvx2j.png)
 

Então conseguimos retirar o arquivo que subimos por engano sem sujar o nosso histórico :)
Pure CSS The Lips
Tags: codepen, html, css, webdev
Published: 2022-06-19 00:18:44

---
title: Pure CSS The Lips
published: true
tags: codepen,html,css,webdev
---

{% codepen https://codepen.io/AsyrafHussin/pen/JjpVMWB %}

<p>Speed Code Video
<a href="https://twitter.com/asyrafhussin4/status/1539219926614876160" target="_blank">https://twitter.com/asyrafhussin4/status/1539219926614876160</a></p>
Remove Palindromic Subsequences
Tags: leetcode, dsa, theabbie
Published: 2022-06-19 00:00:45

You are given a string `s` consisting **only** of letters `'a'` and `'b'`. In a single step you can remove one **palindromic subsequence** from `s`.

Return _the **minimum** number of steps to make the given string empty_.

A string is a **subsequence** of a given string if it is generated by deleting some characters of a given string without changing its order. Note that a subsequence does **not** necessarily need to be contiguous.

A string is called **palindrome** if is one that reads the same backward as well as forward.

**Example 1:**

**Input:** s = "ababa"
**Output:** 1
**Explanation:** s is already a palindrome, so its entirety can be removed in a single step.

**Example 2:**

**Input:** s = "abb"
**Output:** 2
**Explanation:** "abb" -> "bb" -> "". 
Remove palindromic subsequence "a" then "bb".

**Example 3:**

**Input:** s = "baabb"
**Output:** 2
**Explanation:** "baabb" -> "b" -> "". 
Remove palindromic subsequence "baab" then "b".

**Constraints:**

*   `1 <= s.length <= 1000`
*   `s[i]` is either `'a'` or `'b'`.

**SOLUTION:**

    class Solution:
        def removePalindromeSub(self, s: str) -> int:
            if s == s[::-1]:
                return 1
            return 2
tsParticles 2.1.0 Released
Tags: javascript, webdev, typescript, showdev
Published: 2022-06-18 23:37:00

## tsParticles 2.1.0 Changelog

### Bug Fixes

- Fixed svelte typings, closes #4131
- Moved some specific code to the relative project, removing it from the generic engine
- Improving container destruction
- Improved fireworks preset
- Fixed connect links options
- Fixed issue with non-generated canvas elements, closes #4228
- Fixed class attributes on solid component
- Fixed issue with destroyed containers kept alive by plugins, closes #4151 

### New Features

- Added decay to all animations
- Added interactivity options overrides in particles options, closes #4120
- Added a new speed object for the wobble effect
- Added range colors to all color fields
- Added new multiple particles feature and improved particle destroy method

### Other changes

- Changed build from rollup-plugin-vue to vite, no breaking changes, only for vue3 projects
- Moved some updaters related code from engine to the relative updater
- Removed dynamic import of the pathseg polyfill, used the standard one in the polygon mask plugin

---

{% github matteobruni/tsparticles %}
Asteroid Collision
Tags: leetcode, dsa, theabbie
Published: 2022-06-18 23:30:38

We are given an array `asteroids` of integers representing asteroids in a row.

For each asteroid, the absolute value represents its size, and the sign represents its direction (positive meaning right, negative meaning left). Each asteroid moves at the same speed.

Find out the state of the asteroids after all collisions. If two asteroids meet, the smaller one will explode. If both are the same size, both will explode. Two asteroids moving in the same direction will never meet.

**Example 1:**

**Input:** asteroids = \[5,10,-5\]
**Output:** \[5,10\]
**Explanation:** The 10 and -5 collide resulting in 10. The 5 and 10 never collide.

**Example 2:**

**Input:** asteroids = \[8,-8\]
**Output:** \[\]
**Explanation:** The 8 and -8 collide exploding each other.

**Example 3:**

**Input:** asteroids = \[10,2,-5\]
**Output:** \[10\]
**Explanation:** The 2 and -5 collide resulting in -5. The 10 and -5 collide resulting in 10.

**Constraints:**

*   `2 <= asteroids.length <= 104`
*   `-1000 <= asteroids[i] <= 1000`
*   `asteroids[i] != 0`

**SOLUTION:**

    class Solution:
        def asteroidCollision(self, asteroids: List[int]) -> List[int]:
            n = len(asteroids)
            stack = []
            survivors = set()
            for i in range(n):
                if asteroids[i] > 0:
                    stack.append(i)
                else:
                    while len(stack) > 0 and abs(asteroids[stack[-1]]) < abs(asteroids[i]):
                        stack.pop()
                    if len(stack) > 0:
                        if abs(asteroids[stack[-1]]) <= abs(asteroids[i]):
                            stack.pop()
                    else:
                        survivors.add(i)
            for i in stack:
                survivors.add(i)
            return [asteroids[i] for i in range(n) if i in survivors]
Check Whether Two Strings are Almost Equivalent
Tags: leetcode, dsa, theabbie
Published: 2022-06-18 23:00:46

Two strings `word1` and `word2` are considered **almost equivalent** if the differences between the frequencies of each letter from `'a'` to `'z'` between `word1` and `word2` is **at most** `3`.

Given two strings `word1` and `word2`, each of length `n`, return `true` _if_ `word1` _and_ `word2` _are **almost equivalent**, or_ `false` _otherwise_.

The **frequency** of a letter `x` is the number of times it occurs in the string.

**Example 1:**

**Input:** word1 = "aaaa", word2 = "bccb"
**Output:** false
**Explanation:** There are 4 'a's in "aaaa" but 0 'a's in "bccb".
The difference is 4, which is more than the allowed 3.

**Example 2:**

**Input:** word1 = "abcdeef", word2 = "abaaacc"
**Output:** true
**Explanation:** The differences between the frequencies of each letter in word1 and word2 are at most 3:
- 'a' appears 1 time in word1 and 4 times in word2. The difference is 3.
- 'b' appears 1 time in word1 and 1 time in word2. The difference is 0.
- 'c' appears 1 time in word1 and 2 times in word2. The difference is 1.
- 'd' appears 1 time in word1 and 0 times in word2. The difference is 1.
- 'e' appears 2 times in word1 and 0 times in word2. The difference is 2.
- 'f' appears 1 time in word1 and 0 times in word2. The difference is 1.

**Example 3:**

**Input:** word1 = "cccddabba", word2 = "babababab"
**Output:** true
**Explanation:** The differences between the frequencies of each letter in word1 and word2 are at most 3:
- 'a' appears 2 times in word1 and 4 times in word2. The difference is 2.
- 'b' appears 2 times in word1 and 5 times in word2. The difference is 3.
- 'c' appears 3 times in word1 and 0 times in word2. The difference is 3.
- 'd' appears 2 times in word1 and 0 times in word2. The difference is 2.

**Constraints:**

*   `n == word1.length == word2.length`
*   `1 <= n <= 100`
*   `word1` and `word2` consist only of lowercase English letters.

**SOLUTION:**

    from collections import Counter
    
    class Solution:
        def checkAlmostEquivalent(self, word1: str, word2: str) -> bool:
            ctr1 = Counter(word1)
            ctr2 = Counter(word2)
            for c in "abcdefghijklmnopqrstuvwxyz":
                if abs(ctr1[c] - ctr2[c]) > 3:
                    return False
            return True
Things to remember - Dev Advocate Journal #DAJ 5
Tags: daj, devjournal
Published: 2022-06-18 22:30:58

Today I have some things to tell you.

## I lied
Well, a little bit. My previous post was about calming down and trying to organize a lot of things you have to do, and yes, breath it's important; that prevents headaches, but no matter how much I breathe, I still have a lot of things to do, but the keys that helped me the most are these:

- Remember what really matters in your life
- Try to understand that not doing something is not going to kill you
- Communicate that you are struggling
- Do your best to finish things

## About this journal
I decided not to do this journal daily; I want to practice my English writing every day, but I think I can start with tweets or maybe a minor update on my Linkedin. For this journal, I want to give you some value and have enough time to correct this content correctly; not to be perfect, but I want to do my best. I don't want to repeat the wrong things every day.

## What really matters
What do you want to do in your life? I always forget it. I want to do many things, and I have a lot of responsibilities, but why? Why do I want to do all of that? What do I want? I always forget what I really want. So I need to pay attention to that because I don't want to live someone else life, I want to live my life and use all my skills, my love, and my passions to do something that helps, and that's it.

At the moment, I can only tell you that:

- I want to stop doing things by compromise.
- I want to do something because I think that will help me be a better person and gain more skills to do what I really want.
- I need to communicate better when I am struggling because I don't need to be perfect always.
- And I want to do it all with all of my heart.

I am a little bit emotional person, well, a lot, but this is me, and if I want to do something, I want it with all my love as a sign.

With love, Mafer 💖
Find Subsequence of Length K With the Largest Sum
Tags: leetcode, dsa, theabbie
Published: 2022-06-18 22:30:40

You are given an integer array `nums` and an integer `k`. You want to find a **subsequence** of `nums` of length `k` that has the **largest** sum.

Return _**any** such subsequence as an integer array of length_ `k`.

A **subsequence** is an array that can be derived from another array by deleting some or no elements without changing the order of the remaining elements.

**Example 1:**

**Input:** nums = \[2,1,3,3\], k = 2
**Output:** \[3,3\]
**Explanation:**
The subsequence has the largest sum of 3 + 3 = 6.

**Example 2:**

**Input:** nums = \[-1,-2,3,4\], k = 3
**Output:** \[-1,3,4\]
**Explanation:** 
The subsequence has the largest sum of -1 + 3 + 4 = 6.

**Example 3:**

**Input:** nums = \[3,4,3,3\], k = 2
**Output:** \[3,4\]
**Explanation:**
The subsequence has the largest sum of 3 + 4 = 7. 
Another possible subsequence is \[4, 3\].

**Constraints:**

*   `1 <= nums.length <= 1000`
*   `-105 <= nums[i] <= 105`
*   `1 <= k <= nums.length`

**SOLUTION:**

    import heapq
    
    class Solution:
        def maxSubsequence(self, nums: List[int], k: int) -> List[int]:
            heap = []
            valIndexes = {}
            for i, num in enumerate(nums):
                if num not in valIndexes:
                    heapq.heappush(heap, num)
                valIndexes[num] = valIndexes.get(num, []) + [i]
            op = []
            rest = k
            biggest = heapq.nlargest(k, heap)
            while rest > 0:
                indexes = valIndexes[biggest.pop(0)]
                for index in indexes:
                    heapq.heappush(op, index)
                    rest -= 1
                    if rest == 0:
                        break
            return [nums[i] for i in heapq.nsmallest(k, op)]
Documentación Técnica de HTML5.
Tags: tutorial, html, spanish, webdev
Published: 2022-06-18 22:19:01

Este proyecto es una _Documentación Técnica de HTML5_, para aquellos que están comenzando **aprender acerca de HTML**. Es un proyecto diseñado y programado por mí.
![Versión Laptop](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gbkk1qrcst41ghiny6wn.png)

![Versión Móvil](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zzmw1a2l3pbvmr6eg1ne.png)


**¡¡Espero que sea de mucha utilidad!!**

[Dominio de la página](documentacion-html5.tech)
Help with my React Native expo app
Published: 2022-06-18 22:13:15

Hello, dear friends, I'm new to expo and react native. I created and published my first app to play store, which works fine. The issue I'm having now is that the the status bar is showing white and the content are pushed to the button, but shows properly on the expo goApp on my phone. Please I need help on how to fix this bug, I used safeAreaView.
Check if All Characters Have Equal Number of Occurrences
Tags: leetcode, dsa, theabbie
Published: 2022-06-18 22:00:42

Given a string `s`, return `true` _if_ `s` _is a **good** string, or_ `false` _otherwise_.

A string `s` is **good** if **all** the characters that appear in `s` have the **same** number of occurrences (i.e., the same frequency).

**Example 1:**

**Input:** s = "abacbc"
**Output:** true
**Explanation:** The characters that appear in s are 'a', 'b', and 'c'. All characters occur 2 times in s.

**Example 2:**

**Input:** s = "aaabb"
**Output:** false
**Explanation:** The characters that appear in s are 'a' and 'b'.
'a' occurs 3 times while 'b' occurs 2 times, which is not the same number of times.

**Constraints:**

*   `1 <= s.length <= 1000`
*   `s` consists of lowercase English letters.

**SOLUTION:**

    class Solution:
        def areOccurrencesEqual(self, s: str) -> bool:
            ctr = {}
            for c in s:
                ctr[c] = ctr.get(c, 0) + 1
            return len(set(ctr.values())) == 1