teleren/devto huggingface dataset:
126. Leetcode Solution in Java
Tags: java
Published: 2022-07-16 08:32:48

```
class Solution {
    public List<List<String>> findLadders(String beginWord, String endWord, List<String> wordList) {
        Set<String> words = new HashSet<>(wordList);
        List<List<String>> ans = new ArrayList<>();
        if (!words.contains(endWord)) {
            return ans;
        }
        
        Map<String, List<String>> adjWords = new HashMap<>();
        Map<String, Integer> dist = new HashMap<>();
        bfs(beginWord, adjWords, dist, words);
        dfs(endWord, beginWord, adjWords, dist, new ArrayList<>(), ans);
        
        return ans;
    }
    
    public void bfs(String beginWord, Map<String, List<String>> adjWords, Map<String, Integer> dist, Set<String> words) {
        Queue<String> queue = new LinkedList<>();
        queue.offer(beginWord);
        dist.put(beginWord, 0);
        for (String word : words) {
            adjWords.put(word, new ArrayList<>());
        }
        
        while (!queue.isEmpty()) {
            String cur = queue.poll();
            List<String> neighbors = neighbors(cur, words);
            for (String next : neighbors) {
                adjWords.get(next).add(cur);
                if (!dist.containsKey(next)) {
                    dist.put(next, dist.get(cur) + 1);
                    queue.offer(next);
                }
            }
        }
    } 
    
    public void dfs(String curWord, String beginWord,Map<String, List<String>> adjWords, Map<String, Integer> dist, List<String> path, List<List<String>> ans) {
        path.add(curWord);
        if (curWord.equals(beginWord)) {
            Collections.reverse(path);
            ans.add(new ArrayList<>(path));
            Collections.reverse(path);
        } else {
            for (String next : adjWords.get(curWord)) {
                if (dist.containsKey(next) && dist.get(curWord) == dist.get(next) + 1) {
                    dfs(next, beginWord, adjWords, dist, path, ans);
                }
            }
        }
        
        path.remove(path.size() - 1);
    }
    
    public List<String> neighbors(String word, Set<String> words) {
        List<String> ans = new ArrayList<>();
        char[] sc = word.toCharArray();
        for (int i = 0; i < sc.length; i++) {
            char cur = sc[i];
            for (char c = 'a'; c <= 'z'; c++) {
                sc[i] = c;
                String temp = new String(sc);
                if (words.contains(temp)) {
                    ans.add(temp);
                }
            }
            sc[i] = cur;
        }
        
        return ans;
    }
}
```
#leetcode
#challenge
Here is the link for the problem.....
https://leetcode.com/problems/word-ladder-ii/
669. Leetcode Solution in Cpp
Tags: cpp
Published: 2022-07-16 08:38:38

```
class Solution {
 public:
  TreeNode* trimBST(TreeNode* root, int L, int R) {
    if (!root)
      return nullptr;
    if (root->val < L)
      return trimBST(root->right, L, R);
    if (root->val > R)
      return trimBST(root->left, L, R);
    root->left = trimBST(root->left, L, R);
    root->right = trimBST(root->right, L, R);
    return root;
  }
};
```
#leetcode
#challenge
Here is the link for the problem.....
https://leetcode.com/problems/trim-a-binary-search-tree/
Telegram + node.js - bot
Tags: telegram, node, electron, javascript
Published: 2022-07-16 08:37:38

You can easily find tons of articles about creating bot for Telegram, including ones based on node.js. We at [Tonfotos](https://tonfotos.com) faced completely different task - we needed to build a Telegram client into our application.

# Why Telegram client, not a bot?
Tonfotos is an application that takes care of personal or family photo archive. And as such, it has to take care not only about storing, indexing and viewing photos and videos, it also has to simplify photos sharing. And these days people do not share their photos on USB sticks any more. Majority of photos got shared using messengers, and Telegram is one of them. There is wide spread belief among users that Telegram does not over-compress photos, unlike other messenger app, such as Viber for example.

As a result, we have implemented [Telegram connector](https://tonfotos.com/telegram.html) feature into our application. Once user connects Tonfotos to his or her Telegram account, all images that are sent to user by friends got saved into image archive, fully automated.

# Choosing the library
There are several requirements that pretty much narrow down a list of possible Telegram libraries:

* Tonfotos is a cross-platform application using Electron that supports Windows, Linux and macOS. The library should work on all of them.
* Application is not open-source, so no GPL.

Those requirements ruled out many implementations, including ones based on official TDLib library. So we ended up using [telegram-mtproto](https://www.npmjs.com/package/telegram-mtproto) library with MIT license. This is JS-native implementation of MT protocol. Thanks to that there is no native code dependencies, and impact on distribution size is negligible.

Downside is though, this library is not supported anymore and repository is not accepting PR's with fixes. So all bug fixes we had to keep as patches. This includes update of MTproto schema to up-to-date one, which is basically a replacement of schema file.

# Architecture
The disadvantage of the chosen library is that it cannot deinitialize and free up all the used memory. Therefore we had to run it always in a separate process that we would spawn using `child_process.fork`, and killing this process when it is not needed anymore.
628. Leetcode Solution in Cpp
Tags: cpp
Published: 2022-07-16 08:37:33

```
class Solution {
 public:
  int maximumProduct(vector<int>& nums) {
    int min1 = INT_MAX;  // the minimum
    int min2 = INT_MAX;  // 2nd minimum
    int max1 = INT_MIN;  // the maximum
    int max2 = INT_MIN;  // 2nd maximum
    int max3 = INT_MIN;  // 3rd maximum

    for (const int num : nums) {
      if (num <= min1) {
        min2 = min1;
        min1 = num;
      } else if (num <= min2) {
        min2 = num;
      }
      if (num >= max1) {
        max3 = max2;
        max2 = max1;
        max1 = num;
      } else if (num >= max2) {
        max3 = max2;
        max2 = num;
      } else if (num >= max3) {
        max3 = num;
      }
    }

    return max(min1 * min2 * max1, max1 * max2 * max3);
  }
};
```

#leetcode
#challenge
Here is the link for the problem.....
https://leetcode.com/problems/maximum-product-of-three-numbers/
636. Leetcode Solution in Cpp
Tags: cpp
Published: 2022-07-16 08:36:30

```
class Solution {
 public:
  vector<int> exclusiveTime(int n, vector<string>& logs) {
    vector<int> ans(n);
    stack<int> stack;  // [oldest_id, ..., latest_id]
    int prevTime;

    for (const string& log : logs) {
      // get seperators' indices
      const int colon1 = log.find_first_of(':');
      const int colon2 = log.find_last_of(':');
      // get function_id, label, and timestamp
      const int id = stoi(log.substr(0, colon1));  // {function_id}
      const char label = log[colon1 + 1];  // {"s" ("start") | "e" ("end") }
      const int timestamp = stoi(log.substr(colon2 + 1));  // {timestamp}
      if (label == 's') {
        if (!stack.empty())
          ans[stack.top()] += timestamp - prevTime;
        stack.push(id);
        prevTime = timestamp;
      } else {
        ans[stack.top()] += timestamp - prevTime + 1, stack.pop();
        prevTime = timestamp + 1;
      }
    }

    return ans;
  }
};
```
#leetcode
#challenge
Here is the link for the problem.....
https://leetcode.com/problems/exclusive-time-of-functions/
Tips on WSL2
Tags: wsl2
Published: 2022-07-16 08:36:07

> Please note that this blog post will continuously updated. And the wsl2 system I used is Ubuntu22.04

1. wslview
> This is a tool that we can open file (images, html, document...) through software on windows.

- first, install wslview
> type this command: sudo apt install wslview
- second, use it
> For example, create a text file `touch hello.txt`
> and input something in hello.txt
> then use it: `wslview hello.txt`
> then you can see that hello.txt will open in notebook.
689. Leetcode Solution in Cpp
Tags: cpp
Published: 2022-07-16 08:35:05

```
class Solution {
 public:
  vector<int> maxSumOfThreeSubarrays(vector<int>& nums, int k) {
    const int n = nums.size() - k + 1;
    vector<int> sums(n);  // sums[i] := sum of nums[i..i + k)
    vector<int> l(n);     // l[i] := index in [0..i] having max sums[i]
    vector<int> r(n);     // r[i] := index in [i..n) having max sums[i]

    int sum = 0;
    for (int i = 0; i < nums.size(); ++i) {
      sum += nums[i];
      if (i >= k)
        sum -= nums[i - k];
      if (i >= k - 1)
        sums[i - k + 1] = sum;
    }

    int maxIndex = 0;
    for (int i = 0; i < n; ++i) {
      if (sums[i] > sums[maxIndex])
        maxIndex = i;
      l[i] = maxIndex;
    }

    maxIndex = n - 1;
    for (int i = n - 1; i >= 0; --i) {
      if (sums[i] >= sums[maxIndex])
        maxIndex = i;
      r[i] = maxIndex;
    }

    vector<int> ans{-1, -1, -1};

    for (int i = k; i < n - k; ++i)
      if (ans[0] == -1 || sums[ans[0]] + sums[ans[1]] + sums[ans[2]] <
                              sums[l[i - k]] + sums[i] + sums[r[i + k]]) {
        ans[0] = l[i - k];
        ans[1] = i;
        ans[2] = r[i + k];
      }

    return ans;
  }
};
```
#leetcode
#challenge
Here is the link for the problem.....
https://leetcode.com/problems/maximum-sum-of-3-non-overlapping-subarrays/
My Next.js Portfolio
Tags: webdev, javascript, react, nextjs
Published: 2022-07-16 08:33:25

Hello folks,

I have been working on my portfolio/blog Web App based on Next.js and MDX. I am still working on some parts like projects and space sections. So below is the link. Please check it out and let me know your thoughts and what I can improve and add.

[Portfolio link](devkisan.vercel.app)
Pointer & Reference & Deference in C++
Published: 2022-07-16 08:26:16

Say you have a variable 'a' of type integer. 
`int a = 4;`

Then, you can find the address of 'a' using pointer.
`int *b = &a;`

Well, not exactly because '&a' will give you the address as well. Try,
`cout << &a; // will output address of the variable a`

But, back to the pointer, it gives you the ability to 'save' the address of memory. Hence, it will show memory address of 'a' as well. Try,
`cout << b`

What would happen if I try printing out *b? It will give you the value of 'a'. Weird, isn't it? This behavior is called dereferencing, meaning you get the actual value of whatever is saved in that memory. 

Does b have memory address as well? Yes, you can access it with '&b'

So, in summary
```cpp
int a = 4; // note it has memory allocated to this integer
int *b = &a; // you can save the memory address to a variable 'a'
cout << b; // it will give you memory address of 'a'. Notice how it is not saved in '*b' but 'b' itself. 
cout << &a; // this will give you memory address of 'a'
cout << *b; // this will give you the value of 'a'. Dereferenced!
```

Question remains: what would &*b produce? what will *&a produce?

Answer: 
&*b -> it is address of pointer to 'a', hence same as &a, memory address where 'a' is saved. 
*&a -> * dereferences memory address aka finds out the value in the address hence value of 'a'
Create Your Free Resume!
Tags: javascript, react, typescript, resume
Published: 2022-07-16 08:24:56

Hey friends! 👋

I want to share with you a **Minimal RESUME BUILDER** which is free and you can have your resume just by editing a **JSON** file! 👌

I've used **Reactjs**, **Typescript** ,and **i18next** to create the project. You can fork the repository and edit a **JSON** file to make your #resume online with the **GitHub Page**.

➡️ This is an example (the result) of this resume builder:
https://mehdikhoshnevisz.github.io/resume/

🚀 Let's try and launch your free resume today:
https://github.com/MehdiKhoshnevisz/resume

> ❗I know the project may have the bugs, but let me know if you find a bug or if you have ideas to make it better:
> https://github.com/MehdiKhoshnevisz/resume/issues

I would be happy if you like and share this post and star the repo. 🙏
Attest Is All You Need; Goldbach Conjecture.
Tags: cpp, computerscience, math
Published: 2022-07-16 08:24:46

First of all, the title was inspired by the original paper of transformer model, [Attention Is All You Need](https://arxiv.org/abs/1706.03762?context=cs)

I ever thought that i can getting rich easily just to solve an unsolved math problem, but after i surfing the internet with the keyword “Simplest unsolved math problem” I undo my intention because I am stupid in mathematics.

One of the problems that interests me is to try the "Goldbach Conjecture", it is very simple only integers greater than 2 can be added from 2 prime numbers. It's interesting for me not to answer, but to prove it using my computer science background.

Goldbach conjecture was first mentioned by Christian Goldbach in his letter to Euler in 1742. In his letter, Goldbach reported that even numbers greater than or equal to 4 could be written as the sum of two prime numbers, but he failed to prove the truth of his conjecture.

I proved by using the C + + programming language, this is more or less:

First I declare a function that returns a integer numbers.

```
int is_prime(int n){
    int num = 1;
    for (int i = 2; i < n/2; i++){
        if((n%i) == 0){
            return num-1;
        }
    }
    return num;
}
```

The next step is create a procedure for the logic of this mathematical problem.

```
void solve(){
    int number = 0;
    int primes[100000] = {2};
    int j = 0;
    while(true){
		std::cout<<"Input even number:";
		std::cin>>number;
        if(number > 2 && number % 2==0){

            if(primes[j]<number){
                for (int i = primes[j]+1; i < number; i++){
                    if(is_prime(i) == 1){
                        j++;
                        primes[j] = i;
                    }
                }       
            }
            for (int i = 0; i < j; i++){
                for (int k = 0; k < j; k++){
                    if(primes[i] + primes[k] == number){
                        std::cout<<primes[i]<<" + "<<primes[k]<<" = "<<number<<std::endl;
                        break;
                    }
                }
            }
	   	}
        else{
			std::cout<<"Input must a even numbers"<<std::endl;
        }
    }
}
```

The last step is just declared the procedure to main function.
```
int main(){
    solve();
    return 0;
}
```

Here is the output, let's say i entered the number 120. 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o1mtjrx4ie77ll9bzyhq.png)


Maybe you passed the incorrect grammar or tenses, i'm sorry, i'm bad in english :)

Reference
[Wikipedia](https://en.wikipedia.org/wiki/Goldbach%27s_conjecture)

[The one who discussed it first](https://dev.to/hakan/goldbach-conjecture-and-a-simple-approach-in-c-56b0#:~:text=The%20Goldbach%20conjecture%20is%20the,problems%20that%20cannot%20be%20proved.)

[List of unsolved math problem](https://en.wikipedia.org/wiki/List_of_unsolved_problems_in_mathematics)
2140. Leetcode Solution in Python3
Tags: python
Published: 2022-07-16 08:05:45

```
class Solution:
    def mostPoints(self, questions: List[List[int]]) -> int:
        def f(qs, idx, memo):
            if idx >= len(qs):return 0
            if idx in memo: return memo[idx]
            p,b = qs[idx]
            skip = f(qs, idx+1,  memo)
            solve = p + f(qs, idx+b+1, memo)
            ans = max(skip, solve)
            memo[idx] = ans
            return ans
        return f(questions, 0, {})
```
#leetcode
#weekly contest
Here is the link for the problem.....
https://leetcode.com/contest/weekly-contest-276/problems/solving-questions-with-brainpower/
2139. Leetcode Solution in Cpp
Tags: cpp
Published: 2022-07-16 08:04:08

```
class Solution {
 public:
  int minMoves(int target, int maxDoubles) {
    int steps = 0;

    while (target > 1 && maxDoubles) {
      if (target & 1) {
        --target;
      } else {
        target /= 2;
        --maxDoubles;
      }
      ++steps;
    }

    return steps + target - 1;
  }
};

```
#leetcode
#weekly contest
Here is the link for the problem.....
https://leetcode.com/contest/weekly-contest-276/problems/minimum-moves-to-reach-target-score/
2138. Leetcode Solution in Cpp
Tags: cpp
Published: 2022-07-16 08:03:14

```
class Solution {
 public:
  vector<string> divideString(string s, int k, char fill) {
    vector<string> ans;

    for (int i = 0; i < s.length(); i += k)
      ans.push_back(i + k > s.length()
                        ? s.substr(i) + string(i + k - s.length(), fill)
                        : s.substr(i, k));

    return ans;
  }
};

```
#leetcode
#weekly contest
Here is the link for the problem.....
https://leetcode.com/contest/weekly-contest-276/problems/divide-a-string-into-groups-of-size-k/
Are Twitch Emotes Copyrighted?
Tags: javascript, programming, tooling, python
Published: 2022-07-16 08:02:09


Twitch emotes are a popular form of digital content used on the streaming platform Twitch.tv. Many users use these emotes to communicate with each other while watching live streams or playing video games online. While many people believe that twitch emotes are just harmless fun, there have been some concerns raised about their legality. Is it illegal to make and use twitch emotes? And if so, what consequences could this have for you? Although no official ruling has been made in this regard, there is growing concern among legal experts that certain twitch emotes may be copyright infringing under various applicable laws. If you create or use an emoji-based “twitch Emote” (e.g.

## [The full source is here](https://professional-writer0.blogspot.com/2022/07/are-twitch-emotes-copyrighted-and-are.html)

Twitch, Inc. (aka Twitch Interactive, Twitch Labs, and Twitch TV) is a live streaming service headquartered in San Francisco, California. It transmits video game streams and other types of live content from its users' personal computers as well as embedded mini-games and messaging services, in a format that viewers can view in a web browser on computer, mobile devices, televisions, Xbox One, PlayStation 4, Apple products, and some smart TVs.

Twitch Inc. claims that its emotes (also known as "emotes") are protected by US copyright law, and that users may not use such emotes without permission from Twitch. The difficulty in ascertaining whether the use of emotes constitutes an infringement of copyright has led to a great deal of litigation between Twitch and users.

While there is no definitive answer at present, it is likely that the use of twitch emotes without permission may be an infringing act under US copyright law. However, given the presence of fair use restrictions and the limitation of copyright protection to "original works of authorship," it is unclear whether the use of such emotes in YouTube videos would be permissible without the explicit consent of Twitch.

It is likely that the use of twitch emotes without permission may be an infringing act under US copyright law.
Today's Daily Humor For Devs - Daily Developer Jokes
Tags: jokes, dailydeveloperjokes
Published: 2022-07-16 08:00:28

---
title: "Today's Daily Humor For Devs - Daily Developer Jokes"
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/5e1259a186412.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 do developers use mechanical keyboards?

___A___: To strongly type their code.
 -->
gyp no xcode or clt version detected
Tags: tooling, programming, python, javascript
Published: 2022-07-16 07:57:19


When I open up Xcode or Command Line Tools, I get the following error: gyp no xcode or clt version detected.

I have tried the following solutions and none of them have worked:

- a. Updating my Xcode or Command Line Tools
- b. Checking my MacOS version
- c. Updating my Gypsy project

Although I have tried all these solutions, I am still getting the error message. I would really appreciate if someone could help me resolve this issue.

This error indicates that your Gypsy project is not compatible with the version of Xcode or Command Line Tools that you are using. You may need to update your Gypsy project to match the version of Xcode or Command Line Tools that you are using.

## [The source is complete with pictures](https://professional-writer0.blogspot.com/2022/07/macos-catalina-does-not-recognize.html)
Primitive vs reference values in JavaScript
Tags: javascript, beginners, webdev, tutorial
Published: 2022-07-16 07:47:20

In this post, we will take a look at a super common interview question: primitive vs reference values in JavaScript.

## What is a primitive value?

In JS, there are 6 primitive values: number, string, boolean, undefined, null and symbol.

You can think of them as the *base*, hence the name *primitive*. These values are not objects and they don't have methods.

## What is a reference value?

The short answer is: anything that is not a primitive value is a reference value. They are `typeof "object"`. We are talking about objects, arrays, functions, etc.

## Key differences

The key difference is how these values behave under the hood. Specifically, **how they store their values in memory.**

The primitive values would have the value in memory, while the reference values would have a reference to that location in memory (the memory address), and not the value itself.

For example:
```js
let name = 'Jesus'
let nickName = name

name = 'Juan'

console.log(name) // 'Juan'
console.log(nickName) // 'Jesus'
```
We are only using primitive values here, so everything makes sense. Right?

Now, let's take a look at a reference values example:
```js
let jose = {
  type: 'Person',
  name: 'Jose'
}

let juan = jose

juan.name = 'Juan'

console.log(jose.name) // 'Juan'
console.log(juan.name) // 'Juan'
```
See? In here, the `juan` variable is referencing the same spot in memory as the `jose` variable. That is why when we change the `name` property in one of them, we will be changing it in both.

This behavior also explains why if we compare two seemingly equal reference values, the result will be `false`. For example:
```js
const fruit = {
  color: 'Yellow',
  name: 'Banana'
}

const snack = {
  color: 'Yellow',
  name: 'Banana'
}

fruit === snack // false
```
So primitive types are compared by their value, while reference types are compared by their reference. 

Lastly, remember that **primitive values are immutable.** So when you change a primitive value, what you are doing is replacing the in-memory value. You are not modifying it like you can do with reference values.
Firebase: How to use emulator with express.js
Tags: firebase, node
Published: 2022-07-16 07:41:21

If you use `@google-cloud/firestore` as firestore client and you want to use emulator, you can connect by below code

```
// In console

npx firebase emulators:start --project local-project-id

```

And

```
// In app.ts
import {Firestore} from '@google-cloud/firestore'

const firestore = new Firestore({
  // Firestore emulator host
  host: 'localhost:4100',
  projectId: 'local-project-id',
  ssl: false,
  eexperimentalForceLongPolling: true
})

```

Have a good day!!