teleren/devto huggingface dataset:
1185. Leetcode Solution in CPP
Tags: cpp
Published: 2022-07-20 05:19:07

```
class Solution {
 public:
  string dayOfTheWeek(int day, int month, int year) {
    vector<string> week = {"Sunday",   "Monday", "Tuesday", "Wednesday",
                           "Thursday", "Friday", "Saturday"};
    vector<int> days = {
        31, isLeapYear(year) ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    int count = 0;

    for (int i = 1971; i < year; ++i)
      count += i % 4 == 0 ? 366 : 365;
    for (int i = 0; i < month - 1; ++i)
      count += days[i];
    count += day;

    return week[(count + 4) % 7];
  }

 private:
  bool isLeapYear(int year) {
    return (year % 4 == 0 && year % 100 != 0) || year % 400 == 0;
  }
};

```

#leetcode
#challenge
Here is the link for the problem:
https://leetcode.com/problems/day-of-the-week/
1037. Leetcode Solution in CPP
Tags: cpp
Published: 2022-07-20 05:17:45

```
class Solution {
 public:
  bool isBoomerang(vector<vector<int>>& points) {
    return (points[1][0] - points[0][0]) * (points[2][1] - points[1][1]) !=
           (points[1][1] - points[0][1]) * (points[2][0] - points[1][0]);
  }
};

```
#leetcode
#challenge
Here is the link for the problem:
https://leetcode.com/problems/valid-boomerang/
1955. Leetcode Solution in CPP
Tags: cpp
Published: 2022-07-20 05:16:30

```
class Solution {
 public:
  int countSpecialSubsequences(vector<int>& nums) {
    // dp[i][j] := # of special subseqs of nums[i:] and prev + 1 = j
    dp.resize(nums.size(), vector<int>(4, -1));
    return countSpecialSubsequences(nums, 0, -1);
  }

 private:
  constexpr static int kMod = 1e9 + 7;
  vector<vector<int>> dp;

  int countSpecialSubsequences(const vector<int>& nums, int i, int prev) {
    if (i == nums.size())
      return prev == 2;
    if (dp[i][prev + 1] != -1)
      return dp[i][prev + 1];

    long ans = 0;

    // not include nums[i]
    ans += countSpecialSubsequences(nums, i + 1, prev);

    // include nums[i]
    if (nums[i] == prev)
      ans += countSpecialSubsequences(nums, i + 1, prev);
    if (prev == -1 && nums[i] == 0)
      ans += countSpecialSubsequences(nums, i + 1, 0);
    if (prev == 0 && nums[i] == 1)
      ans += countSpecialSubsequences(nums, i + 1, 1);
    if (prev == 1 && nums[i] == 2)
      ans += countSpecialSubsequences(nums, i + 1, 2);

    ans %= kMod;
    return dp[i][prev + 1] = ans;
  }
};

```
#leetcode
#challenge
Here is the link for the problem:
https://leetcode.com/problems/count-number-of-special-subsequences/
1912. Leetcode Solution in CPP
Tags: cpp
Published: 2022-07-20 05:15:36

```
class MovieRentingSystem {
 public:
  MovieRentingSystem(int n, vector<vector<int>>& entries) {
    for (const auto& e : entries) {
      const int shop = e[0];
      const int movie = e[1];
      const int price = e[2];
      unrented[movie].insert({price, shop});
      shopAndMovieToPrice[{shop, movie}] = price;
    }
  }

  vector<int> search(int movie) {
    vector<int> ans;
    int i = 0;

    for (const auto& priceAndShops : unrented[movie]) {
      ans.push_back(priceAndShops.second);
      if (++i >= 5)
        break;
    }

    return ans;
  }

  void rent(int shop, int movie) {
    const int price = shopAndMovieToPrice[{shop, movie}];
    unrented[movie].erase({price, shop});
    rented.insert({price, {shop, movie}});
  }

  void drop(int shop, int movie) {
    const int price = shopAndMovieToPrice[{shop, movie}];
    unrented[movie].insert({price, shop});
    rented.erase({price, {shop, movie}});
  }

  vector<vector<int>> report() {
    vector<vector<int>> ans;
    int i = 0;

    for (const auto& [_, shopAndMovie] : rented) {
      ans.push_back({shopAndMovie.first, shopAndMovie.second});
      if (++i >= 5)
        break;
    }

    return ans;
  }

 private:
  struct pairHash {
    size_t operator()(const pair<int, int>& p) const {
      return p.first ^ p.second;
    }
  };

  // {movie: (price, shop)}
  unordered_map<int, set<pair<int, int>>> unrented;

  // {(shop, movie): price}
  unordered_map<pair<int, int>, int, pairHash> shopAndMovieToPrice;

  // (price, (shop, movie))
  set<pair<int, pair<int, int>>> rented;
};

```
#leetcode
#challenge
Here is the link for the problem:
https://leetcode.com/problems/design-movie-rental-system/
828. Leetcode Solution in CPP
Tags: cpp
Published: 2022-07-20 05:14:36

```
class Solution {
 public:
  int uniqueLetterString(string s) {
    int ans = 0;
    int count = 0;
    vector<int> lastCount(26);
    vector<int> lastSeen(26, -1);

    for (int i = 0; i < s.length(); ++i) {
      const int c = s[i] - 'A';
      const int currentCount = i - lastSeen[c];
      count = count - lastCount[c] + currentCount;
      lastCount[c] = currentCount;
      lastSeen[c] = i;
      ans += count;
    }

    return ans;
  }
};

```
#leetcode
#challenge
Here is the link for the problem:
https://leetcode.com/problems/count-unique-characters-of-all-substrings-of-a-given-string/
1828. Leetcode Solution in Java
Tags: java
Published: 2022-07-20 05:11:17

```
class Solution {
 public:
  vector<int> countPoints(vector<vector<int>>& points,
                          vector<vector<int>>& queries) {
    vector<int> ans;

    auto squared = [](int x) { return x * x; };

    for (const auto& q : queries) {
      const int rSquared = q[2] * q[2];
      int count = 0;
      for (const auto& p : points)
        count += squared(p[0] - q[0]) + squared(p[1] - q[1]) <= rSquared;
      ans.push_back(count);
    }

    return ans;
  }
};

```
#leetcode
#challenge
Here is the link for the problem:
https://leetcode.com/problems/queries-on-number-of-points-inside-a-circle/
1976. Leetcode Solution in Java
Tags: java
Published: 2022-07-20 05:09:46

```
class Solution {
    public int countPaths(int n, int[][] roads) {
        final int MODULO = 1000000007;
        Map<Integer, List<int[]>> map = new HashMap<Integer, List<int[]>>();
        for (int[] road : roads) {
            int u = road[0], v = road[1], time = road[2];
            List<int[]> list1 = map.getOrDefault(u, new ArrayList<int[]>());
            List<int[]> list2 = map.getOrDefault(v, new ArrayList<int[]>());
            list1.add(new int[]{v, time});
            list2.add(new int[]{u, time});
            map.put(u, list1);
            map.put(v, list2);
        }
        long[] times = new long[n];
        Arrays.fill(times, Long.MAX_VALUE);
        times[0] = 0;
        PriorityQueue<Integer> priorityQueue = new PriorityQueue<Integer>(new Comparator<Integer>() {
            public int compare(Integer num1, Integer num2) {
                long difference = times[num1] - times[num2];
                if (difference > 0)
                    return 1;
                else if (difference < 0)
                    return -1;
                else
                    return 0;
            }
        });
        priorityQueue.offer(0);
        while (!priorityQueue.isEmpty()) {
            int curNode = priorityQueue.poll();
            long curTime = times[curNode];
            List<int[]> list = map.getOrDefault(curNode, new ArrayList<int[]>());
            for (int[] road : list) {
                int nextNode = road[0], nextTime = road[1];
                long nextTotalTime = curTime + nextTime;
                if (nextTotalTime < times[nextNode]) {
                    times[nextNode] = nextTotalTime;
                    priorityQueue.offer(nextNode);
                }
            }
        }
        boolean[] visited = new boolean[n];
        int[] counts = new int[n];
        visited[0] = true;
        counts[0] = 1;
        priorityQueue.offer(0);
        while (!priorityQueue.isEmpty()) {
            int size = priorityQueue.size();
            int curNode = priorityQueue.poll();
            long curTime = times[curNode];
            int curCount = counts[curNode];
            List<int[]> list = map.getOrDefault(curNode, new ArrayList<int[]>());
            for (int[] road : list) {
                int nextNode = road[0], nextTime = road[1];
                long nextTotalTime = curTime + nextTime;
                if (nextTotalTime == times[nextNode]) {
                    counts[nextNode] = (counts[nextNode] + curCount) % MODULO;
                    if (!visited[nextNode]) {
                        visited[nextNode] = true;
                        priorityQueue.offer(nextNode);
                    }
                }
            }
        }
        return counts[n - 1];
    }
}
```

#leetcode
#challenge
Here is the link for the problem:
https://leetcode.com/problems/number-of-ways-to-arrive-at-destination/
2002. Leetcode Solution in Cpp
Tags: cpp
Published: 2022-07-20 04:59:25

```
class Solution {
 public:
  int maxProduct(string s) {
    size_t ans = 0;
    dfs(s, 0, "", "", ans);
    return ans;
  }

 private:
  void dfs(const string& s, int i, string&& s1, string&& s2, size_t& ans) {
    if (i == s.length()) {
      if (isPalindrome(s1) && isPalindrome(s2))
        ans = max(ans, s1.length() * s2.length());
      return;
    }

    s1.push_back(s[i]);
    dfs(s, i + 1, move(s1), move(s2), ans);
    s1.pop_back();

    s2.push_back(s[i]);
    dfs(s, i + 1, move(s1), move(s2), ans);
    s2.pop_back();

    dfs(s, i + 1, move(s1), move(s2), ans);
  }

  bool isPalindrome(const string& s) {
    int i = 0;
    int j = s.length() - 1;
    while (i < j) {
      if (s[i] != s[j])
        return false;
      ++i;
      --j;
    }
    return true;
  }
};

```
#leetcode
#challenge
Here is the link for the problem:
https://leetcode.com/problems/maximum-product-of-the-length-of-two-palindromic-subsequences/
152. Leetcode Solution in Cpp
Tags: cpp
Published: 2022-07-20 04:57:29

```
class Solution {
public:
    int maxProduct(vector<int>& nums) {
        if(nums.empty()) return 0;
        int maxv=nums[0];
        int minv=nums[0];
        int res=nums[0];
        int pre;
        for(int i=1; i<nums.size(); i++){
            pre=maxv;
            maxv=max(max(minv*nums[i],maxv*nums[i]),nums[i]);
            minv=min(min(pre*nums[i],minv*nums[i]),nums[i]);
            res=max(maxv,res);
        }
        return res;
    }
};
```

#leetcode
#challenge
Here is the link for the problem:
https://leetcode.com/problems/maximum-product-subarray/
152. Leetcode Solution in Python3
Tags: python
Published: 2022-07-20 04:56:52

```
class Solution:
 def maxProduct(self, nums: List[int]) -> int:
  max_prod, min_prod, ans = nums[0], nums[0], nums[0]
 
  for i in range(1, len(nums)):
   tmp = max_prod
   max_prod = max(max_prod * nums[i], min_prod * nums[i], nums[i])
   min_prod = min(tmp * nums[i], min_prod * nums[i], nums[i])
   ans = max(ans, max_prod)
  return ans
```

#leetcode
#challenge
Here is the link for the problem:
https://leetcode.com/problems/maximum-product-subarray/
416. Leetcode Solution in cpp
Tags: cpp
Published: 2022-07-20 04:53:00

```
class Solution {
 public:
  bool canPartition(vector<int>& nums) {
    const int sum = accumulate(begin(nums), end(nums), 0);
    if (sum & 1)
      return false;
    return knapsack(nums, sum / 2);
  }

 private:
  bool knapsack(const vector<int>& nums, int subsetSum) {
    const int n = nums.size();
    // dp[i][j] := true if j can be formed by nums[0..i)
    vector<vector<bool>> dp(n + 1, vector<bool>(subsetSum + 1));
    dp[0][0] = true;

    for (int i = 1; i <= n; ++i) {
      const int num = nums[i - 1];
      for (int j = 0; j <= subsetSum; ++j)
        if (j < num)
          dp[i][j] = dp[i - 1][j];
        else
          dp[i][j] = dp[i - 1][j] || dp[i - 1][j - num];
    }

    return dp[n][subsetSum];
  }
};

```

#leetcode
#challenge
Here is the link for the problem:
https://leetcode.com/problems/partition-equal-subset-sum/
792. Leetcode Solution in CPP
Tags: cpp
Published: 2022-07-20 04:49:25

```
struct TrieNode {
  vector<TrieNode*> children;
  int count = 0;
  TrieNode() : children(26) {}
  ~TrieNode() {
    for (TrieNode* child : children)
      delete child;
  }
};

class Solution {
 public:
  int numMatchingSubseq(string S, vector<string>& words) {
    for (const string& word : words)
      insert(word);

    return dfs(S, 0, &root);
  }

 private:
  TrieNode root;

  void insert(const string& word) {
    TrieNode* node = &root;
    for (const char c : word) {
      const int i = c - 'a';
      if (!node->children[i])
        node->children[i] = new TrieNode;
      node = node->children[i];
    }
    ++node->count;
  }

  int dfs(const string& s, int i, TrieNode* node) {
    int ans = node->count;
    if (i >= s.length())
      return ans;

    for (int j = 0; j < 26; ++j)
      if (node->children[j]) {
        const int index = s.find('a' + j, i);
        if (index != -1)
          ans += dfs(s, index + 1, node->children[j]);
      }

    return ans;
  }
};

```
#leetcode
#challenge
Here is the link for the problem:
https://leetcode.com/problems/number-of-matching-subsequences/
Sistem Yang Aman Dan Berkualitas
Tags: systems, security
Published: 2022-07-20 04:11:09

Sistem adalah suatu kumpulan atau himpunan dari suatu unsur, komponen, atau variabel yang terorganisasi, saling berinteraksi, saling tergantung satu sama lain dan terpadu” Menurut Sutabri (2012:3). Sebuah sistem banyak digunakan oleh perusahaan-perusahaan di Indonesia maupun dunia mulai dari perusahaan kecil hingga perusahaan raksasa. Namun sebuah sistem yang dimiliki tiap perusahaan memiliki keamanan dan kualitas yang berbeda-beda. Hal tersebut dipengaruhi oleh dana yang dianggarkan oleh perusahaan untuk mendanai keamanan dan kualitas dari sistem mereka. Semakin tinggi dana yang dianggarkan,maka sistem akan semakin berkualitas. Namun dari segi keamanan belum tentu sebuah sistem benar-benar aman. Banyak hacker-hacker handal yang sangat
mudahnya membajak sebuah situs yang dikenal sangat aman, seperti yang dikutip dari [](https://www.cnnindonesia.com/nasional/20210223131459-20-609784/hendropriyonousul-tni-rekrut-remaja-ri-pembobol-situs-nasa.“) yaitu bocah berusia 16 tahun asal Tangerang bernama Putera Adji Adhari yang sempat membobol situs keamanan NASA. Diketahui, Putera memiliki keterampilan di bidang komputerisasi secara otodidak. Ia terampil mencari kelemahan sistem dari suatu instansi, lalu menginformasikannya ke instansi terkait agar dapat memperbaikinya. 

Dilansir dari [](https://antariksa.republika.co.id/posts/72049/anggaran-nasa-tahun2022-rp-354-triliun-apa-saja-programnya-
) , DPR dan Senat Amerika Serikat telah menyelesaikan rancangan anggaran pengeluaran omnibus untuk tahun fiskal 2022. Mereka akan memberi NASA anggaran sebesar 24 miliar dan 760 juta dolar AS di bawah anggaran pemerintah. Jika dirupiahkan, anggaran Badan Antariksa Amerika itu untuk tahun ini sebesar Rp 354 triliun . 

Dalam berita tersebut, dapat diketahui setinggi apapun dana yang dikeluarkan untuk mengamankan sebuah sistem, tidak akan pernah ada sistem yang 100 persen aman kecuali sistem tersebut digunakan secara offline.
CSS Battle: #7 - Leafy Trail
Tags: css, webdev, beginners, tutorial
Published: 2022-07-20 04:43:00



In this article, I will solve a [Leafy Trail](https://cssbattle.dev/play/7) CSS Challenge on [CSS Battle](https://cssbattle.dev/). Let's look at the [problem](https://cssbattle.dev/play/7) first.

## Problem 

We need to create the following container by using CSS Properties only:
![Leafy Trail](https://cssbattle.dev/targets/7.png)

## Solution

{% youtube https://youtu.be/st9QuSTtdJA %}

So now look at the Solution and how we are going to achieve this. 

### HTML



```html
<div class="leaf left"></div>
<div class="leaf middle"></div>
<div class="leaf right"></div>
```


### CSS

Now let's style the leaves.
```css
body{
  margin: 0;
  background: #0B2429;
  display: grid;
  place-items: center;
}   
.leaf {
  position: absolute;
  width: 150;
  height: 150;
  border-radius: 100px 0;
} 
.left {
  z-index: 1;
  background: #1A4341;
  margin-left: -100;
}
.middle {
  z-index: 2;
  background: #998235;
} 
.right{
  z-index:3;
  background: #F3AC3C;
  margin-left: 100;
}
```

>*Note: In CSS Battle you can use `100` instead of `100px`. You don't need to define `px` in CSS. However, if you are using `rem` or `%`, you need to pass them separately. That's why in the above CSS code there are no units mostly. For more info [visit here](https://cssbattle.dev/tips)*

>*Minify the code or CSS by using any [CSS Minifier](https://www.minifier.org/). It helps you to reduce the characters in the code which will increase the score.*

### Codepen

{% codepen https://codepen.io/j471n/pen/Vwbjvrq %}

### Wrapping up
If you like this then don't forget to ❤️ it. And I'll see you in the next article. See you soon.
Aggregate Code timing in Python
Tags: python, performance, programming, opensource
Published: 2022-07-20 03:53:17

There are many ways to get how much time a function takes in Python. Here is an easy decorator implementation to check how much time a function takes.

```python
from functools import wraps
import time


def timeit(func):
    @wraps(func)
    def timeit_wrapper(*args, **kwargs):
        start_time = time.perf_counter()
        result = func(*args, **kwargs)
        end_time = time.perf_counter()
        total_time = end_time - start_time
        print(f'Function {func.__name__}{args} {kwargs} took {total_time:.4f} seconds')
        return result
    return timeit_wrapper

@timeit
def my_func():
    # do stuff

```

This decorator can be used by decorating a function to get the time spent.
What if you want to aggregate this timing data in a timeframe, like how many times this function has been called, and what the maximum time is taken, for that, we need to use a library called [codetiming](https://github.com/realpython/codetiming).
Here is a sample use case:


```python
# pip install codetiming
# pip install humanfriendly
from codetiming import Timer
from humanfriendly import format_timespan
from loguru import logger


@Timer(name="my_func", text=lambda secs: f"my_func elapsed time: {format_timespan(secs)}")
def my_func():
    ...

def get_aggregated_timings(cls):
    timed_function = "my_func"
    logger.info(
        f"\n{timed_function} count: {Timer.timers.count(timed_function)}\n"
        f"total: {Timer.timers.total(timed_function)}\n"
        f"max: {Timer.timers.max(timed_function)}\n"
        f"min: {Timer.timers.min(timed_function)}\n"
        f"mean: {Timer.timers.mean(timed_function)}\n"
        f"standard deviation: {Timer.timers.stdev(timed_function)}\n"
        f"median: {Timer.timers.median(timed_function)}\n"
    )
    Timer.timers.clear()  # clears all the timer data

```
This will find the aggregated time spent by `my_func`. Let's go through what each one of them will log:

- _count_: Number of times the function has been called.
- _total_: Sum of all the seconds elapsed in the function
- _max_: Maximum time spent on a single flow
- _min_: Minimum time spent on a single flow
- _mean_: The average of all the time spent on that function
- _median_: The median of all elapsed time
- _stdev_: The standard deviation of all elapsed time

At the end `Timer.timers.clear()` clears the data stored In memory and starts from fresh for the next iteration.

Do you want to use an in-memory LRU cache with a timeout, you may check out this article:

[Cache functions with timeout](https://blog.soumendrak.com/cache-heavy-computation-functions-with-a-timeout-value)

I post on Python programming on my Twitter handle, you can follow me [@soumendrak_](https://www.twitter.com/soumendrak_)

Originally posted at: [my blog](https://blog.soumendrak.com/aggregate-code-timing-in-python)
PROCESS OF WEB DESIGNING & APP DEVELOPMENT AT LIVEUPX PVT. LTD.
Tags: webdev, app, java, php
Published: 2022-07-20 03:50:14

OUR PROCESS OF WEB DESIGNING & APP DEVELOPMENT AT [LIVEUPX PVT LTD](https://Liveupx.com)

## STEP1: UNDERSTANDING REQUIREMENT

An in-depth understanding of client’s need is the foundation of creating a web design that serves the purpose right. Our team spends time in knowing more about your requirement, at the start of the process.

## STEP2: DEFINING PROJECT

Next comes the stage of defining project based on the inputs received from client, results to be achieved, target audience, and existing competition in market.

## STEP3: CREATING WIREFRAME

Wireframe creation is an integral part of website designing, which can’t be overlooked at any point in time. Our creative minds work together to prepare a wireframe that will be right for your business.

## STEP4: DESIGNING INITIAL CONCEPT

The wireframe is given the form of a real design. The initial concept is to get an idea of how the final design would come out to be.

## STEP5: ASKING FOR CLIENT REVIEW AND FEEDBACK

When done with initial concept design, we share the creation with the client seeking their review and feedback. Any changes suggested by the client are implemented at this stage.

## STEP6: TESTING AND DELIVERY

The final design undergoes multiple testing phases to ensure there’s no flaw and it delivers an awesome user-interaction experience. After testing, the design is rolled-out.

## STEP7: 15-DAYS FREE MAINTENANCE

Our service doesn’t end at the delivery of website design. The team offers 15-days free maintenance so that any issue with the website is taken care of immediately, and the experience delivered to your visitors is smooth.


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

For more you can visit: www.liveupx.com
Google Autocomplete Address In Laravel 8
Tags: laravel, google, address, php
Published: 2022-07-20 03:25:35

In this article, we will see how to google autocomplete address in laravel 8. In laravel 8 google autocomplete address tutorial, you will find out how to create and implement a google autocomplete address in laravel with the use of google address API.

So, let's see google autocomplete address in laravel 8, google places autocomplete example, laravel 8 google autocomplete address, autocomplete address google API PHP, autocomplete address google API jquery. autocomplete address google API laravel, google autocomplete address example. google places address autocomplete example, jquery autocomplete address google maps, google map autocomplete address laravel 6/78

Autocomplete is a feature of the Places library in the Maps JavaScript API. You can use autocomplete to give your applications the type-ahead-search behavior of the Google Maps search field. Laravel google autocomplete address helps you display the complete address such as longitude, latitude, country, state, city, and zip code.

```
Step 1: Create Laravel Application for Google Autocomplete Address In Laravel 8

Step 2: Google Place API Key

Step 3: Create Route

Step 4: Create Controller

Step 5: Create Blade View File
```

---

> **_[Read More: Google Autocomplete Address In Laravel 8](https://techsolutionstuff.com/post/google-autocomplete-address-in-laravel-8)_**
About Pomodoro Technique
Tags: productivity, pomodoro, coding
Published: 2022-07-20 02:53:48

Hello, everyone

I begin using the **pomodoro technique** since nearly one week. However, it does not appear to be suitable for problem solvers, as the pomodoro alarm rings when I am in the midst of a problem-solving session, which hurts my mind.

Good Luck!! Safely choose your productivity style.
New Feature of openGauss 3.0.0: Parallel Decoding
Tags: database
Published: 2022-07-20 02:22:07

[Link](https://blog.opengauss.org/en/post/2022/new-feature-of-opengauss-3-0-0-parallel-decoding/)

summarty：With the rapid development of information technology, various types of databases emerge one after another. Logical replication is increasingly important, with which data can be synchronized between heterogeneous databases. Currently, the average serial decoding performance of logical replication in openGauss is only 3 to 5 Mbit/s, which cannot meet the requirements of real-time synchronization in heavy service pressure scenarios. As a result, logs are stacked, affecting services in the production cluster. Therefore, the parallel decoding feature is designed to enable multiple threads to perform decoding in parallel, improving the decoding performance. In basic scenarios, the decoding performance can reach 100 Mbit/s.
openGauss solutions as follow.