This file contains 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
void preZtBc(char *x, int m, int ztBc[ASIZE][ASIZE]) { | |
int i, j; | |
for (i = 0; i < ASIZE; ++i) | |
for (j = 0; j < ASIZE; ++j) | |
ztBc[i][j] = m; | |
for (i = 0; i < ASIZE; ++i) | |
ztBc[i][x[0]] = m - 1; | |
for (i = 1; i < m - 1; ++i) | |
ztBc[x[i - 1]][x[i]] = m - 1 - i; |
This file contains 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
/* suppose the problem says tha we are given an array with only one unique element and rest all elements have their duplicates and we have to find the | |
unique element in O(n) time and O(1) space complexity then we can use the idea of XOR as shown below: | |
*/ | |
#include<iostream> | |
using namespace std; | |
int main(){ | |
int ans=0; | |
for(int i=0;i<n;++i) | |
ans ^= arr[i]; | |
// this will find the unique element in the array in O(1) space complexity |
This file contains 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
class LRUCache | |
{ | |
public: | |
list<int> dq; | |
int size; | |
unordered_map<int,pair<list<int>::iterator,int>>m; | |
public: | |
//Constructor for initializing the cache capacity with the given value. | |
LRUCache(int cap) |
This file contains 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
class LockingTree { | |
private: | |
vector<int>parent; | |
map<int,vector<int>>children; | |
map<int,int>lockby; | |
public: | |
LockingTree(vector<int>& p):parent(p) { | |
for(int i = 0;i<p.size();++i){ | |
children[p[i]].push_back(i); |
This file contains 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<map> | |
#include<algorithm> | |
using namespace std; | |
// Declaration of all functions | |
//Function 1 |
This file contains 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
ll cnt =0; | |
ll dfs(ll i,ll pre,vector<ll>&a,vector<vector<ll>>&edges,ll val){ | |
ll cur = a[i]; | |
for(auto x:edges[i]){ | |
if(x==pre) | |
continue; | |
cur^=dfs(x,i,a,edges,val); | |
} | |
if(cur==val) | |
++cnt,cur = 0; |
This file contains 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 <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <unistd.h> | |
#include <arpa/inet.h> | |
#include <time.h> | |
// importing files and time lib is used to measure time interval | |
int main(){ | |
char *ip = "127.0.0.1"; |
This file contains 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 <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <unistd.h> | |
#include <arpa/inet.h> | |
// importing libraries | |
int main(){ | |
//intializations | |
char *ip = "127.0.0.1"; |
This file contains 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
map<long long int,long long int>mr,mc; | |
long long int cntc = 0; | |
long long int cntr = 0; | |
long long int i = 0; | |
long long int val = (long long int)(n*n); | |
vector<long long int>ans; | |
while(k--){ | |
long long r = arr[i][0]; | |
long long c = arr[i][1]; |
OlderNewer