This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <stdio.h> | |
#include <vector> | |
#include <cmath> | |
typedef long long int ll; | |
using namespace std; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <stdio.h> | |
#include <set> | |
#include <map> | |
#define MAX 100010 | |
int a[MAX],b[MAX]; | |
using namespace std; | |
set<int> s; | |
map<int,int> mp; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
#include<vector> | |
#include<set> | |
using namespace std; | |
#define pb push_back | |
#define mp make_pair | |
typedef long long ll; | |
ll n,m,a[333333],b[333333],x,y; | |
vector<ll>v[333333]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
number of ways will be number of ways of its children can be arranged consecutively excluding | |
its root | |
*/ | |
#include <iostream> | |
#include <stdio.h> | |
#include <vector> | |
#include <set> | |
#include <map> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
"This is palindrome partitioning" | |
@author : rohit | |
*/ | |
#include <iostream> | |
#include <stdio.h> | |
#include <cmath> | |
#include <vector> | |
#include <set> | |
#include <algorithm> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <cstring> | |
#include <cmath> | |
#define MAXI 1000000 | |
using namespace std; | |
int func(string s){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Longest palindromic substring (DP approach) | |
time complexity :- O(n^2) | |
space complexity:- O(n^2) | |
@Author : rohit | |
*/ | |
#include <iostream> | |
#include <stdio.h> | |
#include <cmath> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const long INF = 4000000000000LL; | |
int n; | |
// Storing the graph. Each g[i] is a list of edges adjacent to vertex i | |
// each edge is a pair (j,e), where j is the other vertex connected to i | |
// and e is the id of the edge. So L[e] is the weight of the edge. | |
vector<list<tuple<int, int>>> g; | |
vector<int> L; | |
long dist[2000]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Pre-order using iterative traversal | |
void preorder(node *root){ | |
stack<node *> stk; | |
stk.push(root); | |
while(!stk.empty()){ | |
node *temp = stk.top(); | |
cout << temp -> data << " "; | |
stk.pop(); | |
if(temp -> right) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Great solution:- | |
Idea is to swap each positive integer you encounter to its "rightful" place at index (x-1) where x is the integer. It's O(n) because you visit each integer in at most 2 unique loop iterations. | |
Best time complexity:- O(n) | |
Worst time complexity:- O(n^2) | |
Space:- O(1) | |
*/ | |
class Solution { | |
public: |