let's start Code

801. Minimum Swaps To Make Sequences Increasing

801. Minimum Swaps To Make Sequences Increasing  Solution: class Solution {public:    int minSwap(vector<int>& A, vector<int>& B){  int n = A.size();  vector<int> X(n,0);  vector<int> Y(n,1);  for(int i = 1; i < n; i++){    X[i] = Y[i] = n;   ...
Share:

Sum of subsets

Sum of subsets Solution 01:   A recursive solution for subset sum proble.  #include<bits/stdc++.h>using namespace std;typedef long long ll;map<int , int>M;bool isSubsetsum(int set[], int n, int sum){ // cout << "Enter-------"<<endl;  if(sum == 0)return true;  if(n == 0 && sum != 0)return...
Share:

805. Split Array With Same Average

805. Split Array With Same Average Topic: pruning  + DP. Copmplexity: O(n^3). Soltion:  Code: class Solution {public:    bool is_possible(int m, int sum, int n){  bool possible = false;  for(int i = 1; i <= m; i++)   ...
Share:

Bus Routes

815. Bus Routes complexity : O(n) Topic: BFS  Eplanation class Solution {    #include<bits/stdc++.h>public:    int numBusesToDestination(vector<vector<int> >& routes, int S, int T){    unordered_map<int, unordered_set<int>...
Share:

Consecutive Numbers Sum

829. Consecutive Numbers Sum O( sqrt(N) ) Solution: Code: class Solution {public:    int consecutiveNumbersSum(int N){    int ans = 0;    for(int n = 2; n*(n+1)/2 <= N; ++n){        if(...
Share:

Shortest Bridge

934. Shortest Bridge Problem Type: Recursion; Flood Fill. Code: using island = set<pair<int, int> >;using vi = vector<int>;using vvi = vector<vi>;class Solution{public:    int n;    vi dx = {0, 0, 1, -1};    vi dy = {1, -1, 0, 0};    bool is_valid(int x, int y){       ...
Share:

Groups of Special-Equivalent Strings

893. Groups of Special-Equivalent Strings CODE: class Solution { public:     int numSpecialEquivGroups(vector<string>& A) {         unordered_set<string> s; for(const auto& w: A){    ...
Share:

Minimum Falling Path Sum

931. Minimum Falling Path Sum 1   2  3   4  ------------- 1   2   3   4 4  -1  3  -2  ------------- 5   0   5   1 -2  5  -3  2  ------------- -2  4  -3  3 7   -6  9  8  -------------...
Share:

Tiling Problem/Defective chessboard problem

#include<bits/stdc++.h>using namespace std;int team[500][500],cnt=1,m;void room(int x1, int y1, int X, int Y, int nx, int ny){    if(cnt > m)return;    if(abs(x1 - nx) <= 1 && abs(y1 - ny)<= 1){        for(int i = x1; i <= nx; i++){           ...
Share:

Large Number Factorial

>> Large Number Factorial: #include<bits/stdc++.h> using namespace std; typedef long long ll; #define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); #define INF 10000000 #define MAX 500 int multiply(int x, int res[], int res_size); void factorial(int n) {     int res[MAX];     res[0]...
Share:

About

let's start CODE

Popular Posts