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
# Getting Started, first we load our text file and encode the text with integers. | |
with open('./The Outcasts.txt', 'r') as f: | |
text = f.read() | |
characters = tuple(set(text)) | |
int2char = dict(enumerate(characters)) # enumerate gives the characters their integer values | |
char2int = {char: index for index, char in int2char.items()} # create the dictionary from characters to assigned integers | |
encoded = np.array([char2int[char] for char in text]) # encode text using character to integer dictionary |
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 Solution::trap(const vector<int> &A) { | |
int ans = 0; | |
int n = A.size(); | |
int i = 0, j = n - 1; | |
int lm = -1, rm = -1; | |
while(i < j){ | |
if(A[i] < A[j]){ | |
if(A[i] > lm) lm = A[i]; | |
else ans += (lm - A[i]); | |
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
typedef long long ll; | |
vector<int>ans; | |
vector<int>ar; | |
ll dp[1000][1000]; | |
ll bestcut[1000][1000]; | |
ll sol(int l,int r) | |
{ | |
ll good_cut; | |
if(l + 1 >= r) return 0; | |
if(dp[l][r] != -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 Solution::threeSumClosest(vector<int> &A, int B) { | |
int ans = INT_MIN/2; | |
int n = A.size(); | |
sort(A.begin(),A.end()); | |
int i, j, k; | |
for(int i = 0; i < n; i++){ | |
j = i + 1; | |
k = n - 1; | |
while(j < k){ | |
if(abs(B - (A[i]+A[j]+A[k])) < abs(B - ans)) |
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 fact(int n) | |
{ | |
int i = 0,ans = 1; | |
for(i=1;i<=n;i++) | |
{ | |
ans = ans*i; | |
ans = ans%1000003; | |
} | |
return ans; | |
} |
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
vector<int> Solution::subUnsort(vector<int> &A) { | |
int n = A.size(); | |
if(A[0] > A[n-1]) { | |
vector<int> ret; | |
ret.push_back(0); | |
ret.push_back(n-1); | |
return ret; | |
} | |
vector<int> ret; |