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
from scrapy.crawler import CrawlerProcess | |
from scrapy_tasks.spiders.trial import * | |
class CustomCrawler: | |
def __init__(self): | |
self.output = None | |
self.process = CrawlerProcess(settings={'LOG_ENABLED': False}) |
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
sudo rm /var/lib/apt/lists/lock | |
sudo rm /var/cache/apt/archives/lock | |
sudo rm /var/lib/dpkg/lock |
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
def isSafe(board, row, col): | |
for i in range(col): | |
if board[row][i] == 'Q': | |
return False | |
i = row | |
j = col | |
while i >= 0 and j >= 0: | |
if board[i][j] == 'Q': |
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
def solve(n, o, c, res): | |
if len(res) == 2*n: | |
yield res | |
if o > 0: | |
yield from solve(n, o-1, c, res+'(') | |
# derived from c > 0 and n-o > n-c | |
if c > o: | |
yield from solve(n, o, c-1, res+')') |
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
/* | |
Bitmasks are cool. A bitmask is a string of binary bits (0s and 1s). For example: "01010" is a bitmask. | |
Kuldeep is a naughty but brilliant computer scientist. In his free time, he writes some random programs | |
to play with bitmasks. He has a PhD student under him and to test him (and entertain himself), | |
he has given him the following task: Given a number N, write a bitmask of length N containing all 0s. | |
Now, you are given Q operations. Each operation contains two numbers (l, r) as input. | |
An operation can be one of the following: | |
Update operation: Take the XOR of all the bits in the bitmask from index l to r (both inclusive) with 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 "bits/stdc++.h" | |
using namespace std; | |
int partition(int a[], int low, int high) { | |
/* try with different values of p in range [low, high] */ | |
int p = (low + high) / 2; | |
int i = low; | |
int j = high; | |
while (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
int longestPalindromeSubsequence(string A) { | |
int n = A.length(); | |
int dp[3][n]; | |
int res = 1; | |
for (int l = 1; l <= n; l++) { | |
int idx = (l - 1) % 3; | |
for (int left = 1; left <= n - l + 1; left++) { | |
int right = left + l - 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
/* | |
Hash each subtree recursively and check if that hash already exists. | |
*/ | |
string check_dup(node *root, set<string> &subtrees, int &duplicate_exists) { | |
if (root == NULL) | |
return "#"; | |
string hash_left = check_dup(root->left, subtrees, duplicate_exists); | |
string hash_right = check_dup(root->right, subtrees, duplicate_exists); |
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
typedef vector<vector<int>> graph; | |
graph create(int n, vector<vector<int>> &edges) { | |
graph adj(n, vector<int>(0)); | |
for(auto e : edges) { | |
adj[e[0]].push_back(e[1]); | |
adj[e[1]].push_back(e[0]); | |
} | |
return adj; | |
} |
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 DSU { | |
private: | |
vector<int> arr; | |
vector<int> size; | |
public: | |
DSU(int n) { | |
arr.resize(n); | |
for (int i = 0; i < n; i++) arr[i] = i; | |
size.resize(n, 1); |
OlderNewer