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; ...
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...
805. Split Array With Same Average
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>...
Consecutive Numbers Sum
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){ ...
Groups of Special-Equivalent Strings
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 -------------...
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++){ ...
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]...