teleren/devto huggingface dataset:
883. Leetcode Solution in Cpp
Tags: cpp
Published: 2022-07-14 16:17:10

```
class Solution {
 public:
  int projectionArea(vector<vector<int>>& grid) {
    int ans = 0;

    for (int i = 0; i < grid.size(); ++i) {
      int maxOfRow = 0;
      int maxOfCol = 0;
      for (int j = 0; j < grid.size(); ++j) {
        maxOfRow = max(maxOfRow, grid[i][j]);
        maxOfCol = max(maxOfCol, grid[j][i]);
        if (grid[i][j])
          ++ans;
      }
      ans += maxOfRow + maxOfCol;
    }

    return ans;
  }
};
```
#leetcode
#challenge
Here is the link for the problem:
https://leetcode.com/problems/projection-area-of-3d-shapes/
877. Leetcode Solution in Cpp
Tags: cpp
Published: 2022-07-14 16:16:13

```
class Solution {
 public:
  bool stoneGame(vector<int>& piles) {
    const int n = piles.size();
    // dp[i][j] := max stones you can get more than your opponent in piles[i..j]
    vector<vector<int>> dp(n, vector<int>(n));

    for (int i = 0; i < n; ++i)
      dp[i][i] = piles[i];

    for (int d = 1; d < n; ++d)
      for (int i = 0; i + d < n; ++i) {
        const int j = i + d;
        dp[i][j] = max(piles[i] - dp[i + 1][j], piles[j] - dp[i][j - 1]);
      }

    return dp[0][n - 1] > 0;
  }
};
```
#leetcode
#challenge
Here is the link for the problem:
https://leetcode.com/problems/stone-game/
870. Leetcode Solution in Cpp
Tags: cpp, javascript
Published: 2022-07-14 16:15:13

```
class Solution {
 public:
  vector<int> advantageCount(vector<int>& A, vector<int>& B) {
    multiset<int> set{begin(A), end(A)};

    for (int i = 0; i < B.size(); ++i) {
      auto p = *rbegin(set) <= B[i] ? begin(set) : set.upper_bound(B[i]);
      A[i] = *p;
      set.erase(p);
    }

    return A;
  }
};
```
#leetcode
#challenge
Here is the link for the problem:
https://leetcode.com/problems/advantage-shuffle/
866. Leetcode Solution in Cpp
Tags: cpp
Published: 2022-07-14 16:14:19

```
class Solution {
 public:
  int primePalindrome(int N) {
    if (N <= 2)
      return 2;
    if (N == 3)
      return 3;
    if (N <= 5)
      return 5;
    if (N <= 7)
      return 7;
    if (N <= 11)
      return 11;

    int n = to_string(N).length();

    while (true) {
      for (const int num : getPalindromes(n))
        if (num >= N && isPrime(num))
          return num;
      ++n;
    }

    throw;
  }

 private:
  vector<int> getPalindromes(int n) {
    vector<int> palindromes;
    const int length = n / 2;

    for (int i = pow(10, length - 1); i < pow(10, length); ++i) {
      const string s = to_string(i);
      string reversedS = s;
      reverse(begin(reversedS), end(reversedS));
      for (int j = 0; j < 10; ++j)
        palindromes.push_back(stoi(s + to_string(j) + reversedS));
    }

    return palindromes;
  }

  bool isPrime(int num) {
    for (int i = 2; i < sqrt(num) + 1; ++i)
      if (num % i == 0)
        return false;

    return true;
  }
};
```
#leetcode
#challenge
Here is the link for the problem:
https://leetcode.com/problems/prime-palindrome/
5 VS Code Extensions for Web Designers
Tags: vscode, javascript, webdev, extensions
Published: 2022-07-14 16:07:35


1.. [JavaScript (ES6) Code Snippets](https://marketplace.visualstudio.com/items?itemName=xabikos.JavaScriptSnippets)

This extension contains code snippets for JavaScript in ES6 syntax for Vs Code editor. It supports both JavaScript and TypeScript.

2.. [Auto Close Tag](https://marketplace.visualstudio.com/items?itemName=formulahendry.auto-close-tag)

After opening a tag in HTML and XML it’s a hectic job to close it. So here is a nice solution.This extension closes the HTML and XML tag automatically.

3.. [Prettier — Code formatter](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode)

This extension will help us to format the JavaScript, HTML, CSS code. We can configure it as per our need.

4.. [Auto Rename Tag](https://marketplace.visualstudio.com/items?itemName=formulahendry.auto-rename-tag)

This extension renames html tags automatically. So we can keep our code consistent and easy to maintain, even when working on bigger projects with lots of elements deep in the HTML structure.

5.. [Live Server](https://marketplace.visualstudio.com/items?itemName=ritwickdey.LiveServer)

At the last the one extension every web designer/developer must use.This extension helps us in launching a local development server with live reload feature for both static & dynamic pages.So the next time you guys don't have to refresh the page again to see the output.
Hadoop
Published: 2022-07-14 16:00:53

Hadoop is an open source framework from Apache and is used to store process and analyze data which are very huge in volume. Hadoop is written in Java and is not OLAP (online analytical processing). It is used for batch/offline processing.It is being used by Facebook, Yahoo, Google, Twitter, LinkedIn and many more. Moreover it can be scaled up just by adding nodes in the cluster.
Big Data
Published: 2022-07-14 15:54:08

The definition of big data is data that contains greater variety, arriving in increasing volumes and with more velocity. This is also known as the three Vs.

Put simply, big data is larger, more complex data sets, especially from new data sources. These data sets are so voluminous that traditional data processing software just can’t manage them. But these massive volumes of data can be used to address business problems you wouldn’t have been able to tackle before.
TCP/IP
Tags: internet, tcpip, dev, beginners
Published: 2022-07-14 15:41:28

**TCP/IP**
**TCP** stands for transmission control protocol and **IP** stands for Internet Protocol.
A protocol is a set of rules that define how data is transferred between 2 devices connected in a computer network.One such a popular protocol is TCP/IP.
There are 5 layers in **TCP/IP** model:

1. Application layer
2. Transport layer
3. Network layer
4. Data-link layer
5. Physical layer



**1. Application layer**
It is the top most layer of TCP/IP protocol.It acts as an interface between the user and the model.It is the only layer which interacts with the user.The protocols defined in the layer are HTTPS,FTP,SMTP.The user applications work on these protocols.

**2. Transport layer**
The protocols in this layer are TCP and UDP.It provides an end to end connection between 2 devices. TCP is a connection oriented protocol while UDP is a connectionless protocol.UDP is fast but not secure, while TCP is secure but slower.
The transport layer converts the data into smaller layers called segments for easier transfer of data .
Also in TCP there is an acknowledgement process to check whether the data transfer is completed or not.If the transfer is not completed the data is sent again.

**3. Network layer**
The protocols in the network layer are IP and ARP.
IP stands for Internet Protocol.Each device has an unique IP address by which it is found on the network.It is responsible for delivering packets from the sender to the receiver’s end.Packets refers to small fragments of data that is to be transferred.
The data is converted to packets for easier transfer of data.
The network protocol is also responsible for assigning routing protocols .
Also it determines the paths through the network for these packets to travel.



**4. Data-link layer**

The data link layer is responsible for encapsulating the packets with MAC address of the nearest router and also a header link which contains a checksum for error detection.
It ensures that data transfer has occurred completely without any errors.
If any errors have occurred it tries to resolve it.

**5. Physical Layer**
It is the lowest layer in the TCP/IP model.It is responsible for handling host to host connection between the sender and the receiver.
Also it is responsible for converting packets into bits.It also oversees whether the communication occurs through wireless medium or through a wired medium.

TCP/IP is the backbone of the internet .All the data that we send and receive are governed by the TCP/IP protocols .
Brave Chicky Dice Adventure
Tags: codepen, webdev, gamedev, showdev
Published: 2022-07-14 15:35:33

<h1>Brave Chicky Dice Adventure</h1>

<h2>Description</h2>

<p>This is just a simple turn-based game where you just have to throw a dice, defeat the enemy, and go to the highest floor as you can.</p>

<p>Help Chicky to climb up the Natural Tower by giving it a command. Chicky doesn't quite understand yet what it will do.</p>

<p>There are 4 possible commands to fight the ghost defending the Natural Tower.</p>

<p>By rolling the dice, you can guide Chicky with the possible commands depends on the number appeared on the dice.</p>

<ul>
<li>== 1 Do nothing</li>
<li>&gt;= 2 Defend</li>
<li>&gt;= 3 Defend, Attack</li>
<li>&gt;= 5 Defend, Attack, Heal</li>
</ul>

<p>Also, you may challenge your friends and brag your highest score.</p>

<p>I haven't been ditching practicing web development these days, and I had hard time creating all these stuff.</p>

<p>This game is best viewed in landscape mode.</p>

<h2>Resources</h2>

<ul>
<li>
<a href="https://threejs.org">ThreeJS</a> for 3D rendering and graphics</li>
<li>
<a href="https://greensock.com">GSAP</a> for animation</li>
<li><a href="https://reactjs.org">ReactJS</a> for UI</li>
<li><a href="https://ephtracy.github.io">MagicaVoxel</a> to create all the 3D models.</li>
<li><a href="https://www.aseprite.org">Aseprite</a> for background, dice, and effect.</li>
<li><a href="https://www.aseprite.org">PICO-8</a> for the colour palette used for graphics.</li>
<li><a href="https://fonts.google.com/specimen/Press+Start+2P">Press Start 2P</a> for the fonts in the UI.</li>
</ul>

{% codepen https://codepen.io/takaneichinose/pen/dympyjN %}
849. Leetcode Solution in Cpp
Tags: cpp
Published: 2022-07-14 15:35:33

```
class Solution {
 public:
  int maxDistToClosest(vector<int>& seats) {
    const int n = seats.size();
    int ans = 0;
    int j = -1;

    for (int i = 0; i < n; ++i)
      if (seats[i] == 1) {
        ans = j == -1 ? i : max(ans, (i - j) / 2);
        j = i;
      }

    return max(ans, n - j - 1);
  }
};
```
#leetcode
#challenge
Here is the link for the problem:
https://leetcode.com/problems/maximize-distance-to-closest-person/
Why references to `OPENSSL_init_crypto' are undefined when crossbuilt openssl from source for windows 32 bit?
Tags: help, c, crossbuild, openssl
Published: 2022-07-14 15:34:58

I managed to bypass any unwanted files but now I have thwe following issue:

{% stackoverflow 72983025 %}

Some referenced are undefined when I crossbuild my app on mingw32 at linux for windows 32 bit executable. Do you know how I can bypass this problem as well?
Ways to test SSL Certificates
Tags: ssl, security
Published: 2022-07-14 15:34:53

- For Externally accessible websites only – Only works with a hostname, can’t use IP address
https://www.ssllabs.com/ssltest/analyze.html 

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

- For Internally and Externally accessible websites – Can use hostname or IP address
Sslyze command line tool - https://github.com/nabla-c0d3/sslyze/releases  - current version is 4.1.0

1. Download sslyze-4.1.1-exe.zip and extract sslyze-4.1.0 folder to local drive

2. Open command prompt and change to the folder where sslyze-3.0.8 was extracted:
o sslyze.exe --regular [hostname or IP address]
o sslyze.exe --regular ep.firstam.com 
o sslyze.exe --regular 172.17.22.117

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ou4wqy0krjr63i7ujbx4.jpg)
What are the 4 properties in a CSS Box Model?
Tags: css, webdev, tutorial
Published: 2022-07-14 06:50:00

One of the most important concepts in CSS is the Box Model.

Boxes can be used to represent any HTML element. The design and layout of the site are represented by the CSS box model. It’s made up of **margins**, **borders**, **padding**, and the **actual content**.

The **content box** is the area where the content is displayed.
The **padding box** is the white space around the content.
The **border box** comes after the padding.
The **margin box** is the last one and defines the space between this box and other elements.

The properties work in the same order: top, right, bottom, and left.

The image below illustrates the box model:

![Box Model](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sghqgexbz1ewfy7jd493.jpg)

## Understanding the Box Model

A box is a placeholder for any element on the page.
The box model is used by CSS to calculate the size and placement of boxes.
The box model is also used to calculate the HTML element’s actual width and height.

### Total Width of an Element

It’s crucial to understand how the entire width of an element is calculated when working with boxes.
The sum of width plus padding left and padding right, for example, is the total width of the box with paddings.

Here is an example of total element width:

![Total width of box model](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gsk58nlx6i0yqm1sedw1.jpg)

Padding left: 10px
Content width: 200px
Padding right: 10px
Total width = 220px

Here is another box with margins, border, and paddings.
The total width is the sum of left and right margins, left and right borders, left and right paddings, and the actual width of the content.

![Total width of box model](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/03vcaxylv6c2i08aathc.jpg)

Margin-left: 20px
Border-left: 5px
Padding-left: 10px
Content: 200px
Padding-right: 10px
Border-right: 5px
Margin-right: 20px
Total width = 270px

If you specify a width (or height) on an element, it will be applied to the content area by default. All padding, border, and margin calculations are done outside of the value, so keep that in mind when you’re doing your calculations.
845. Leetcode Solution in Cpp
Tags: cpp
Published: 2022-07-14 15:34:35

```
class Solution {
 public:
  int longestMountain(vector<int>& A) {
    int ans = 0;

    for (int i = 0; i + 1 < A.size();) {
      while (i + 1 < A.size() && A[i] == A[i + 1])
        ++i;

      int increasing = 0;
      int decreasing = 0;

      while (i + 1 < A.size() && A[i] < A[i + 1]) {
        ++increasing;
        ++i;
      }

      while (i + 1 < A.size() && A[i] > A[i + 1]) {
        ++decreasing;
        ++i;
      }

      if (increasing > 0 && decreasing > 0)
        ans = max(ans, increasing + decreasing + 1);
    }

    return ans;
  }
};
```
#leetcode
#challenge
Here is the link for the problem:
https://leetcode.com/problems/longest-mountain-in-array/
840. Leetcode Solution in Cpp
Tags: cpp
Published: 2022-07-14 15:33:44

```
class Solution {
 public:
  int numMagicSquaresInside(vector<vector<int>>& grid) {
    int ans = 0;

    for (int i = 0; i + 2 < grid.size(); ++i)
      for (int j = 0; j + 2 < grid[0].size(); ++j)
        if (grid[i][j] % 2 == 0 && grid[i + 1][j + 1] == 5)
          ans += isMagic(grid, i, j);

    return ans;
  }

 private:
  int isMagic(const vector<vector<int>>& grid, int i, int j) {
    string s;

    for (const int num : {0, 1, 2, 5, 8, 7, 6, 3})
      s += to_string(grid[i + num / 3][j + num % 3]);

    return string("4381672943816729").find(s) != string::npos ||
           string("9276183492761834").find(s) != string::npos;
  }
};
```
#leetcode
#challenge
Here is the link for the problem:
https://leetcode.com/problems/magic-squares-in-grid/
836. Leetcode Solution in Cpp
Tags: cpp
Published: 2022-07-14 15:32:53

```
class Solution {
 public:
  bool isRectangleOverlap(vector<int>& rec1, vector<int>& rec2) {
    return rec1[0] < rec2[2] && rec2[0] < rec1[2] &&
           rec1[1] < rec2[3] && rec2[1] < rec1[3];
  }
};
```
#leetcode
#challenge
Here is the link for the problem:
https://leetcode.com/problems/rectangle-overlap/
823. Leetcode Solution in Cpp
Tags: cpp
Published: 2022-07-14 15:31:50

```
class Solution {
 public:
  int numFactoredBinaryTrees(vector<int>& arr) {
    constexpr int kMod = 1e9 + 7;
    const int n = arr.size();
    // dp[i] := # of binary trees with arr[i] as root
    vector<long> dp(n, 1);
    unordered_map<int, int> numToIndex;

    sort(begin(arr), end(arr));

    for (int i = 0; i < n; ++i)
      numToIndex[arr[i]] = i;

    for (int i = 0; i < n; ++i)  // arr[i] is root
      for (int j = 0; j < i; ++j)
        if (arr[i] % arr[j] == 0) {  // arr[j] is left subtree
          const int right = arr[i] / arr[j];
          if (numToIndex.count(right)) {
            dp[i] += dp[j] * dp[numToIndex[right]];
            dp[i] %= kMod;
          }
        }

    return accumulate(begin(dp), end(dp), 0L) % kMod;
  }
};
```
#leetcode
#challenge
Here is the link for the problem:
https://leetcode.com/problems/binary-trees-with-factors/
811. Leetcode Solution in Cpp
Tags: cpp
Published: 2022-07-14 15:30:46

```
class Solution {
 public:
  vector<string> subdomainVisits(vector<string>& cpdomains) {
    vector<string> ans;
    unordered_map<string, int> count;

    for (const string& cpdomain : cpdomains) {
      const int space = cpdomain.find(' ');
      const int num = stoi(cpdomain.substr(0, space));
      const string& domain = cpdomain.substr(space + 1);
      count[domain] += num;
      for (int i = 0; i < domain.length(); ++i)
        if (domain[i] == '.')
          count[domain.substr(i + 1)] += num;
    }

    for (const auto& [subdomain, freq] : count)
      ans.push_back(to_string(freq) + ' ' + subdomain);

    return ans;
  }
};
```
#leetcode
#challenge
Here is the link for the problem:
https://leetcode.com/problems/subdomain-visit-count/
809. Leetcode Solution in Cpp
Tags: cpp
Published: 2022-07-14 15:29:43

```
class Solution {
 public:
  int expressiveWords(string S, vector<string>& words) {
    int ans = 0;

    for (const string& word : words)
      if (isStretchy(S, word))
        ++ans;

    return ans;
  }

 private:
  bool isStretchy(const string& S, const string& word) {
    const int n = S.length();
    const int m = word.length();

    int j = 0;
    for (int i = 0; i < n; ++i)
      if (j < m && S[i] == word[j])
        ++j;
      else if (i > 1 && S[i] == S[i - 1] && S[i - 1] == S[i - 2])
        continue;
      else if (0 < i && i + 1 < n && S[i - 1] == S[i] && S[i] == S[i + 1])
        continue;
      else
        return false;

    return j == m;
  }
};
```
#leetcode
#challenge
Here is the link for the problem:
https://leetcode.com/problems/expressive-words/
Looping is vital
Tags: javascript, webdev, beginners
Published: 2022-07-14 15:28:27


My background

When I got to high school I joined the engineering magnet 
program. Then, I went to Montgomery college where I studied 
business for two years and switched majors to Info sci. I think that this is the perfect time for me to join Flatiron schools software engineering program because I left college to pursue a different route than my current major. I chose to not continue forward with my business major because it doesn't interest me and I want to venture into tech. Furthermore, I chose software engineering because I really enjoyed engineering in high school. In conclusion,I never had much but I have never used that as an excuse. Next, my love and curiosity for technology will continue to grow as I further my career. 

Why looping is important as a beginners!

Loops provide a quick and simple way to repeat an action.

Although there are many distinct forms of loops, they all effectively repeat an action a certain number of times.

Out of all of the forms of looping the most vital is for loops.

We need to look more closely at what for loops do as engineers.

here is an examples...

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

A for loop has three parts to it 

 The first I equals where the user wants the loop starts.

 The second I equals where the user wants the loop to end.  

 Finally, the last I equals the incrementation of the loop
863. Leetcode Solution in Cpp
Tags: cpp
Published: 2022-07-14 15:28:06

```
class Solution {
 public:
  vector<int> distanceK(TreeNode* root, TreeNode* target, int K) {
    vector<int> ans;
    unordered_map<TreeNode*, int> nodeToDist;  // {node: distance to target}

    getDists(root, target, nodeToDist);
    dfs(root, K, 0, nodeToDist, ans);

    return ans;
  }

 private:
  void getDists(TreeNode* root, TreeNode* target,
                unordered_map<TreeNode*, int>& nodeToDist) {
    if (!root)
      return;
    if (root == target) {
      nodeToDist[root] = 0;
      return;
    }

    getDists(root->left, target, nodeToDist);
    if (nodeToDist.count(root->left)) {
      // the target is in the left subtree
      nodeToDist[root] = nodeToDist[root->left] + 1;
      return;
    }

    getDists(root->right, target, nodeToDist);
    if (nodeToDist.count(root->right))
      // the target is in the right subtree
      nodeToDist[root] = nodeToDist[root->right] + 1;
  }

  void dfs(TreeNode* root, int K, int dist,
           unordered_map<TreeNode*, int>& nodeToDist, vector<int>& ans) {
    if (!root)
      return;
    if (nodeToDist.count(root))
      dist = nodeToDist[root];
    if (dist == K)
      ans.push_back(root->val);

    dfs(root->left, K, dist + 1, nodeToDist, ans);
    dfs(root->right, K, dist + 1, nodeToDist, ans);
  }
};
```
#leetcode
#challenge
Here is the link for the problem:
https://leetcode.com/problems/all-nodes-distance-k-in-binary-tree/
859. Leetcode Solution in Cpp
Tags: cpp
Published: 2022-07-14 15:27:08

```
class Solution {
 public:
  bool buddyStrings(string A, string B) {
    if (A.length() != B.length())
      return false;
    if (A == B && set<char>(begin(A), end(A)).size() < A.length())
      return true;

    vector<int> diff;

    for (int i = 0; i < A.length(); ++i)
      if (A[i] != B[i])
        diff.push_back(i);

    return diff.size() == 2 && A[diff[0]] == B[diff[1]] &&
           A[diff[1]] == B[diff[0]];
  }
};
```
#leetcode
#challenge
Here is the link for the problem:
https://leetcode.com/problems/buddy-strings/
837. Leetcode Solution in Cpp
Tags: cpp
Published: 2022-07-14 15:26:03

```
class Solution {
 public:
  double new21Game(int n, int k, int maxPts) {
    // when the game ends, the point is in [k..k - 1 + maxPts]
    //   P = 1, if n >= k - 1 + maxPts
    //   P = 0, if n < k (note the constraints already have k <= n)
    if (k == 0 || n >= k - 1 + maxPts)
      return 1.0;

    double ans = 0.0;
    vector<double> dp(n + 1);  // dp[i] := prob to have i points
    dp[0] = 1.0;
    double windowSum = dp[0];  // P(i - 1) + P(i - 2) + ... + P(i - maxPts)

    for (int i = 1; i <= n; ++i) {
      // the prob to get point i is
      // P(i) = [P(i - 1) + P(i - 2) + ... + P(i - maxPts)] / maxPts
      dp[i] = windowSum / maxPts;
      if (i < k)
        windowSum += dp[i];
      else  // the game ends
        ans += dp[i];
      if (i - maxPts >= 0)
        windowSum -= dp[i - maxPts];
    }

    return ans;
  }
};
```
#leetcode
#challenge
Here is the link for the problem:
https://leetcode.com/problems/new-21-game/
846. Leetcode Solution in Cpp
Tags: cpp
Published: 2022-07-14 15:25:04

```
class Solution {
 public:
  bool isNStraightHand(vector<int>& hand, int W) {
    map<int, int> count;

    for (const int card : hand)
      ++count[card];

    for (const auto& [start, _] : count) {
      const int value = count[start];
      if (value > 0)
        for (int i = start; i < start + W; ++i) {
          count[i] -= value;
          if (count[i] < 0)
            return false;
        }
    }

    return true;
  }
};
```

#leetcode
#challenge
Here is the link for the problem:
https://leetcode.com/problems/hand-of-straights/