Skip to content

Instantly share code, notes, and snippets.

void solve(vector<int> &A,int l,int r,vector<int> &ans,map< pair<int,int> , long long > &mp,map< pair<int,int> , int > &index){
if(r-l<=1) {
mp[{l,r}]=0;
}
if(mp.find({l,r})!=mp.end()) return;
long long cost=1e15;
int mn=l+1;
class SegTree{
public:
int n;
int *tree;
SegTree(int nn){
n=nn;
tree=new int[5*nn+5];
memset(tree,0,sizeof(tree));
build(0,n-1,0);
/**
* Definition for binary tree
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
https://www.interviewbit.com/problems/2-sum-binary-tree/
/**
* Definition for binary tree
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
vector<int> Solution::findPerm(const string A, int B) {
vector<int> ans;
int d=0,i;
for(auto x:A) {
if(x=='D') d++;
}
i=d+1;
int Solution::maxProduct(const vector<int> &A) {
int mx=A[0],mn=A[0];
int ans=A[0];
for(int i=1;i<A.size();i++){
int mx1=max(A[i],max(mx*A[i],mn*A[i]));
int mn1=min(A[i],min(mx*A[i],mn*A[i]));
mx=mx1;
mn=mn1;
#include <bits/stdc++.h>
using namespace std;
class BIT_Tree {
private:
int BIT[1008][1008];
public:
void reset(){
memset(BIT,0,sizeof(BIT));
/*
Array uses 0 based index and BIT uses 1 based index, so remember conversions
*/
class BinaryIndexedTree {
int *BIT;
int len;
BinaryIndexedTree(int size){
BIT=new BIT[size+1];
int Solution::repeatedNumber(const vector<int> &A) {
int n=A.size();
int sq=sqrt(n);
int a[sq+5];
memset(a,0,sizeof(a));
for(auto x:A){
int y=sqrt(x);
int Solution::divide(int dividend, int divisor) {
long long ans=0;
int sign=1;
if(dividend<0) sign=sign*(-1);
if(divisor<0) sign=sign*(-1);
long long a=abs((long)dividend);
long long b=abs((long)divisor);