let's start Code

Data Structure

1. Vector Most common methods: push_back() -- O(1) [ ] --> bracket operators -- O(1) size() -- O(1)  code: vector<int> v;                   // v = {} cout << v.size() << endl;   // outputs 0 v.push_back(20);           ...
Share:

Construct the Array

Construct the Array Topic: DP Complexity: O(n)  Solution: Code: const long long mod = 1000000000+7;long countArray(int n, int k, int x) {    // Return the number of ways to fill in the array.    vector<long long> a(n),...
Share:

1136 - Division by 3

                              1136 - Division by 3                                                 Explanation #include<bits/stdc++.h> using...
Share:

1182 - Parity

                                      1182 - Parity //copy #include<bits/stdc++.h> using namespace std; int main() { int t; cin >> t; for(int cs = 1; cs <= t; cs++){ int x; cin >> x; ...
Share:

1133 - Array Simulation

1133 - Array Simulation  #include<bits/stdc++.h> using namespace std; typedef long long ll; //map<int , int>M; int main() {      #ifndef ONLINE_JUDGE     freopen("in.txt", "r", stdin);     freopen("out.txt", "w", stdout);   #endif     int t;    ...
Share:

773. Sliding Puzzle

773. Sliding Puzzle source Topic: BFS Time Complexity: (n*m)! Solution 01 class Solution{public:  int slidingPuzzle (vector<vector<int>>& board)  {    constexpr int row = 2;    constexpr int col = 3;    string goal, start;   ...
Share:

771. Jewels and Stones

771. Jewels and Stones   Solution 01:  Complexity: O(N^2) class Solution {public:    int numJewelsInStones(string J, string S) {        int cnt = 0;  for(int i = 0; i < S.size(); i++){    for(int k = 0; k < J.size(); k++){   ...
Share:

Minimize Max Distance to Gas Station

Minimize Max Distance to Gas Station #include<bits/stdc++.h>using namespace std;struct Interval{  Interval (int d): num(d), den(1), dist(d){}  bool operator< (const Interval &d) const {return dist < d.dist;}  double num,den, dist;  void update(){den++, dist = num/den;}};template<typename T>priority_queue<T>...
Share:

779. K-th Symbol in Grammar

779. K-th Symbol in Grammar Nth row  = (N-1)th row + (n-1)th Inverse. Example; 1st row = 0 2nd row = 1st row + 1st row Inverse (01) Every row will power of two. Solution: class Solution {public:    int kthGrammar (int N, int k){  long s = 1 << (N - 1), flips = 0;  while(s > 2){    if(k >...
Share:

SpliBST

SplitBST It's a premium problem. So it's not tested; Solution: vector<TreeNode*> SplitBST(TreeNode* root, int V){  vector<TreeNode*> ans (2, nullptr)  if(root == nullptr) return ans;  int x = root->val > V ? 1 : 0;  int y = root->val > V ? 0 : 1;  auto& node = root->val > V ? root->left...
Share:

About

let's start CODE

Popular Posts