teleren/devto huggingface dataset:
1202. Leetcode Solution in Cpp
Tags: cpp
Published: 2022-07-13 10:07:35

```
class UF {
 public:
  UF(int n) : id(n) {
    iota(begin(id), end(id), 0);
  }

  void union_(int u, int v) {
    id[find(u)] = find(v);
  }

  int find(int u) {
    return id[u] == u ? u : id[u] = find(id[u]);
  }

 private:
  vector<int> id;
};

struct compare {
  bool operator()(const char a, const char b) {
    return a > b;
  }
};

class Solution {
 public:
  string smallestStringWithSwaps(string s, vector<vector<int>>& pairs) {
    string ans;
    UF uf(s.length());
    unordered_map<int, priority_queue<char, vector<char>, compare>> map;

    for (vector<int>& pair : pairs)
      uf.union_(pair[0], pair[1]);

    for (int i = 0; i < s.length(); ++i)
      map[uf.find(i)].push(s[i]);

    for (int i = 0; i < s.length(); ++i)
      ans += map[uf.find(i)].top(), map[uf.find(i)].pop();

    return ans;
  }
};

```

#Leetcode
#challende
Here is the link for the problem:
https://leetcode.com/problems/smallest-string-with-swaps/
1202. Leetcode Solution in Java
Tags: java
Published: 2022-07-13 10:07:04

```
class UF {
  public UF(int n) {
    id = new int[n];
    for (int i = 0; i < n; ++i)
      id[i] = i;
  }

  public void union(int u, int v) {
    id[find(u)] = find(v);
  }

  public int find(int u) {
    return id[u] == u ? u : (id[u] = find(id[u]));
  }

  private int[] id;
}

class Solution {
  public String smallestStringWithSwaps(String s, List<List<Integer>> pairs) {
    StringBuilder ans = new StringBuilder();
    UF uf = new UF(s.length());
    Map<Integer, Queue<Character>> map = new HashMap<>();

    for (List<Integer> pair : pairs)
      uf.union(pair.get(0), pair.get(1));

    for (int i = 0; i < s.length(); ++i)
      map.computeIfAbsent(uf.find(i), k -> new PriorityQueue<>()).offer(s.charAt(i));

    for (int i = 0; i < s.length(); ++i)
      ans.append(map.get(uf.find(i)).poll());

    return ans.toString();
  }
}

```


#Leetcode
#challende
Here is the link for the problem:
https://leetcode.com/problems/smallest-string-with-swaps/
1217. Leetcode Solution in Java
Tags: java
Published: 2022-07-13 10:06:09

```
class Solution {
  public int minCostToMoveChips(int[] chips) {
    int[] count = new int[2];

    for (int chip : chips)
      ++count[chip % 2];

    return Math.min(count[0], count[1]);
  }
}

```
#Leetcode
#challende
Here is the link for the problem:
https://leetcode.com/problems/minimum-cost-to-move-chips-to-the-same-position/
1217. Leetcode Solution in Cpp
Tags: cpp
Published: 2022-07-13 10:05:35

```
class Solution {
 public:
  int minCostToMoveChips(vector<int>& chips) {
    vector<int> count(2);

    for (int chip : chips)
      ++count[chip % 2];

    return min(count[0], count[1]);
  }
};

```
#Leetcode
#challende
Here is the link for the problem:
https://leetcode.com/problems/minimum-cost-to-move-chips-to-the-same-position/
1275. Leetcode Solution in java
Tags: java
Published: 2022-07-13 10:04:37

```
class Solution {
  public String tictactoe(int[][] moves) {
    int[][] row = new int[2][3];
    int[][] col = new int[2][3];
    int[] diag1 = new int[2];
    int[] diag2 = new int[2];

    for (int i = 0; i < moves.length; ++i) {
      int r = moves[i][0];
      int c = moves[i][1];
      int j = i % 2;
      if (++row[j][r] == 3 || ++col[j][c] == 3 || r == c && ++diag1[j] == 3 ||
          r + c == 2 && ++diag2[j] == 3)
        return j == 0 ? "A" : "B";
    }

    return moves.length == 9 ? "Draw" : "Pending";
  }
}

```

#Leetcode
#challende
Here is the link for the problem:
https://leetcode.com/problems/find-winner-on-a-tic-tac-toe-game/
1275. Leetcode Solution in Cpp
Tags: cpp
Published: 2022-07-13 10:04:09

```
class Solution {
 public:
  string tictactoe(vector<vector<int>>& moves) {
    vector<vector<int>> row(2, vector<int>(3));
    vector<vector<int>> col(2, vector<int>(3));
    vector<int> diag1(2);
    vector<int> diag2(2);

    for (int i = 0; i < moves.size(); ++i) {
      int r = moves[i][0];
      int c = moves[i][1];
      int j = i % 2;
      if (++row[j][r] == 3 || ++col[j][c] == 3 || r == c && ++diag1[j] == 3 ||
          r + c == 2 && ++diag2[j] == 3)
        return j == 0 ? "A" : "B";
    }

    return moves.size() == 9 ? "Draw" : "Pending";
  }
};

```

#Leetcode
#challende
Here is the link for the problem:
https://leetcode.com/problems/find-winner-on-a-tic-tac-toe-game/
1266. Leetcode Solution in Java
Tags: java
Published: 2022-07-13 10:03:04

```
class Solution {
    public int minTimeToVisitAllPoints(int[][] points) {
        if(points.length == 1){
            return 0;
        }
        int res = 0;
        for(int i = 1; i < points.length; i++){
            res += Math.max(Math.abs(points[i][0] - points[i - 1][0]),
                           Math.abs(points[i][1] - points[i - 1][1]));   
        }
        return res; 
    }
}
```
#Leetcode
#challende
Here is the link for the problem:
https://leetcode.com/problems/minimum-time-visiting-all-points/
1299. Leetcode Solution in C#
Tags: csharp
Published: 2022-07-13 10:01:56

```
public class Solution {
    public int[] ReplaceElements(int[] arr) {
        int size = arr.Length, maxVal = -1;
        int[] answer = new int[size];
        
        for (int i = size - 1; i >= 0; i--) {
            answer[i] = maxVal;
            maxVal = Math.Max(maxVal, arr[i]);
        }
        
        return answer; 
    }
}
```
#Leetcode
#challende
Here is the link for the problem:
https://leetcode.com/problems/replace-elements-with-greatest-element-on-right-side/
1441. Leetcode Solution in Java
Tags: java
Published: 2022-07-13 09:59:42

```
class Solution {
    public List<String> buildArray(int[] target, int n) {
        List<String> res = new ArrayList<>();
        int current = 0;
        int p = target.length;
        for (int i = 1; i <= n; i++) {
            if (current < p) {
                if (target[current] == i) {
                    res.add("Push");
                    current++;
                } else {
                    res.add("Push");
                    res.add("Pop");
                }
            } else {
                return res;
            }
        }
        return res;
    }
}
```
#Leetcode
#challende
Here is the link for the problem:
https://leetcode.com/problems/build-an-array-with-stack-operations/
How peo and staffing services pair to solve business challenges?
Published: 2022-07-13 09:59:38

[Professional Employer Organizations](https://www.mmepayrollindia.com/professional-employer-organizations-india/) (PEOs) and staffing firms provide employers with specialized services that reduce administrative responsibilities, address business problems, and boost success. Any company owner or HR manager who oversees an expanding operation is aware that expanding the staff is frequently necessary and unavoidable. 

Finding outstanding workers is the best approach to support a company’s expansion, but it takes a lot of work. The advantages of a PEO make it superior to a staffing firm. With a staffing agency, you won’t have access to the former’s multiple jobs. However, both have substantial advantages that will enable you to manage your business more efficiently and save time and money. 

To properly combine these services, take a short look at both models below.

**[Learn More](https://www.mmepayrollindia.com/how-peo-and-staffing-services-pair-to-solve-business-challenges/)**
1464. Leetcode Solution in Cpp
Tags: cpp
Published: 2022-07-13 09:58:34

```
class Solution {
public:
    int maxProduct(vector<int>& nums) {
        int N = nums.size(), ans = 0;
        for (int i = 0; i < N; ++i) {
            for (int j = i + 1; j < N; ++j) ans = max(ans, (nums[i] - 1) * (nums[j] - 1)) ;
        }
        return ans;
    }
};
```
#Leetcode
#challende
Here is the link for the problem:
https://leetcode.com/problems/maximum-product-of-two-elements-in-an-array/
1492. Leetcode Solution in Java
Tags: java
Published: 2022-07-13 09:57:29

```
class Solution {
    public int kthFactor(int n, int k) {
        int current = 0;
        for (int i = 1; i <= n; i++) {
            if (n % i == 0) {
                current++;
                if (current == k) {
                    return i;
                }
            }
        }
        return -1;
    }
}
```
#Leetcode
#challende
Here is the link for the problem:
https://leetcode.com/problems/the-kth-factor-of-n/
1546. Leetcode Solution in Cpp
Tags: cpp
Published: 2022-07-13 09:55:59

```
class Solution {
public:
    int maxNonOverlapping(vector<int>& nums, int target) {
        int n = nums.size();
        /*
        unordered_map's search/insertion/deletion time: 
        average O(1), worst O(n)
        */
        unordered_map<int, int> sum2count;
        int sum = 0;
        int count = 0;
        
        /*
        if we can find a i s.t. nums[0...i] = target,
        count should be sum2count[0]+1 = 1
        */
        sum2count[0] = 0;
        
        for(int i = 0; i < n; ++i){
            //sum: accumulate sum of nums[0...i]
            sum += nums[i];
            
            if(sum2count.find(sum-target) != sum2count.end()){
                /*
                we can find a j s.t. nums[0...j] + target = nums[0...i],
                so nums[j+1...i] sums to target
                */
                //choose btw original count and current found count
                count = max(count, sum2count[sum-target] + 1);
            }
            
            sum2count[sum] = count;
        }
        
        return count;
    }
};
```
#Leetcode
#challende
Here is the link for the problem:
https://leetcode.com/problems/maximum-number-of-non-overlapping-subarrays-with-sum-equals-target/
1584. Leetcode Solution in Cpp
Tags: cpp
Published: 2022-07-13 09:52:53

```
class Solution {
public:
    
    int dist(vector<int>& a, vector<int>& b) {
        return abs(a[0]-b[0]) + abs(a[1]-b[1]);
    }
    
    int minCostConnectPoints(vector<vector<int>>& a) {
        int n = a.size(), ans = 0;
        vector<int> d(n, INT_MAX);
        d[0] = 0;
        for (int _t=0; _t<n; ++_t) {
            int mind = INT_MAX, p = 0;
            for (int i=0; i<n; ++i)
                if (d[i]!=-1 && d[i] < mind) {
                    mind = d[i];
                    p = i;
                }
            ans += mind;
            d[p] = -1;
            for (int j=0; j<n; ++j)
                if (d[j] != -1)
                    d[j] = min(d[j], dist(a[p], a[j]));
        }
        return ans;
    }
};
```
#Leetcode
#challende
Here is the link for the problem:
https://leetcode.com/problems/min-cost-to-connect-all-points/
Freelancing or Part time job in Data Analysis or Visualisation
Tags: freelancing, dataanalysis, job, sql
Published: 2022-07-13 09:52:36

Hi, 
I am looking for freelancing or part time job in Data Analysis or Data Visualisation.
I have 3 years of experince in Data Analysis and SQL ir my primary skill. I am skilled in Excel, MSSQL, Power BI as well. Data Extraction, Cleaning, Validation, Processing, Loading & Visualization is part if my job.
I am available for more than 25 hours/week or more than 5 hours/day and full day on weekends.
Thanks in advance.
1600. Leetcode Solution in Cpp
Tags: cpp
Published: 2022-07-13 09:51:06

```
class ThroneInheritance {
 public:
  ThroneInheritance(string kingName) : kingName(kingName) {}

  void birth(string parentName, string childName) {
    family[parentName].push_back(childName);
  }

  void death(string name) {
    dead.insert(name);
  }

  vector<string> getInheritanceOrder() {
    vector<string> ans;
    dfs(kingName, ans);
    return ans;
  }

 private:
  unordered_set<string> dead;
  unordered_map<string, vector<string>> family;
  string kingName;

  void dfs(const string& name, vector<string>& ans) {
    if (!dead.count(name))
      ans.push_back(name);
    if (!family.count(name))
      return;

    for (const string& child : family[name])
      dfs(child, ans);
  }
};

```
#Leetcode
#challende
Here is the link for the problem:
https://leetcode.com/problems/throne-inheritance/
dynamic loop for parameter combinations
Tags: javascript, codenewbie, help
Published: 2022-07-13 09:19:19

Hi there,

I'm doing JavaScript programming for a short time and I could solve most of my problems on my own searching the web. Most of my programming has been done in Excel VBA so my thinking maybe is still influenced by that.

I use JavaScript in a calculation tool to performe multiple calculations automatically.  

My problem is that I need to setup a dynamic loop to start the calculation with all possible combinations of parameter values.

I have multiple objects like:
```
parameter_01 = {
  trigger: "trigger_01"
  values : [0,2,5]
  }
parameter_02 = {
  trigger: "trigger_02"
  values : [3,6]
  }
...
parameter_xx = {
  trigger: "trigger_xx"
  values : [8,5,9,7,5]
  }
```


The number of parameters and values can change so I don't want to implement a fixed serial of loops iterating each parameter. My first thought is to declare an additional object that contains all parameters I want to take into the calculation:

```
all_parameters = [parameter_01, parameter_02, ... , parameter_xx]
```

Then I would need someting like this:
```
for (var each_paramter of all_parameters) {
    for (var i of each_parameter[values]) {
        setAttr(each_parameter[trigger],i); // This is to set the parameter value in my calculation program
        for (var each_paramter+1 of all_parameters) {
             for (var j of each_parameter+1[values]) {
             setAttr(each_parameter+1[trigger],j);
             ...
                 for (var each_paramter+x of all_parameters) {
                      for (var x of each_parameter+x[values]) {
                      setAttr(each_parameter+1[trigger],x);
                      run_calulation;
                      }
                 }
             }
        }
    }
}
```

Is it possible to create such a dynamic loop? Maybe I'm just searching with the wrong key words. I would appreciate every tip or link that could help me to solve this problem.
1643. Leetcode Solution in CPP
Tags: cpp
Published: 2022-07-13 09:49:11

```
class Solution {
    int comb(int n, int r) {
        long ans = 1;
        for (int i = 1, j = n - r + 1; i <= r; ++i, ++j) ans = ans * j / i;
        return ans;
    }
public:
    string kthSmallestPath(vector<int>& A, int k) {
        int h = A[1], v = A[0], N = h + v;
        string s;
        for (int i = 0; i < N; ++i) {
            if (h) { // we have H available to pick
                int c = comb(h - 1 + v, v); // if we pick H at the current position, there will be `c` combinations for the rest of characters
                if (k <= c) { // k is covered within `c`, so we should pick H.
                    s += 'H';
                    --h;
                } else { // otherwise we should pick V
                    k -= c;
                    s += 'V';
                    --v;
                }
            } else { // no H left, have to pick V.
                s += 'V';
                --v;
            }
        }
        return s;
    }
};
```
#Leetcode
#challende
Here is the link for the problem:
https://leetcode.com/problems/kth-smallest-instructions/
Major Projects For ECE
Tags: webdev, programming, tutorial, react
Published: 2022-07-13 09:40:59

Engineering student projects for B.Tech and M.Tech final year students. Takeoff Edu Group offers a wide range of projects best for [major projects for ece](https://takeoffprojects.com/major-projects-for-ece) looking for magnificent final projects at low cost.

We have successfully delivered major projects for ece to our engineering students. Our programs are specially designed by experts for best results of major projects for ece students. max of the B.Tech, M.Tech, PhD and Diploma scholars.

𝗧𝗮𝗸𝗲𝗼𝗳𝗳 𝗘𝗱𝘂 𝗚𝗿𝗼𝘂𝗽 provides the most creative conceptions and ideas for that can make very effective final year projects for scholars, experimenters, and engineers. So browse through our list of [major projects for ece](https://www.youtube.com/watch?v=kzEHLbvmJgA). contents and choose the smart final year projects for your requirements moment.


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

The full form of ECE is Electronics and Communication Engineering. ECE is an engineering branch that includes the product, design, research and testing of electronic bias and technology issues related to the telecommunications systems, electronics, computers and related artificial sectors. ECE is introduced at the UG and PG standard by several institutions and universities in India applying to B.Tech and M.Tech degrees, independently.

ECE engineers are developing all of the electronic devices in the world, which makes our life simple and agreeable. An ECE generally conducts conditioning similar as designing, constructing and maintaining satellites to offer telephone, TV and internet access to remote and pastoral areas; constructing ultramodern networking services similar as videotape conferencing that connect druggies around the world.

currently, the appetite for strong development in technology has led to the demand for oneness and inventions. The demand has led to the development of colorful operations and ideas. Colleges offering ECE engineering allow the scholars to get the stylish project done for their final year so that they can recommend their profile to the top recruiters.

5 of the Best Project Ideas for ECE Students in Their Final Year
- Robotic vehicle controlled through touch screen-based device.
- Coal mine system for safety alerting and monitoring.
- IoT-based home automation system.
- Home automation for disabled persons using his voice tag.
- IoT-based reduction of electricity theft.
Generate and Add a new SSH key to your GitHub account
Tags: github, ssh, tutorial, git
Published: 2022-07-13 09:35:54

When working with a GitHub repository, you'll often need to identify yourself to GitHub using your username and password. An `SSH key` is an alternate way to identify yourself that doesn't require you to enter you username and password every time. To add such key, you need to generate it on your PC. To generate and add it to GitHub, you need to follow following steps,

## 1. Generate the SSH key

The `SSH key` can be generated using `ssh-keygen` command using git bash as below,

```sh
ssh-keygen -t ed25519 -C "your_email@example.com"
```

> replace *your_email@example.com* with your actual email address.


## 2. Add your SSH key to GitHub

By default, the `SSH key` will be stored in the home directory. Now, you need to copy the public key. The public key can be seen using `cat` command as below,

```sh
cat ~/.ssh/id_rsa.pub
```

Copy the public key from terminal. The final step is to add it to the GitHub. 

![SSH key add to github](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/acc6qbi8q8ckw0z88hud.png)

To add it, go to your GitHub profile `settings` > `SSH and GPG keys` > `new SSH key`, add title for your key and paste the public key in `Key` box.

I hope this post is informative for you. If you like this blog, please support me by subscribing to my YouTube channel: https://www.youtube.com/c/iamtekson
Everyone wants to work with this developer.
Tags: devops, softskills, devtools
Published: 2022-07-13 09:35:34

1. Strategist
— solution oriented not code oriented
— understands that planning is more important than execution

2. Gives reasons not excuses
— excuse: “I tried Q, it didn’t work!”
— reason: “I tried Q, didn’t work because we don’t have X in place. We can either do Y or Z.”

3. Use tools, not letting tools use them
— tools are not suppose to be cool, they can be; Some are…but yeah, the shiniest tool might not be for you

4. Embrace challenges
— see obstacles as opportunities rather than barriers

5. Eager to act on new information
— not to serve a master, just excited to put fresh information to use
—are the first in line to accept a task when it is presented on a subject they are unfamiliar with.

6. Who understand there is no one’s code…it’s everyone’s
— by allowing a piece of code to exists in the codebase (ownership by endorsement)

7. Professional
— do what they promised to do

---

Follow our tech blogs for more articles like this one and others from the ClickPesa development team as they discuss, among other things, their efforts to enhance the development process.

{% embed https://dev.to/clickpesa %}
{% embed https://clickpesa.hashnode.dev %}
Agilitest uses graphic recognition in test automation
Tags: testing, webdev, devops, agile
Published: 2022-07-13 09:31:00

A new feature has emerged in your favorite software testing solution! The graphic recognition of elements of your applications (web, mobile, desktop) to make **comparisons of graphic elements** with each other.

## Logical capture and graphic capture

Until now, detections and comparisons of application elements required capturing an element and its text attributes. To do this, you used the capture tool of Agilitest which allowed you to **dig into the tree structure** of your application and its data logic.

Now, this capture tool has been expanded with a **graphical capture possibility which "photographs"** a small area of ​​the application in order to detect its occurrence during a test, once or several times.

## Implement a graphic capture of your application

To use the graphics recognition functionality, simply open the Agilitest capture tool and **select a rectangular area.** The blue selection rectangle allows you to choose the area to be captured, for later detection during a test.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hcoqqbpt6mwm0xixm40y.png)Selection of a graphic area in Agilitest




Once the image is selected, Agilitest allows you to copy or save the image for external use, but you can also drop the image directly in an Agilitest comment or access the tree of elements to generate an activatable zone...

Read full article [here](https://www.agilitest.com/blog/agilitest-graphical-recognition).