├── Algorithm on Strings ├── Programming Assignment 1 │ ├── _f8a4443f144319c6da63eeb31af4199b_Programming-Assignment-1.pdf │ ├── suffix_tree │ │ └── suffix_tree.cpp │ ├── trie │ │ └── trie.cpp │ ├── trie_matching │ │ └── trie_matching.cpp │ └── trie_matching_extended │ │ └── trie_matching_extended.cpp ├── Programming Assignment 2 │ ├── Programming-Assignment-2.pdf │ ├── bwmatching │ │ └── bwmatching.cpp │ ├── bwt │ │ └── bwt.cpp │ ├── bwtinverse │ │ └── bwtinverse.cpp │ └── suffix_array │ │ └── suffix_array.cpp └── Programming Assignment 3 │ ├── Programming-Assignment-3.pdf │ ├── kmp │ └── kmp.cpp │ ├── suffix_array_long │ └── suffix_array_long.cpp │ ├── suffix_array_matching │ └── suffix_array_matching.cpp │ └── suffix_tree_from_array │ └── suffix_tree_from_array.cpp ├── Algorithmic Tool Box ├── week1_programming_challenges │ ├── 1_sum_of_two_digits │ │ └── APlusB.cpp │ ├── 2_maximum_pairwise_product │ │ └── max_pairwise_product.cpp │ └── week1_programming_challenges.pdf ├── week2_algorithmic_warmup │ ├── 1_fibonacci_number │ │ └── fibonacci.cpp │ ├── 2_last_digit_of_fibonacci_number │ │ └── fibonacci_last_digit.cpp │ ├── 3_greatest_common_divisor │ │ └── gcd.cpp │ ├── 4_least_common_multiple │ │ └── lcm.cpp │ ├── 5_fibonacci_number_again │ │ └── fibonacci_huge.cpp │ ├── 6_last_digit_of_the_sum_of_fibonacci_numbers │ │ └── fibonacci_sum_last_digit.cpp │ ├── 7_last_digit_of_the_sum_of_fibonacci_numbers_again │ │ └── fibonacci_partial_sum.cpp │ ├── 8_last_digit_of_the_sum_of_squares_of_fibonacci_numbers │ │ └── fibonacci_sum_squares.cpp │ └── week2_algorithmic_warmup.pdf ├── week3_greedy_algorithms │ ├── 1_money_change │ │ └── change.cpp │ ├── 2_maximum_value_of_the_loot │ │ └── fractional_knapsack.cpp │ ├── 3_car_fueling │ │ └── car_fueling.cpp │ ├── 4_maximum_advertisement_revenue │ │ └── dot_product.cpp │ ├── 5_collecting_signatures │ │ └── covering_segments.cpp │ ├── 6_maximum_number_of_prizes │ │ └── different_summands.cpp │ ├── 7_maximum_salary │ │ └── largest_number.cpp │ └── week3_greedy_algorithms.pdf ├── week4_divide_and_conquer │ ├── 1_binary_search │ │ └── binary_search.cpp │ ├── 2_majority_element │ │ └── majority_element.cpp │ ├── 3_improving_quicksort │ │ └── sorting.cpp │ ├── 4_number_of_inversions │ │ └── inversions.cpp │ ├── 5_organizing_a_lottery │ │ └── points_and_segments.cpp │ ├── 6_closest_points │ │ └── closest.cpp │ └── week4_divide_and_conquer.pdf ├── week5_dynamic_programming1 │ ├── 1_money_change_again │ │ └── change_dp.cpp │ ├── 2_primitive_calculator │ │ └── primitive_calculator.cpp │ ├── 3_edit_distance │ │ ├── by_learners │ │ │ └── edit_distance.rb │ │ └── edit_distance.cpp │ ├── 4_longest_common_subsequence_of_two_sequences │ │ └── lcs2.cpp │ ├── 5_longest_common_subsequence_of_three_sequences │ │ └── lcs3.cpp │ └── week5_dynamic_programming1.pdf └── week6_dynamic_programming2 │ ├── 1_maximum_amount_of_gold │ └── knapsack.cpp │ ├── 2_partitioning_souvenirs │ └── partition3.cpp │ ├── 3_maximum_value_of_an_arithmetic_expression │ └── placing_parentheses.cpp │ └── week6_dynamic_programming2.pdf ├── Algorithms on Graphs ├── week1_decomposition1 │ ├── 1_reachability │ │ └── reachability.cpp │ ├── 2_connected_components │ │ └── connected_components.cpp │ └── decomposition1.pdf ├── week2_decomposition2 │ ├── 1_acyclicity │ │ └── acyclicity.cpp │ ├── 2_toposort │ │ └── toposort.cpp │ ├── 3_strongly_connected │ │ └── strongly_connected.cpp │ └── decomposition2.pdf ├── week3_paths1 │ ├── 1_bfs │ │ └── bfs.cpp │ ├── 2_bipartite │ │ └── bipartite.cpp │ └── paths1.pdf ├── week4_paths2 │ ├── 1_dijkstra │ │ └── dijkstra.cpp │ ├── 2_negative_cycle │ │ └── negative_cycle.cpp │ └── paths2.pdf └── week5_mst │ ├── 1_connecting_points │ └── connecting_points.cpp │ ├── 2_clustering │ └── clustering.cpp │ └── mst.pdf ├── Data Structures ├── week1_basic_data_structures │ ├── 1_brackets_in_code │ │ └── check_brackets.cpp │ ├── 2_tree_height │ │ └── tree_height.java │ ├── 3_network_simulation │ │ └── process_packages.cpp │ ├── 4_stack_with_max │ │ └── stack_with_max_naive.cpp │ ├── 5_max_sliding_window │ │ └── max_sliding_window.cpp │ └── week1_basic_data_structures.pdf ├── week2_priority_queues_and_disjoint_sets │ ├── 1_make_heap │ │ └── build_heap.cpp │ ├── 3_merging_tables │ │ └── merging_tables.cpp │ └── week2_priority_queues_and_disjoint_sets.pdf ├── week3_hash_tables │ ├── 1_phone_book │ │ └── phone_book.cpp │ ├── 2_hash_chains │ │ └── hash_chains.cpp │ ├── 3_hash_substring │ │ └── hash_substring.cpp │ └── week3_hash_tables.pdf └── week4_binary_search_trees │ ├── 1_tree_traversals │ └── tree_orders.cpp │ ├── 2_is_bst │ └── is_bst.cpp │ ├── 3_is_bst_advanced │ └── is_bst_hard.cpp │ └── week4_binary_search_trees.pdf ├── LICENSE └── README.md /Algorithm on Strings/Programming Assignment 1/_f8a4443f144319c6da63eeb31af4199b_Programming-Assignment-1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Roopam-mishra/Data-Structures-and-Algorithms-Coursera/0422c64769909ad82c631c14e814d958136afc18/Algorithm on Strings/Programming Assignment 1/_f8a4443f144319c6da63eeb31af4199b_Programming-Assignment-1.pdf -------------------------------------------------------------------------------- /Algorithm on Strings/Programming Assignment 1/suffix_tree/suffix_tree.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | typedef long long int ll; 4 | typedef unsigned long long int ull; 5 | typedef long double ld; 6 | #define MOD 1000000007 7 | #define INF 1000000000000000000 8 | #define endll "\n" 9 | #define pb push_back 10 | #define forn(i,n) for(i=0;i> 13 | #define pll pair 14 | #define vll vector 15 | #define ff first 16 | #define ss second 17 | #define bs binary_search 18 | #define lb lower_bound 19 | #define ub upper_bound 20 | #define test ll t;cin>>t; while(t--) 21 | #define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 22 | 23 | vll SortCharacters(string& s) 24 | { 25 | vll order(s.length()); 26 | ll count[27]={0},i; 27 | for(i=0;i=0;i--) 39 | { 40 | ll x=s[i]-'A'+1; 41 | count[x]-=1; 42 | order[count[x]]=i; 43 | } 44 | return order; 45 | } 46 | 47 | vll ComputeCharClasses(string& s, vll& order) 48 | { 49 | vll clss(s.length()); 50 | ll i; 51 | clss[order[0]]=0; 52 | for(i=1;i=0;i--) 76 | { 77 | start=(order[i]-len+s.length())%s.length(); 78 | cl=clss[start]; 79 | count[cl]-=1; 80 | newOrder[count[cl]]=start; 81 | } 82 | return newOrder; 83 | } 84 | 85 | vll UpdateClasses(vll& newOrder,vll& clss,ll len) 86 | { 87 | ll n=newOrder.size(),i,cur,prev,midprev,mid; 88 | vll newClass(n); 89 | newClass[newOrder[0]]=0; 90 | for(i=1;i child; 156 | ll stringdepth,edgestart,edgeend; 157 | SuffixTreeNode(SuffixTreeNode* w,ll x,ll y,ll z) 158 | { 159 | parent=w; 160 | stringdepth=x; 161 | edgestart=y; 162 | edgeend=z; 163 | } 164 | }; 165 | 166 | SuffixTreeNode* CreateNewLeaf(SuffixTreeNode* node,string& s,ll suffix) 167 | { 168 | SuffixTreeNode* leaf=new SuffixTreeNode(node,s.length()-suffix,suffix+node->stringdepth,s.length()-1); 169 | node->child[s[leaf->edgestart]]=leaf; 170 | return leaf; 171 | } 172 | 173 | SuffixTreeNode* BreakEdge(SuffixTreeNode* node,string& s,ll start,ll offset) 174 | { 175 | char startchar=s[start]; 176 | char midchar=s[start+offset]; 177 | SuffixTreeNode* midnode=new SuffixTreeNode(node,node->stringdepth+offset,start,start+offset-1); 178 | midnode->child[midchar]=node->child[startchar]; 179 | node->child[startchar]->parent=midnode; 180 | node->child[startchar]->edgestart+=offset; 181 | node->child[startchar]=midnode; 182 | return midnode; 183 | } 184 | 185 | SuffixTreeNode* STFormSA(string& s,vll& order, vll& lcparray) 186 | { 187 | SuffixTreeNode* root=new SuffixTreeNode(NULL,0,-1,-1); 188 | ll lcpprev=0,i,suffix; 189 | SuffixTreeNode* curnode=root; 190 | for(i=0;istringdepth>lcpprev) 194 | curnode=curnode->parent; 195 | if(curnode->stringdepth==lcpprev) 196 | curnode=CreateNewLeaf(curnode,s,suffix); 197 | else 198 | { 199 | ll edgestart=order[i-1]+curnode->stringdepth; 200 | ll offset=lcpprev-curnode->stringdepth; 201 | SuffixTreeNode* midnode=BreakEdge(curnode,s,edgestart,offset); 202 | curnode=CreateNewLeaf(midnode,s,suffix); 203 | } 204 | if(ichild) 214 | { 215 | cout<edgestart,j.second->edgeend+1-j.second->edgestart)<edgestart<<" "<edgeend+1<>s; 226 | ll i; 227 | vll order=SortCharacters(s); 228 | vll clss=ComputeCharClasses(s,order); 229 | ll len=1; 230 | while(len 2 | using namespace std; 3 | typedef long long int ll; 4 | typedef unsigned long long int ull; 5 | typedef long double ld; 6 | #define MOD 1000000007 7 | #define INF 1000000000000000000 8 | #define endll "\n" 9 | #define pb push_back 10 | #define forn(i,n) for(i=0;i> 13 | #define pll pair 14 | #define vll vector 15 | #define ff first 16 | #define ss second 17 | #define bs binary_search 18 | #define lb lower_bound 19 | #define ub upper_bound 20 | #define test ll t;cin>>t; while(t--) 21 | #define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 22 | ll k=0; 23 | struct node 24 | { 25 | char ch; 26 | ll val; 27 | struct node* child[26]; 28 | bool last; 29 | node() 30 | { 31 | last=false; 32 | ll i; 33 | forn(i,26) 34 | { 35 | child[i]=NULL; 36 | } 37 | } 38 | }; 39 | 40 | void trieconstruct(node* root,string &s) 41 | { 42 | ll i; 43 | node* temp=root; 44 | forn(i,s.length()) 45 | { 46 | ll x=s[i]-'A'; 47 | if(temp->child[x]==NULL) 48 | { 49 | node* newnode=new node(); 50 | newnode->ch=s[i]; 51 | newnode->val=k++; 52 | temp->child[x]=newnode; 53 | } 54 | temp=temp->child[x]; 55 | } 56 | temp->last=true; 57 | } 58 | 59 | bool prefixtriematch(node* root, string s) 60 | { 61 | node* temp=root; 62 | ll i; 63 | forn(i,s.length()) 64 | { 65 | ll x=s[i]-'A'; 66 | if(temp->child[x]==NULL) 67 | return false; 68 | temp=temp->child[x]; 69 | } 70 | return true; 71 | } 72 | 73 | bool searchaword(string s,node* root) 74 | { 75 | node* temp=root; 76 | ll i; 77 | forn(i,s.length()) 78 | { 79 | ll x=s[i]-'A'; 80 | if(temp->child[x]==NULL) 81 | return false; 82 | temp=temp->child[x]; 83 | } 84 | return temp->last; 85 | } 86 | 87 | void dfs(node* root) 88 | { 89 | ll i; 90 | for(i=0;i<26;i++) 91 | { 92 | if(root->child[i]!=NULL) 93 | { 94 | cout<val<<"->"<child[i]->val<<":"<child[i]->ch<child[i]); 96 | } 97 | } 98 | } 99 | 100 | int main() 101 | { 102 | fast_io; 103 | node* root; 104 | root=new node(); 105 | root->val=k++; 106 | ll i,n; 107 | string s; 108 | cin>>n; 109 | forn(i,n) 110 | { 111 | cin>>s; 112 | trieconstruct(root,s); 113 | } 114 | dfs(root); 115 | return 0; 116 | } 117 | 118 | -------------------------------------------------------------------------------- /Algorithm on Strings/Programming Assignment 1/trie_matching/trie_matching.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | typedef long long int ll; 4 | typedef unsigned long long int ull; 5 | typedef long double ld; 6 | #define MOD 1000000007 7 | #define INF 1000000000000000000 8 | #define endll "\n" 9 | #define pb push_back 10 | #define forn(i,n) for(i=0;i> 13 | #define pll pair 14 | #define vll vector 15 | #define ff first 16 | #define ss second 17 | #define bs binary_search 18 | #define lb lower_bound 19 | #define ub upper_bound 20 | #define test ll t;cin>>t; while(t--) 21 | #define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 22 | ll k=0; 23 | vll v; 24 | struct node 25 | { 26 | char ch; 27 | ll val; 28 | struct node* child[26]; 29 | bool last; 30 | node() 31 | { 32 | last=false; 33 | ll i; 34 | forn(i,26) 35 | { 36 | child[i]=NULL; 37 | } 38 | } 39 | }; 40 | 41 | void trieconstruct(node* root,string &s) 42 | { 43 | ll i; 44 | node* temp=root; 45 | forn(i,s.length()) 46 | { 47 | ll x=s[i]-'A'; 48 | if(temp->child[x]==NULL) 49 | { 50 | node* newnode=new node(); 51 | newnode->ch=s[i]; 52 | newnode->val=k++; 53 | temp->child[x]=newnode; 54 | } 55 | temp=temp->child[x]; 56 | } 57 | temp->last=true; 58 | } 59 | 60 | bool prefixtriematch(node* root,string s) 61 | { 62 | node* temp=root; 63 | ll i; 64 | forn(i,s.length()) 65 | { 66 | ll x=s[i]-'A'; 67 | if(temp->child[x]==NULL) 68 | return false; 69 | temp=temp->child[x]; 70 | } 71 | return true; 72 | } 73 | 74 | bool searchaword(node* root,string s,ll i) 75 | { 76 | node* temp=root; 77 | for(;ilast==true) 81 | return true; 82 | else 83 | if(temp->child[x]==NULL) 84 | return false; 85 | else 86 | temp=temp->child[x]; 87 | } 88 | return temp->last; 89 | } 90 | 91 | void dfs(node* root) 92 | { 93 | ll i; 94 | for(i=0;i<26;i++) 95 | { 96 | if(root->child[i]!=NULL) 97 | { 98 | cout<val<<"->"<child[i]->val<<":"<child[i]->ch<child[i]); 100 | } 101 | } 102 | } 103 | 104 | int main() 105 | { 106 | fast_io; 107 | node* root; 108 | root=new node(); 109 | root->val=k++; 110 | ll i,n; 111 | string s,a; 112 | cin>>s; 113 | cin>>n; 114 | forn(i,n) 115 | { 116 | cin>>a; 117 | trieconstruct(root,a); 118 | } 119 | for(i=0;i 2 | using namespace std; 3 | typedef long long int ll; 4 | typedef unsigned long long int ull; 5 | typedef long double ld; 6 | #define MOD 1000000007 7 | #define INF 1000000000000000000 8 | #define endll "\n" 9 | #define pb push_back 10 | #define forn(i,n) for(i=0;i> 13 | #define pll pair 14 | #define vll vector 15 | #define ff first 16 | #define ss second 17 | #define bs binary_search 18 | #define lb lower_bound 19 | #define ub upper_bound 20 | #define test ll t;cin>>t; while(t--) 21 | #define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 22 | ll k=0; 23 | vll v; 24 | struct node 25 | { 26 | char ch; 27 | ll val; 28 | struct node* child[26]; 29 | bool last; 30 | node() 31 | { 32 | last=false; 33 | ll i; 34 | forn(i,26) 35 | { 36 | child[i]=NULL; 37 | } 38 | } 39 | }; 40 | 41 | void trieconstruct(node* root,string &s) 42 | { 43 | ll i; 44 | node* temp=root; 45 | forn(i,s.length()) 46 | { 47 | ll x=s[i]-'A'; 48 | if(temp->child[x]==NULL) 49 | { 50 | node* newnode=new node(); 51 | newnode->ch=s[i]; 52 | newnode->val=k++; 53 | temp->child[x]=newnode; 54 | } 55 | temp=temp->child[x]; 56 | } 57 | temp->last=true; 58 | } 59 | 60 | bool prefixtriematch(node* root,string s) 61 | { 62 | node* temp=root; 63 | ll i; 64 | forn(i,s.length()) 65 | { 66 | ll x=s[i]-'A'; 67 | if(temp->child[x]==NULL) 68 | return false; 69 | temp=temp->child[x]; 70 | } 71 | return true; 72 | } 73 | 74 | bool searchaword(node* root,string s,ll i) 75 | { 76 | node* temp=root; 77 | for(;ilast==true) 81 | return true; 82 | else 83 | if(temp->child[x]==NULL) 84 | return false; 85 | else 86 | temp=temp->child[x]; 87 | } 88 | return temp->last; 89 | } 90 | 91 | void dfs(node* root) 92 | { 93 | ll i; 94 | for(i=0;i<26;i++) 95 | { 96 | if(root->child[i]!=NULL) 97 | { 98 | cout<val<<"->"<child[i]->val<<":"<child[i]->ch<child[i]); 100 | } 101 | } 102 | } 103 | 104 | int main() 105 | { 106 | fast_io; 107 | node* root; 108 | root=new node(); 109 | root->val=k++; 110 | ll i,n; 111 | string s,a; 112 | cin>>s; 113 | cin>>n; 114 | forn(i,n) 115 | { 116 | cin>>a; 117 | trieconstruct(root,a); 118 | } 119 | for(i=0;i 2 | using namespace std; 3 | typedef long long int ll; 4 | typedef unsigned long long int ull; 5 | typedef long double ld; 6 | #define MOD 1000000007 7 | #define INF 1000000000000000000 8 | #define endll "\n" 9 | #define pb push_back 10 | #define forn(i,n) for(i=0;i> 13 | #define pll pair 14 | #define vll vector 15 | #define ff first 16 | #define ss second 17 | #define bs binary_search 18 | #define lb lower_bound 19 | #define ub upper_bound 20 | #define test ll t;cin>>t; while(t--) 21 | #define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 22 | 23 | void PreprocessBWT(string& bwt,map& starts,map>& occ_count_before) 24 | { 25 | string bwt2=bwt; 26 | ll i; 27 | sort(bwt2.begin(),bwt2.end()); 28 | for(i=0;i& starts,map>& occ_count_before) 51 | { 52 | ll top,bottom; 53 | char symbol; 54 | top=0; 55 | bottom=bwt.length()-1; 56 | while(top<=bottom) 57 | { 58 | if(pattern.size()!=0) 59 | { 60 | symbol=pattern.back(); 61 | pattern.pop_back(); 62 | if(starts.find(symbol)!=starts.end()) 63 | { 64 | top=starts.find(symbol)->second+occ_count_before.find(symbol)->second[top]; 65 | bottom=starts.find(symbol)->second+occ_count_before.find(symbol)->second[bottom+1]-1; 66 | } 67 | else 68 | return 0; 69 | } 70 | else 71 | return bottom-top+1; 72 | } 73 | return 0; 74 | } 75 | 76 | int main() 77 | { 78 | fast_io; 79 | string bwt,pattern; 80 | cin>>bwt; 81 | ll pattern_count,i,occ_count; 82 | cin>>pattern_count; 83 | map starts; 84 | map> occ_count_before; 85 | PreprocessBWT(bwt, starts, occ_count_before); 86 | for(i=0;i>pattern; 89 | occ_count=CountOccurrences(pattern,bwt,starts,occ_count_before); 90 | cout< 2 | using namespace std; 3 | typedef long long int ll; 4 | typedef unsigned long long int ull; 5 | typedef long double ld; 6 | #define MOD 1000000007 7 | #define INF 1000000000000000000 8 | #define endll "\n" 9 | #define pb push_back 10 | #define forn(i,n) for(i=0;i> 13 | #define pll pair 14 | #define vll vector 15 | #define ff first 16 | #define ss second 17 | #define bs binary_search 18 | #define lb lower_bound 19 | #define ub upper_bound 20 | #define test ll t;cin>>t; while(t--) 21 | #define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 22 | 23 | void consructBWT(string s) 24 | { 25 | vector v; 26 | ll l=s.length(); 27 | s+=s; 28 | ll i; 29 | for(i=0;i>s; 46 | consructBWT(s); 47 | return 0; 48 | } 49 | 50 | -------------------------------------------------------------------------------- /Algorithm on Strings/Programming Assignment 2/bwtinverse/bwtinverse.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | typedef long long int ll; 4 | typedef unsigned long long int ull; 5 | typedef long double ld; 6 | #define MOD 1000000007 7 | #define INF 1000000000000000000 8 | #define endll "\n" 9 | #define pb push_back 10 | #define forn(i,n) for(i=0;i> 13 | #define pll pair 14 | #define vll vector 15 | #define ff first 16 | #define ss second 17 | #define bs binary_search 18 | #define lb lower_bound 19 | #define ub upper_bound 20 | #define test ll t;cin>>t; while(t--) 21 | #define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 22 | 23 | void inverseBWT(string s) 24 | { 25 | ll l=s.length(); 26 | ll i,j; 27 | vector> v; 28 | for(i=0;i x; 32 | x=v[0]; 33 | for(i=0;i>s; 45 | inverseBWT(s); 46 | return 0; 47 | } 48 | 49 | -------------------------------------------------------------------------------- /Algorithm on Strings/Programming Assignment 2/suffix_array/suffix_array.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | typedef long long int ll; 4 | typedef unsigned long long int ull; 5 | typedef long double ld; 6 | #define MOD 1000000007 7 | #define INF 1000000000000000000 8 | #define endll "\n" 9 | #define pb push_back 10 | #define forn(i,n) for(i=0;i> 13 | #define pll pair 14 | #define vll vector 15 | #define ff first 16 | #define ss second 17 | #define bs binary_search 18 | #define lb lower_bound 19 | #define ub upper_bound 20 | #define test ll t;cin>>t; while(t--) 21 | #define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 22 | 23 | vll SortCharacters(string& s) 24 | { 25 | vll order(s.length()); 26 | ll count[27]={0},i; 27 | for(i=0;i=0;i--) 39 | { 40 | ll x=s[i]-'A'+1; 41 | count[x]-=1; 42 | order[count[x]]=i; 43 | } 44 | return order; 45 | } 46 | 47 | vll ComputeCharClasses(string& s, vll& order) 48 | { 49 | vll clss(s.length()); 50 | ll i; 51 | clss[order[0]]=0; 52 | for(i=1;i=0;i--) 76 | { 77 | start=(order[i]-len+s.length())%s.length(); 78 | cl=clss[start]; 79 | count[cl]-=1; 80 | newOrder[count[cl]]=start; 81 | } 82 | return newOrder; 83 | } 84 | 85 | vll UpdateClasses(vll& newOrder,vll& clss,ll len) 86 | { 87 | ll n=newOrder.size(),i,cur,prev,midprev,mid; 88 | vll newClass(n); 89 | newClass[newOrder[0]]=0; 90 | for(i=1;i>s; 109 | ll i; 110 | vll order=SortCharacters(s); 111 | vll clss=ComputeCharClasses(s,order); 112 | ll len=1; 113 | while(len 2 | using namespace std; 3 | typedef long long int ll; 4 | typedef unsigned long long int ull; 5 | typedef long double ld; 6 | #define MOD 1000000007 7 | #define INF 1000000000000000000 8 | #define endll "\n" 9 | #define pb push_back 10 | #define forn(i,n) for(i=0;i> 13 | #define pll pair 14 | #define vll vector 15 | #define ff first 16 | #define ss second 17 | #define bs binary_search 18 | #define lb lower_bound 19 | #define ub upper_bound 20 | #define test ll t;cin>>t; while(t--) 21 | #define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 22 | 23 | void createLPS(string pattern,ll m,ll *lps) 24 | { 25 | ll len=0; //length of the previous longest prefix which is also a suffix 26 | lps[0]=0; 27 | ll i=1; 28 | while(i>pattern>>text; 84 | ll n=text.length(); 85 | ll m=pattern.length(); 86 | if(m>n) 87 | cout< 2 | using namespace std; 3 | typedef long long int ll; 4 | typedef unsigned long long int ull; 5 | typedef long double ld; 6 | #define MOD 1000000007 7 | #define INF 1000000000000000000 8 | #define endll "\n" 9 | #define pb push_back 10 | #define forn(i,n) for(i=0;i> 13 | #define pll pair 14 | #define vll vector 15 | #define ff first 16 | #define ss second 17 | #define bs binary_search 18 | #define lb lower_bound 19 | #define ub upper_bound 20 | #define test ll t;cin>>t; while(t--) 21 | #define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 22 | 23 | vll SortCharacters(string& s) 24 | { 25 | vll order(s.length()); 26 | ll count[27]={0},i; 27 | for(i=0;i=0;i--) 39 | { 40 | ll x=s[i]-'A'+1; 41 | count[x]-=1; 42 | order[count[x]]=i; 43 | } 44 | return order; 45 | } 46 | 47 | vll ComputeCharClasses(string& s, vll& order) 48 | { 49 | vll clss(s.length()); 50 | ll i; 51 | clss[order[0]]=0; 52 | for(i=1;i=0;i--) 76 | { 77 | start=(order[i]-len+s.length())%s.length(); 78 | cl=clss[start]; 79 | count[cl]-=1; 80 | newOrder[count[cl]]=start; 81 | } 82 | return newOrder; 83 | } 84 | 85 | vll UpdateClasses(vll& newOrder,vll& clss,ll len) 86 | { 87 | ll n=newOrder.size(),i,cur,prev,midprev,mid; 88 | vll newClass(n); 89 | newClass[newOrder[0]]=0; 90 | for(i=1;i>s; 109 | ll i; 110 | vll order=SortCharacters(s); 111 | vll clss=ComputeCharClasses(s,order); 112 | ll len=1; 113 | while(len 2 | using namespace std; 3 | typedef long long int ll; 4 | typedef unsigned long long int ull; 5 | typedef long double ld; 6 | #define MOD 1000000007 7 | #define INF 1000000000000000000 8 | #define endll "\n" 9 | #define pb push_back 10 | #define forn(i,n) for(i=0;i> 13 | #define pll pair 14 | #define vll vector 15 | #define ff first 16 | #define ss second 17 | #define bs binary_search 18 | #define lb lower_bound 19 | #define ub upper_bound 20 | #define test ll t;cin>>t; while(t--) 21 | #define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 22 | 23 | vll SortCharacters(string& s) 24 | { 25 | vll order(s.length()); 26 | ll count[27]={0},i; 27 | for(i=0;i=0;i--) 39 | { 40 | ll x=s[i]-'A'+1; 41 | count[x]-=1; 42 | order[count[x]]=i; 43 | } 44 | return order; 45 | } 46 | 47 | vll ComputeCharClasses(string& s, vll& order) 48 | { 49 | vll clss(s.length()); 50 | ll i; 51 | clss[order[0]]=0; 52 | for(i=1;i=0;i--) 76 | { 77 | start=(order[i]-len+s.length())%s.length(); 78 | cl=clss[start]; 79 | count[cl]-=1; 80 | newOrder[count[cl]]=start; 81 | } 82 | return newOrder; 83 | } 84 | 85 | vll UpdateClasses(vll& newOrder,vll& clss,ll len) 86 | { 87 | ll n=newOrder.size(),i,cur,prev,midprev,mid; 88 | vll newClass(n); 89 | newClass[newOrder[0]]=0; 90 | for(i=1;i ss; 105 | 106 | void PatternMatchingWithSuffixArray(string& text,string& pattern,vll& order) 107 | { 108 | ll l,r,start,end,i; 109 | l=0; 110 | r=text.size(); 111 | while(l(text.substr(order[m],pattern.length()))) 115 | l=m+1; 116 | else 117 | r=m; 118 | } 119 | start=l; 120 | r=text.size(); 121 | while(lend) 131 | return; 132 | if(start<=end) 133 | { 134 | for(i=start;i>s; 145 | s+='$'; 146 | ll i,n; 147 | vll order=SortCharacters(s); 148 | vll clss=ComputeCharClasses(s,order); 149 | ll len=1; 150 | while(len>n; 157 | for(i=0;i>pattern; 160 | PatternMatchingWithSuffixArray(s,pattern,order); 161 | } 162 | for (auto it=ss.begin();it !=ss.end();++it) 163 | cout<<*it<<" "; 164 | cout< 2 | using namespace std; 3 | typedef long long int ll; 4 | typedef unsigned long long int ull; 5 | typedef long double ld; 6 | #define MOD 1000000007 7 | #define INF 1000000000000000000 8 | #define endll "\n" 9 | #define pb push_back 10 | #define forn(i,n) for(i=0;i> 13 | #define pll pair 14 | #define vll vector 15 | #define ff first 16 | #define ss second 17 | #define bs binary_search 18 | #define lb lower_bound 19 | #define ub upper_bound 20 | #define test ll t;cin>>t; while(t--) 21 | #define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 22 | 23 | struct SuffixTreeNode 24 | { 25 | SuffixTreeNode* parent{nullptr}; 26 | map child; 27 | ll stringdepth{0}; 28 | ll edgestart{-1}; 29 | ll edgeend{-1}; 30 | SuffixTreeNode(SuffixTreeNode* w,ll x,ll y,ll z) 31 | { 32 | parent=w; 33 | stringdepth=x; 34 | edgestart=y; 35 | edgeend=z; 36 | } 37 | }; 38 | 39 | SuffixTreeNode* CreateNewLeaf(SuffixTreeNode* node,string& s,ll suffix) 40 | { 41 | SuffixTreeNode* leaf=new SuffixTreeNode(node,s.length()-suffix,suffix+node->stringdepth,s.length()-1); 42 | node->child[s[leaf->edgestart]]=leaf; 43 | return leaf; 44 | } 45 | 46 | SuffixTreeNode* BreakEdge(SuffixTreeNode* node,string& s,ll start,ll offset) 47 | { 48 | char startchar=s[start]; 49 | char midchar=s[start+offset]; 50 | SuffixTreeNode* midnode=new SuffixTreeNode(node,node->stringdepth+offset,start,start+offset-1); 51 | midnode->child[midchar]=node->child[startchar]; 52 | node->child[startchar]->parent=midnode; 53 | node->child[startchar]->edgestart=node->child[startchar]->edgestart+offset; 54 | node->child[startchar]=midnode; 55 | return midnode; 56 | } 57 | 58 | SuffixTreeNode* STFormSA(string& s,vll& order, vll& lcparray) 59 | { 60 | SuffixTreeNode* root=new SuffixTreeNode(nullptr,0,-1,-1); 61 | ll lcpprev=0,i,suffix; 62 | SuffixTreeNode* curnode=root; 63 | ll N=s.size(); 64 | for(i=0;istringdepth > lcpprev) 68 | curnode=curnode->parent; 69 | if(curnode->stringdepth == lcpprev) 70 | curnode=CreateNewLeaf(curnode,s,suffix); 71 | else 72 | { 73 | ll edgestart = order[i-1] + curnode->stringdepth; 74 | ll offset = lcpprev - curnode->stringdepth; 75 | SuffixTreeNode* midnode=BreakEdge(curnode,s,edgestart,offset); 76 | curnode = CreateNewLeaf(midnode,s,suffix); 77 | } 78 | if(iedgestart!=-1 && root->edgeend!=-1) 86 | cout<edgestart<<" "<edgeend+1<<"\n"; 87 | for(auto j: root->child) 88 | { 89 | dfs(j.second); 90 | // cout<edgestart<<" "<edgeend+1<>s; 99 | ll i; 100 | ll N=s.size(); 101 | vll order(N); 102 | vll lcparray(N-1); 103 | for(i=0;i>order[i]; 105 | for(i=0;i>lcparray[i]; 107 | SuffixTreeNode* root=STFormSA(s,order,lcparray); 108 | cout< 2 | using namespace std; 3 | typedef long long int ll; 4 | int main() 5 | { 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(NULL); 8 | cout.tie(NULL); 9 | ll a,b; 10 | cin>>a>>b; 11 | cout< 2 | using namespace std; 3 | typedef long long int ll; 4 | int main() 5 | { 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(NULL); 8 | cout.tie(NULL); 9 | ll n,i; 10 | cin>>n; 11 | ll a[n]; 12 | for(i=0;i>a[i]; 14 | sort(a,a+n); 15 | cout< 2 | using namespace std; 3 | typedef long long int ll; 4 | int main() 5 | { 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(NULL); 8 | cout.tie(NULL); 9 | ll n,i; 10 | ll a[55]; 11 | a[0]=0; 12 | a[1]=1; 13 | for(i=2;i<=50;i++) 14 | a[i]=a[i-1]+a[i-2]; 15 | cin>>n; 16 | cout< 2 | using namespace std; 3 | typedef long long int ll; 4 | int main() 5 | { 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(NULL); 8 | cout.tie(NULL); 9 | ll n,i; 10 | cin>>n; 11 | ll a[n+1]; 12 | a[0]=0; 13 | a[1]=1; 14 | for(i=2;i<=n;i++) 15 | { 16 | a[i]=(a[i-1]+a[i-2])%10; 17 | } 18 | cout< 2 | using namespace std; 3 | typedef long long int ll; 4 | int main() 5 | { 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(NULL); 8 | cout.tie(NULL); 9 | ll x1,y1,a1,b1,d; 10 | cin>>a1>>b1; 11 | x1=a1; 12 | y1=b1; 13 | while(1) 14 | { 15 | d=b1%a1; 16 | if(d==0) 17 | break; 18 | b1=a1; 19 | a1=d; 20 | } 21 | cout< 2 | using namespace std; 3 | typedef long long int ll; 4 | int main() 5 | { 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(NULL); 8 | cout.tie(NULL); 9 | ll x1,y1,a1,b1,d; 10 | cin>>a1>>b1; 11 | x1=a1; 12 | y1=b1; 13 | while(1) 14 | { 15 | d=b1%a1; 16 | if(d==0) 17 | break; 18 | b1=a1; 19 | a1=d; 20 | } 21 | cout<<(x1*y1)/a1< 2 | using namespace std; 3 | typedef long long int ll; 4 | void muly(long long int F[2][2], long long int M[2][2],long long int m); 5 | void pow(long long int F[2][2], long long int n,long long int m); 6 | long long int fib(long long int n,long long int m) 7 | { 8 | long long int F[2][2] = {{1,1},{1,0}}; 9 | if (n == 0) 10 | return 0; 11 | pow(F, n-1,m); 12 | return F[0][0]; 13 | } 14 | void muly(long long int F[2][2],long long int M[2][2],long long int m) 15 | { 16 | long long int x = (F[0][0]*M[0][0]%m + F[0][1]*M[1][0]%m)%m; 17 | long long int y = (F[0][0]*M[0][1]%m + F[0][1]*M[1][1]%m)%m; 18 | long long int z = (F[1][0]*M[0][0]%m + F[1][1]*M[1][0]%m)%m; 19 | long long int w = (F[1][0]*M[0][1]%m + F[1][1]*M[1][1]%m)%m; 20 | 21 | F[0][0] = x; 22 | F[0][1] = y; 23 | F[1][0] = z; 24 | F[1][1] = w; 25 | } 26 | void pow(long long int F[2][2],long long int n,long long int m) 27 | { 28 | long long int i; 29 | if(n == 0 || n == 1) return; 30 | long long int M[2][2] = {{1,1},{1,0}}; 31 | pow(F,n/2, m); 32 | muly(F, F, m); 33 | if(n % 2 != 0) muly(F, M, m); 34 | } 35 | int main() 36 | { 37 | ios_base::sync_with_stdio(false); 38 | cin.tie(NULL); 39 | cout.tie(NULL); 40 | ll n,m; 41 | cin>>n>>m; 42 | cout< 2 | using namespace std; 3 | typedef long long int ll; 4 | int main() 5 | { 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(NULL); 8 | cout.tie(NULL); 9 | ll n,i,x; 10 | cin>>n; 11 | ll a[65],s[65]; 12 | a[0]=0; 13 | a[1]=1; 14 | s[0]=0; 15 | s[1]=1; 16 | for(i=2;i<=60;i++) 17 | { 18 | a[i]=(a[i-1]+a[i-2])%10; 19 | s[i]=(s[i-1]+a[i])%10; 20 | } 21 | if(n==0) 22 | cout<<"0"< 2 | using namespace std; 3 | typedef long long int ll; 4 | int main() 5 | { 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(NULL); 8 | cout.tie(NULL); 9 | ll n,m,i,x,y,k,p,q,r,o; 10 | cin>>n>>m; 11 | o=m-n; 12 | p=o/60; 13 | q=n%60; 14 | r=m%60; 15 | ll a[65],s[65]; 16 | a[0]=0; 17 | a[1]=1; 18 | s[0]=0; 19 | s[1]=1; 20 | for(i=2;i<=60;i++) 21 | { 22 | a[i]=(a[i-1]+a[i-2])%10; 23 | s[i]=(s[i-1]+a[i])%10; 24 | } 25 | /*for(i=0;i<=60;i++) 26 | cout< 2 | using namespace std; 3 | typedef long long int ll; 4 | int main() 5 | { 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(NULL); 8 | cout.tie(NULL); 9 | ll n,i,x,y; 10 | cin>>n; 11 | ll a[65],s[65]; 12 | a[0]=0; 13 | a[1]=1; 14 | s[0]=0; 15 | s[1]=1; 16 | for(i=2;i<=60;i++) 17 | { 18 | a[i]=(a[i-1]+a[i-2])%10; 19 | s[i]=(s[i-1]+(((a[i-1]+a[i-2])%10)*((a[i-1]+a[i-2])%10))%10)%10; 20 | } 21 | if(n==0) 22 | cout<<"0"< 2 | using namespace std; 3 | typedef long long int ll; 4 | int main() 5 | { 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(NULL); 8 | cout.tie(NULL); 9 | ll n,x,s=0; 10 | cin>>n; 11 | x=n/10; 12 | s+=x; 13 | n=n-(10*x); 14 | x=n/5; 15 | s+=x; 16 | n=n-(5*x); 17 | s+=n; 18 | cout< 2 | using namespace std; 3 | typedef long long int ll; 4 | struct roop 5 | { 6 | ll v; 7 | ll w; 8 | long double p; 9 | }; 10 | bool comp (roop a,roop b) 11 | { 12 | return a.p>b.p; 13 | } 14 | int main() 15 | { 16 | ios_base::sync_with_stdio(false); 17 | cin.tie(NULL); 18 | cout.tie(NULL); 19 | ll n,W,i; 20 | long double value; 21 | cin>>n>>W; 22 | struct roop a[n]; 23 | for(i=0;i>a[i].v; 26 | cin>>a[i].w; 27 | a[i].p=(long double)((1.0*a[i].v)/a[i].w); 28 | } 29 | sort(a,a+n,comp); 30 | value=0; 31 | for(i=0;iW) 45 | { 46 | value+=(W*1.0*a[i].p); 47 | W=W-W; 48 | } 49 | } 50 | cout< 2 | using namespace std; 3 | typedef long long int ll; 4 | int main() 5 | { 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(NULL); 8 | cout.tie(NULL); 9 | ll m,n,d,numrefill,currrefill,lastrefill,i; 10 | cin>>d>>m>>n; 11 | ll a[n+2]; 12 | a[0]=0; 13 | for(i=1;i<=n;i++) 14 | cin>>a[i]; 15 | a[n+1]=d; 16 | numrefill=0; 17 | currrefill=0; 18 | while(currrefill<=n) 19 | { 20 | lastrefill=currrefill; 21 | while(currrefill<=n && (a[currrefill+1]-a[lastrefill]<=m)) 22 | { 23 | currrefill=currrefill+1; 24 | } 25 | if(currrefill==lastrefill) 26 | { 27 | cout<<"-1"< 2 | using namespace std; 3 | typedef long long int ll; 4 | int main() 5 | { 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(NULL); 8 | cout.tie(NULL); 9 | ll n,i,f; 10 | cin>>n; 11 | ll a[n],b[n]; 12 | for(i=0;i>a[i]; 14 | for(i=0;i>b[i]; 16 | sort(a,a+n); 17 | sort(b,b+n); 18 | f=0; 19 | for(i=0;i 2 | using namespace std; 3 | typedef long long int ll; 4 | struct roop 5 | { 6 | ll starting; 7 | ll ending; 8 | }; 9 | bool comp(roop p,roop q) 10 | { 11 | if(p.ending==q.ending) 12 | return p.starting>n; 23 | struct roop r[n]; 24 | for(i=0;i>r[i].starting>>r[i].ending; 27 | } 28 | sort(r,r+n,comp); 29 | /*for(i=0;i=r[i].starting && p<=r[i].ending) 41 | continue; 42 | else 43 | if(pr[i].ending) 44 | { 45 | p=r[i].ending; 46 | b[k++]=p; 47 | } 48 | } 49 | cout< 2 | using namespace std; 3 | typedef long long int ll; 4 | int main() 5 | { 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(NULL); 8 | cout.tie(NULL); 9 | ll n,k,x,y,i; 10 | cin>>n; 11 | if(n==1) 12 | { 13 | cout<<"1"< 2 | using namespace std; 3 | typedef long long int ll; 4 | int main() 5 | { 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(NULL); 8 | cout.tie(NULL); 9 | ll n,i,k,x,y,j; 10 | cin>>n; 11 | string s[n]; 12 | for(i=0;i>s[i]; 15 | } 16 | sort(s,s+n); 17 | /*for(i=0;i=0;i--) 26 | { 27 | string ab=to_string(i); 28 | x=lower_bound(s,s+n,ab)-s; 29 | y=upper_bound(s,s+n,ab)-s; 30 | if(binary_search(s,s+n,ab)==1) 31 | { 32 | for(j=x;j=y;j--) 36 | cout< 2 | using namespace std; 3 | typedef long long int ll; 4 | int main() 5 | { 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(NULL); 8 | cout.tie(NULL); 9 | ll n,k,i,x; 10 | cin>>n; 11 | ll a[n]; 12 | for(i=0;i>a[i]; 14 | cin>>k; 15 | ll b[k]; 16 | for(i=0;i>b[i]; 18 | for(i=0;i 2 | using namespace std; 3 | typedef long long int ll; 4 | int main() 5 | { 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(NULL); 8 | cout.tie(NULL); 9 | ll n,x,s,i; 10 | vector v; 11 | cin>>n; 12 | ll a[n]; 13 | for(i=0;i>a[i]; 15 | sort(a,a+n); 16 | s=1; 17 | for(i=1;i(n/2)) 36 | { 37 | cout<<"1"< 2 | using namespace std; 3 | typedef long long int ll; 4 | int main() 5 | { 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(NULL); 8 | cout.tie(NULL); 9 | ll n,x,s,i; 10 | cin>>n; 11 | ll a[n]; 12 | for(i=0;i>a[i]; 14 | sort(a,a+n); 15 | for(i=0;i 2 | using namespace std; 3 | typedef long long int ll; 4 | ll merge( long long int a[],long long int l,long long int m,long long int r) 5 | { 6 | long long int i,j,k,cnt=0; 7 | long long int n1=m-l+1; 8 | long long int n2=r-m; 9 | long long int L[n1],R[n2]; 10 | for(i=0;i>n; 63 | ll a[n]; 64 | for(i=0;i>a[i]; 66 | cout< 2 | using namespace std; 3 | typedef long long int ll; 4 | struct roop 5 | { 6 | ll x; 7 | ll y; 8 | }; 9 | bool comp2(roop a, roop b) 10 | { 11 | return a.x>n>>k; 30 | struct roop rup[k+1]; 31 | struct roop r[2*n+k+1]; 32 | ll arr[k+1]; 33 | //cout<>a>>b; 37 | r[2*i].x=a; 38 | r[2*i].y=1; 39 | r[2*i+1].x=b; 40 | r[2*i+1].y=3; 41 | } 42 | for(i=0;i>c; 45 | r[2*n+i].x=c; 46 | r[2*n+i].y=2; 47 | rup[i].x=c; 48 | rup[i].y=i; 49 | } 50 | sort(rup,rup+k,comp2); 51 | sort(r,r+(2*n+k),comp); 52 | c=0; 53 | l=0; 54 | for(i=0;i<(2*n+k);i++) 55 | { 56 | if(r[i].y==1) 57 | c++; 58 | else 59 | if(r[i].y==3) 60 | c--; 61 | else 62 | if(r[i].y==2) 63 | { 64 | arr[rup[l++].y]=c; 65 | } 66 | } 67 | for(i=0;i 2 | using namespace std; 3 | typedef long long int ll; 4 | struct point 5 | { 6 | ll x, y; 7 | }; 8 | bool compareX(point a,point b) 9 | { 10 | return a.x>n; 72 | struct point p[n]; 73 | for(i=0;i>p[i].x>>p[i].y; 76 | } 77 | sort(p,p+n,compareX); 78 | cout< 2 | using namespace std; 3 | #define MAX 1000000000000000000 4 | typedef long long int ll; 5 | int main() 6 | { 7 | ios_base::sync_with_stdio(false); 8 | cin.tie(NULL); 9 | cout.tie(NULL); 10 | ll n,i,j,numcoins,a[3]; 11 | a[0]=1; 12 | a[1]=3; 13 | a[2]=4; 14 | cin>>n; 15 | ll minnumcoins[n+1]; 16 | minnumcoins[0]=0; 17 | for(i=1;i<=n;i++) 18 | { 19 | minnumcoins[i]=MAX; 20 | for(j=0;j<3;j++) 21 | { 22 | if(i>=a[j]) 23 | { 24 | numcoins=minnumcoins[i-a[j]]+1; 25 | if(numcoins 2 | using namespace std; 3 | typedef long long int ll; 4 | #define MAX 1000000000000000000 5 | int main() 6 | { 7 | ios_base::sync_with_stdio(false); 8 | cin.tie(NULL); 9 | cout.tie(NULL); 10 | ll n,i,nc1,nc2,nc3,z,y; 11 | cin>>n; 12 | vector> vec(n+1); 13 | ll a[n+1]; 14 | a[0]=0; 15 | vec[0].push_back(0); 16 | a[1]=0; 17 | vec[1].push_back(1); 18 | for(i=2;i<=n;i++) 19 | { 20 | a[i]=MAX; 21 | nc1=nc2=nc3=MAX; 22 | if(i%3==0) 23 | { 24 | nc1=a[i/3]+1; 25 | } 26 | if(i%2==0) 27 | { 28 | nc2=a[i/2]+1; 29 | } 30 | nc3=a[i-1]+1; 31 | if(nc1<=nc2 && nc1<=nc3) 32 | { 33 | z=nc1; 34 | y=i/3; 35 | } 36 | else 37 | if(nc2<=nc1 && nc2<=nc3) 38 | { 39 | z=nc2; 40 | y=i/2; 41 | } 42 | else 43 | { 44 | z=nc3; 45 | y=i-1; 46 | } 47 | copy(vec[y].begin(), vec[y].end(), back_inserter(vec[i])); 48 | vec[i].push_back(i); 49 | a[i]=z; 50 | } 51 | cout< 2 | using namespace std; 3 | typedef long long int ll; 4 | bool compare(ll p, ll q) 5 | { 6 | return (p>a>>b; 17 | l1=strlen(a); 18 | l2=strlen(b); 19 | for(i=l1;i>=1;i--) 20 | { 21 | a[i]=a[i-1]; 22 | } 23 | a[0]='0'; 24 | //cout<=1;i--) 26 | { 27 | b[i]=b[i-1]; 28 | } 29 | b[0]='0'; 30 | //cout< 2 | using namespace std; 3 | typedef long long int ll; 4 | #define MAX 100000000000000000; 5 | int main() 6 | { 7 | ios_base::sync_with_stdio(false); 8 | cin.tie(NULL); 9 | cout.tie(NULL); 10 | ll n1,m1,i,j; 11 | cin>>n1; 12 | ll arr1[n1+1]; 13 | arr1[0]=0; 14 | for(i=1;i<=n1;i++) 15 | cin>>arr1[i]; 16 | cin>>m1; 17 | ll arr2[m1+1]; 18 | arr2[0]=0; 19 | for(i=1;i<=m1;i++) 20 | cin>>arr2[i]; 21 | ll dp[n1+1][m1+1]; 22 | for(i=0;i<=n1;i++) 23 | dp[i][0]=0; 24 | 25 | for(i=0;i<=m1;i++) 26 | dp[0][i]=0; 27 | for(i=1;i<=n1;i++) 28 | { 29 | for(j=1;j<=m1;j++) 30 | { 31 | if(arr1[i]==arr2[j]) 32 | dp[i][j]=1+dp[i-1][j-1]; 33 | else 34 | dp[i][j]=max(dp[i-1][j],dp[i][j-1]); 35 | } 36 | } 37 | cout< 2 | using namespace std; 3 | typedef long long int ll; 4 | int main() 5 | { 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(NULL); 8 | cout.tie(NULL); 9 | ll n,i,j,k,m,l; 10 | cin>>n; 11 | ll arr1[n+1]; 12 | arr1[0]=0; 13 | for(i=1;i<=n;i++) 14 | cin>>arr1[i]; 15 | cin>>m; 16 | ll arr2[m+1]; 17 | arr2[0]=0; 18 | for(i=1;i<=m;i++) 19 | cin>>arr2[i]; 20 | cin>>l; 21 | ll arr3[l+1]; 22 | arr3[0]=0; 23 | for(i=1;i<=l;i++) 24 | cin>>arr3[i]; 25 | ll dp[n+1][m+1][l+1]; 26 | for(i=0;i<=n;i++) 27 | { 28 | for(j=0;j<=m;j++) 29 | { 30 | for(k=0;k<=l;k++) 31 | { 32 | if(i==0 || j==0 || k==0) 33 | dp[i][j][k]=0; 34 | else 35 | if(arr1[i]==arr2[j] && arr1[i]==arr3[k]) 36 | dp[i][j][k]=dp[i-1][j-1][k-1]+1; 37 | else 38 | dp[i][j][k]=max(dp[i][j-][k],max(dp[i-1][j][k],dp[i][j][k-1])); 39 | } 40 | } 41 | } 42 | cout< 2 | using namespace std; 3 | typedef long long int ll; 4 | int main() 5 | { 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(NULL); 8 | cout.tie(NULL); 9 | ll W,n,i,n1,W1,val,j; 10 | cin>>W>>n; 11 | ll wt[n+1],value[n+1]; 12 | for(i=1;i<=n;i++) 13 | { 14 | cin>>wt[i]; 15 | value[i]=wt[i]; 16 | } 17 | ll w; 18 | n1=n+1; 19 | W1=W+1; 20 | vector K(n1 * W1); 21 | for(i=0;i 2 | using namespace std; 3 | typedef long long int ll; 4 | bool Possible(ll a[],ll subsetSum[],bool used[],ll sumofeachsubset,ll n,ll currIndex,ll lastindex) 5 | { 6 | ll i,temp; 7 | bool next; 8 | if(subsetSum[currIndex]==sumofeachsubset) 9 | { 10 | if(currIndex==1) 11 | return true; 12 | return Possible(a,subsetSum,used,sumofeachsubset,n,currIndex+1,n-1); 13 | } 14 | for(i=lastindex;i>=0;i--) 15 | { 16 | if(used[i]) 17 | continue; 18 | temp=subsetSum[currIndex]+a[i]; 19 | if (temp<=sumofeachsubset) 20 | { 21 | used[i]=true; 22 | subsetSum[currIndex]+=a[i]; 23 | next=Possible(a,subsetSum,used,sumofeachsubset,n,currIndex,i-1); 24 | used[i]=false; 25 | subsetSum[currIndex]-=a[i]; 26 | if(next) 27 | return true; 28 | } 29 | } 30 | return false; 31 | } 32 | int main() 33 | { 34 | ios_base::sync_with_stdio(false); 35 | cin.tie(NULL); 36 | cout.tie(NULL); 37 | ll n,i,k,sum,sumofeachsubset; 38 | cin>>n; 39 | ll a[n],subsetSum[3]; 40 | bool used[n]; 41 | for(i=0;i>a[i]; 43 | if (n<3) 44 | { 45 | cout<<"0"< 2 | using namespace std; 3 | long long calculate(long long sha, long long roop, char xyz) 4 | { 5 | if (xyz == '*') 6 | return sha * roop; 7 | else 8 | if (xyz == '+') 9 | return sha + roop; 10 | else 11 | if (xyz == '-') 12 | return sha - roop; 13 | else 14 | assert(0); 15 | } 16 | int main() 17 | { 18 | ios_base::sync_with_stdio(false); 19 | cin.tie(NULL); 20 | cout.tie(NULL); 21 | char a[50]; 22 | cin>>a; 23 | long long l,n,i,s,j,k,minvalue,maxvalue,p,b,c,d; 24 | l=strlen(a); 25 | n=(l+1)/2; 26 | //cout<=1;i--) 28 | { 29 | a[i]=a[i-1]; 30 | } 31 | a[0]='0'; 32 | long long mina[n+1][n+1]; 33 | long long maxa[n+1][n+1]; 34 | memset(mina,0,sizeof(mina)); 35 | memset(maxa,0,sizeof(maxa)); 36 | for(i=1;i<=n;i++) 37 | { 38 | mina[i][i]=a[2*i-1]-'0'; 39 | maxa[i][i]=a[2*i-1]-'0'; 40 | } 41 | for(s=1;s<=n-1;s++) 42 | { 43 | for(i=1;i<=n-s;i++) 44 | { 45 | j=i+s; 46 | minvalue=LLONG_MAX; 47 | maxvalue=LLONG_MIN; 48 | for(k=i;k<=j-1;k++) 49 | { 50 | p=calculate(maxa[i][k],maxa[k+1][j],a[2*k]); 51 | b=calculate(maxa[i][k],mina[k+1][j],a[2*k]); 52 | c=calculate(mina[i][k],maxa[k+1][j],a[2*k]); 53 | d=calculate(mina[i][k],mina[k+1][j],a[2*k]); 54 | minvalue=min(minvalue,min(p,min(b,min(c,d)))); 55 | maxvalue=max(maxvalue,max(p,max(b,max(c,d)))); 56 | } 57 | mina[i][j]=minvalue; 58 | maxa[i][j]=maxvalue; 59 | } 60 | } 61 | /*for(i=1;i<=n;i++) 62 | { 63 | for(j=1;j<=n;j++) 64 | { 65 | cout< 2 | using namespace std; 3 | typedef long long int ll; 4 | #define INF 100000000 5 | int main() 6 | { 7 | ios_base::sync_with_stdio(false); 8 | cin.tie(NULL); 9 | cout.tie(NULL); 10 | ll n,m,i,x,a,b,u,v; 11 | cin>>n>>m; 12 | vector adj[n+1]; 13 | for(i=0;i>a>>b; 16 | adj[a].push_back(b); 17 | adj[b].push_back(a); 18 | } 19 | ll visited[n+1]; 20 | ll level[n+1]; 21 | for(i=0;i<=n;i++) 22 | { 23 | visited[i]=0; 24 | level[i]=-1; 25 | } 26 | cin>>u>>v; 27 | queue q; 28 | q.push(u); 29 | level[u]=1; 30 | visited[u]=1; 31 | while(!q.empty()) 32 | { 33 | x=q.front(); 34 | for(i=0;i 2 | using namespace std; 3 | typedef long long int ll; 4 | #define INF LLONG_MAX 5 | int main() 6 | { 7 | ios_base::sync_with_stdio(false); 8 | cin.tie(NULL); 9 | cout.tie(NULL); 10 | ll n,m,i,j,x,a,b,u,v; 11 | cin>>n>>m; 12 | vector adj[n+1]; 13 | for(i=0;i>a>>b; 16 | adj[a].push_back(b); 17 | adj[b].push_back(a); 18 | } 19 | ll visited[n+1]; 20 | for(i=0;i<=n;i++) 21 | { 22 | visited[i]=0; 23 | } 24 | ll c=0; 25 | for(j=1;j<=n;j++) 26 | { 27 | if(!visited[j]) 28 | { 29 | visited[j]=1; 30 | queue q; 31 | q.push(j); 32 | while(!q.empty()) 33 | { 34 | x=q.front(); 35 | for(i=0;i 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | using namespace std; 16 | #define ll long long 17 | #define MOD 1000000007 18 | #define MAX 1000000000000000000 19 | #define ln "\n" 20 | #define pb push_back 21 | #define pll pair 22 | #define mp make_pair 23 | #define f first 24 | #define s second 25 | #define Test ll t;cin>>t;while(t--) 26 | #define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL); 27 | vector color; 28 | vector parent; 29 | ll cycle_start, cycle_end; 30 | bool dfs(ll v,vector adj[]) 31 | { 32 | color[v]=1; 33 | for(auto u:adj[v]) 34 | { 35 | if(color[u]==0) 36 | { 37 | parent[u]=v; 38 | if(dfs(u,adj)) 39 | return true; 40 | } 41 | else 42 | if(color[u]==1) 43 | { 44 | cycle_end=v; 45 | cycle_start=u; 46 | return true; 47 | } 48 | } 49 | color[v]=2; 50 | return false; 51 | } 52 | int main() 53 | { 54 | fast_io; 55 | ll n,m,i,a,b; 56 | cin>>n>>m; 57 | vector adj[n+1]; 58 | for(i=0;i>a>>b; 61 | adj[a].push_back(b); 62 | //adj[b].push_back(a); 63 | } 64 | color.assign(n+1,0); 65 | parent.assign(n+1,-1); 66 | cycle_start=-1; 67 | for(i=1;i<=n;i++) 68 | { 69 | if(color[i]==0 && dfs(i,adj)) 70 | { 71 | break; 72 | } 73 | } 74 | if(cycle_start==-1) 75 | cout<<0< cycle; 80 | cycle.push_back(cycle_start); 81 | for(i=cycle_end;i!=cycle_start;i=parent[i]) 82 | { 83 | cycle.push_back(i); 84 | } 85 | cycle.push_back(cycle_start); 86 | reverse(cycle.begin(), cycle.end()); 87 | cout<<"Cycle:"< 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | using namespace std; 16 | #define ll long long 17 | #define MOD 1000000007 18 | #define MAX 1000000000000000000 19 | #define ln "\n" 20 | #define pb push_back 21 | #define pll pair 22 | #define mp make_pair 23 | #define f first 24 | //#define s second 25 | #define Test ll t;cin>>t; while(t--) 26 | #define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL); 27 | vector ans; 28 | vector visited; 29 | void dfs(vector adj[],ll s) 30 | { 31 | visited[s]=true; 32 | for (auto i:adj[s]) 33 | { 34 | if(!visited[i]) 35 | dfs(adj,i); 36 | } 37 | ans.pb(s); 38 | } 39 | void topological_sorting(vector adj[],ll n) 40 | { 41 | visited.assign(n+1,false); 42 | ans.clear(); 43 | for(ll i=1;i<=n;i++) 44 | { 45 | if(!visited[i]) 46 | { 47 | dfs(adj,i); 48 | } 49 | } 50 | reverse(ans.begin(),ans.end()); 51 | } 52 | int main() 53 | { 54 | fast_io; 55 | ll n,m,i,s,a,b; 56 | cin>>n>>m; 57 | vector adj[n+1]; 58 | visited.assign(n+1,false); 59 | for(i=0;i>a>>b; 62 | adj[a].push_back(b); 63 | //adj[b].push_back(a); 64 | } 65 | topological_sorting(adj,n); 66 | for(auto i:ans) 67 | { 68 | cout< 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | using namespace std; 16 | #define ll long long 17 | #define MOD 1000000007 18 | #define MAX 1000000000000000000 19 | #define ln "\n" 20 | #define pb push_back 21 | #define pll pair 22 | #define mp make_pair 23 | #define F first 24 | #define S second 25 | #define Test ll t;cin>>t; while(t--) 26 | #define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL); 27 | vector visited; 28 | stack st; 29 | void dfs1(vector adj[],ll v) 30 | { 31 | visited[v]=true; 32 | for(int u:adj[v]) 33 | { 34 | if(!visited[u]) 35 | dfs1(adj,u); 36 | } 37 | st.push(v); 38 | } 39 | void dfs2(vector adj[],ll v) 40 | { 41 | visited[v]=true; 42 | for(int u:adj[v]) 43 | { 44 | if(!visited[u]) 45 | dfs2(adj,u); 46 | } 47 | } 48 | int main() 49 | { 50 | fast_io; 51 | ll n,m,i,x,c,a,b; 52 | cin>>n>>m; 53 | vector adj1[n+1]; 54 | vector adj2[n+1]; 55 | for(i=0;i>a>>b; 58 | adj1[a].pb(b); 59 | adj2[b].pb(a); 60 | } 61 | visited.assign(n+1,false); 62 | for(i=1;i<=n;i++) 63 | { 64 | if(!visited[i]) 65 | { 66 | dfs1(adj1,i); 67 | } 68 | } 69 | visited.assign(n+1,false); 70 | c=0; 71 | while(!st.empty()) 72 | { 73 | x=st.top(); 74 | if(!visited[x]) 75 | { 76 | dfs2(adj2,x); 77 | c++; 78 | } 79 | st.pop(); 80 | } 81 | cout< 2 | using namespace std; 3 | typedef long long int ll; 4 | #define INF 100000000 5 | int main() 6 | { 7 | ios_base::sync_with_stdio(false); 8 | cin.tie(NULL); 9 | cout.tie(NULL); 10 | ll n,m,i,x,a,b,u,v; 11 | cin>>n>>m; 12 | vector adj[n+1]; 13 | for(i=0;i>a>>b; 16 | adj[a].push_back(b); 17 | adj[b].push_back(a); 18 | } 19 | ll visited[n+1]; 20 | ll level[n+1]; 21 | for(i=0;i<=n;i++) 22 | { 23 | visited[i]=0; 24 | level[i]=-1; 25 | } 26 | cin>>u>>v; 27 | queue q; 28 | q.push(u); 29 | level[u]=0; 30 | visited[u]=1; 31 | while(!q.empty()) 32 | { 33 | x=q.front(); 34 | for(i=0;i 2 | using namespace std; 3 | typedef long long int ll; 4 | int main() 5 | { 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(NULL); 8 | cout.tie(NULL); 9 | ll t,n,i,j,z,x,flag,m,a,b,k=1; 10 | cin>>n>>m; 11 | vector adj[n+1]; 12 | for(i=0;i>a>>b; 15 | adj[a].push_back(b); 16 | adj[b].push_back(a); 17 | } 18 | vector color(n+1,-1); 19 | queue q; 20 | flag=1; 21 | for(i=1;i<=n;i++) 22 | { 23 | if(color[i]==-1) 24 | { 25 | color[i]=0; 26 | q.push(i); 27 | while(!q.empty()) 28 | { 29 | x=q.front(); 30 | for(j=0;j 2 | using namespace std; 3 | #define INF LLONG_MAX 4 | typedef long long int ll; 5 | vector Dijkstra(ll s,vector>> adj) 6 | { 7 | ll n=adj.size(); 8 | vector dist(n+5,INF); 9 | vector prev(n+5,0); 10 | priority_queue, vector>, greater>> pq; 11 | pq.push({0,s}); 12 | dist[s]=0; 13 | while(!pq.empty()) 14 | { 15 | ll v=pq.top().second; 16 | ll dist_v=pq.top().first; 17 | pq.pop(); 18 | if(dist_v!=dist[v]) 19 | continue; 20 | for(ll i=0;i>n>>m;; 41 | vector>> adj(n+5); 42 | for(i=0;i>a>>b>>w; 45 | adj[a].push_back({b,w}); 46 | } 47 | cin>>u>>v; 48 | vector dist(n+1); 49 | dist=Dijkstra(u,adj); 50 | if(dist[v]==INF) 51 | cout<<-1< 2 | using namespace std; 3 | typedef long long int ll; 4 | #define INF 100000000000 5 | struct edge 6 | { 7 | ll u,v,cost; 8 | }; 9 | ll bellman_ford(struct edge e[],ll n,ll m,ll s,ll visited[]) 10 | { 11 | vector dist(n+1,INF); 12 | dist[s]=0; 13 | ll x; 14 | for(ll i=0;idist[e[j].u]+e[j].cost) 22 | { 23 | dist[e[j].v]=dist[e[j].u]+e[j].cost; 24 | x=e[j].v; 25 | } 26 | } 27 | } 28 | } 29 | for(ll i=1;i<=n;i++) 30 | { 31 | if(dist[i]!=INF) 32 | visited[i]=1; 33 | } 34 | if(x==-1) 35 | return 0; 36 | else 37 | return 1; 38 | } 39 | int main() 40 | { 41 | ios_base::sync_with_stdio(false); 42 | cin.tie(NULL); 43 | cout.tie(NULL); 44 | 45 | ll n,m,i,flag=0,x; 46 | cin>>n>>m; 47 | ll visited[n+1]={0}; 48 | struct edge e[m+1]; 49 | for(i=0;i>e[i].u>>e[i].v>>e[i].cost; 52 | } 53 | for(i=1;i<=n;i++) 54 | { 55 | if(visited[i]==0) 56 | { 57 | x=bellman_ford(e,n,m,i,visited); 58 | if(x==1) 59 | { 60 | flag=1; 61 | break; 62 | } 63 | } 64 | } 65 | if(flag==1) 66 | cout<<1< 2 | using namespace std; 3 | typedef long long int ll; 4 | typedef long double ld; 5 | void make_set(ll n,ll parent[]) 6 | { 7 | for(ll i=0;i<=n;i++) 8 | { 9 | parent[i]=i; 10 | } 11 | } 12 | ll find(ll x,ll parent[]) 13 | { 14 | if(x==parent[x])return x; 15 | return find(parent[x],parent); 16 | } 17 | void unioni(ll x,ll y,ll parent[]) 18 | { 19 | ll first=find(x,parent); 20 | ll second=find(y,parent); 21 | parent[first]=parent[second]; 22 | } 23 | long double kruskal(vector>> adj,ll parent[]) 24 | { 25 | ll x,y,i; 26 | long double cost=0; 27 | long double minimum_cost=0; 28 | for(i=0;i>n; 49 | ll parent[n+1]; 50 | make_set(n,parent); 51 | vector>> adj; 52 | for(i=0;i>a[i]>>b[i]; 55 | } 56 | for(i=0;i 2 | using namespace std; 3 | typedef long long int ll; 4 | #define MAX 1000000 5 | long long int id[MAX],n,edges; 6 | pair > p[MAX]; 7 | void initialize() 8 | { 9 | for(ll i=0;i kruskal(pair > p[]) 30 | { 31 | ll x, y; 32 | vector vect; 33 | long double cost; 34 | for(ll i=0;i>n; 54 | ll a[n],b[n]; 55 | edges=(n*(n-1))/2; 56 | for(i=1;i<=n;i++) 57 | { 58 | cin>>a[i]>>b[i]; 59 | } 60 | cin>>kk; 61 | k=0; 62 | for(i=1;i<=n;i++) 63 | { 64 | for(j=i+1;j<=n;j++) 65 | { 66 | dist=sqrt(((a[i]-a[j])*(a[i]-a[j]))+((b[i]-b[j])*(b[i]-b[j]))); 67 | p[k]=make_pair(dist,make_pair(i,j)); 68 | k++; 69 | } 70 | } 71 | sort(p,p+edges); 72 | vector vect=kruskal(p); 73 | cout< 2 | using namespace std; 3 | typedef long long int ll; 4 | int main() 5 | { 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(NULL); 8 | cout.tie(NULL); 9 | ll n,top,i; 10 | char a[1000000]; 11 | cin>>a; 12 | n=strlen(a); 13 | stack s; 14 | stack q; 15 | for(i=0;i 2 | using namespace std; 3 | typedef long long int ll; 4 | int main() 5 | { 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(NULL); 8 | cout.tie(NULL); 9 | ll n,i,j,c,maxheight,height; 10 | cin>>n; 11 | ll p[n]; 12 | for(i=0;i>p[i]; 15 | } 16 | ll h[n]; 17 | for(i=0;i 2 | using namespace std; 3 | typedef long long int ll; 4 | ll n,size_of_buffer; 5 | struct entry 6 | { 7 | ll arrival_time; 8 | ll process_time; 9 | }; 10 | queue end_time; 11 | ll calculating(ll arrival,ll process) 12 | { 13 | while(!end_time.empty()) 14 | { 15 | if(end_time.front()<=arrival) 16 | end_time.pop(); 17 | else 18 | break; 19 | } 20 | if(end_time.empty()) 21 | { 22 | end_time.push(arrival+process); 23 | return(arrival); 24 | } 25 | if(end_time.size()==size_of_buffer) 26 | { 27 | return(-1); 28 | } 29 | ll last=end_time.back(); 30 | end_time.push(last+process); 31 | return(last); 32 | } 33 | int main() 34 | { 35 | ios_base::sync_with_stdio(false); 36 | cin.tie(NULL); 37 | cout.tie(NULL); 38 | ll i; 39 | cin>>size_of_buffer; 40 | cin>>n; 41 | ll ans[n]; 42 | struct entry e[n]; 43 | for(i=0;i>e[i].arrival_time>>e[i].process_time; 46 | } 47 | for(i=0;i 2 | #include 3 | using namespace std; 4 | typedef long long int ll; 5 | int main() 6 | { 7 | ios_base::sync_with_stdio(false); 8 | cin.tie(NULL); 9 | cout.tie(NULL); 10 | ll t,n; 11 | stack s1; 12 | stack s2; 13 | cin>>t; 14 | while(t--) 15 | { 16 | char s[10]; 17 | cin>>s; 18 | if(s[0]=='p' && s[1]=='u' && s[2]=='s' && s[3]=='h') 19 | { 20 | cin>>n; 21 | s1.push(n); 22 | if(s2.empty()) 23 | { 24 | s2.push(n); 25 | } 26 | else 27 | if(n>=s2.top()) 28 | { 29 | s2.push(n); 30 | } 31 | } 32 | else 33 | if(s[0]=='p' && s[1]=='o' && s[2]=='p') 34 | { 35 | if(s1.top()==s2.top()) 36 | { 37 | s1.pop(); 38 | s2.pop(); 39 | } 40 | else 41 | { 42 | s1.pop(); 43 | } 44 | } 45 | else 46 | if(s[0]=='m' && s[1]=='a' && s[2]=='x') 47 | { 48 | cout< 2 | using namespace std; 3 | typedef long long int ll; 4 | int main() 5 | { 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(NULL); 8 | cout.tie(NULL); 9 | ll number_of_elements,i,k; 10 | cin>>number_of_elements; 11 | ll a[number_of_elements]; 12 | for(i=0;i>a[i]; 15 | } 16 | cin>>k; 17 | vector answer; 18 | deque q; 19 | for(i=0;i=k) 22 | { 23 | answer.push_back(a[q.front()]); 24 | while((!q.empty()) && (q.front()<=i-k)) 25 | q.pop_front(); 26 | } 27 | while((!q.empty()) && (a[q.back()]<=a[i])) 28 | q.pop_back(); 29 | q.push_back(i); 30 | } 31 | answer.push_back(a[q.front()]); 32 | for(i=0;i 2 | using namespace std; 3 | typedef long long int ll; 4 | vector b; 5 | ll c=0; 6 | void siftdown(ll a[],ll n,ll i) 7 | { 8 | ll minindex=i; 9 | ll left=2*i+1; 10 | ll right=2*i+2; 11 | if(left=0;i--) 29 | { 30 | siftdown(a,n,i); 31 | } 32 | } 33 | int main() 34 | { 35 | ios_base::sync_with_stdio(false); 36 | cin.tie(NULL); 37 | cout.tie(NULL); 38 | ll n,i; 39 | cin>>n; 40 | ll a[n]; 41 | for(i=0;i>a[i]; 43 | build_heap(a,n); 44 | cout< 2 | using namespace std; 3 | typedef long long int ll; 4 | ll max_table,n,m,parent[100000],ranki[100000],b[100000],a[100000]; 5 | void makeset() 6 | { 7 | for(ll i=0;i>n>>m; 52 | max_table=LLONG_MIN; 53 | for(i=0;i>a[i]; 56 | b[i]=a[i]; 57 | max_table=max(max_table,a[i]); 58 | } 59 | makeset(); 60 | for(i=0;i>to_merge_table_a>>to_merge_table_b; 63 | --to_merge_table_a; 64 | --to_merge_table_b; 65 | unioni(to_merge_table_a,to_merge_table_b); 66 | cout< 2 | using namespace std; 3 | typedef long long int ll; 4 | int main() 5 | { 6 | ios_base::sync_with_stdio(false); 7 | cin.tie(NULL); 8 | cout.tie(NULL); 9 | ll n,i,number; 10 | cin>>n; 11 | string s1,name; 12 | vector a; 13 | for(i=0;i<10000000;i++) 14 | { 15 | a.push_back("not found"); 16 | } 17 | for(i=0;i>s1; 20 | if(s1[0]=='a' && s1[1]=='d' && s1[2]=='d') 21 | { 22 | cin>>number; 23 | cin>>name; 24 | a[number]=name; 25 | } 26 | else 27 | if(s1[0]=='d' && s1[1]=='e' && s1[2]=='l') 28 | { 29 | cin>>number; 30 | a[number]="not found"; 31 | } 32 | else 33 | if(s1[0]=='f' && s1[1]=='i' && s1[2]=='n' && s1[3]=='d') 34 | { 35 | cin>>number; 36 | cout< 2 | using namespace std; 3 | typedef long long int ll; 4 | #define x 263 5 | #define modp 1000000007 6 | struct roop 7 | { 8 | vector v; 9 | }; 10 | ll power(ll xx, unsigned long long int y, ll p) 11 | { 12 | ll res = 1; 13 | xx = xx % p; 14 | while (y > 0) 15 | { 16 | if (y & 1) 17 | res = (res*xx) % p; 18 | y = y>>1; 19 | xx = (xx*xx) % p; 20 | } 21 | return res; 22 | } 23 | int main() 24 | { 25 | ios_base::sync_with_stdio(false); 26 | cin.tie(NULL); 27 | cout.tie(NULL); 28 | ll m,n,i,j,k,number,flag; 29 | string s1,str; 30 | cin>>m; 31 | cin>>n; 32 | struct roop r[m+1]; 33 | for(i=0;i>s1; 36 | if(s1[0]=='a' && s1[1]=='d' && s1[2]=='d') 37 | { 38 | cin>>str; 39 | k=0; 40 | for(j=0;j>str; 63 | k=0; 64 | for(j=0;j>str; 84 | k=0; 85 | for(j=0;j>number; 109 | for(j=(r[number].v.size())-1;j>=0;j--) 110 | { 111 | cout< 2 | using namespace std; 3 | typedef long long int ll; 4 | ll polyhash(string S,ll p,ll x) 5 | { 6 | ll hash=0; 7 | for(ll i=S.length()-1;i>=0;i--) 8 | { 9 | hash=(((hash*x))+(S[i]))%p; 10 | } 11 | return hash; 12 | } 13 | vector precomputehashes(string T,ll pl,ll p,ll x) 14 | { 15 | vector H; 16 | for(ll i=0;i<(T.length()-pl+1);i++) 17 | { 18 | H.push_back(0); 19 | } 20 | string S; 21 | S=T.substr(T.length()-pl,pl); 22 | H[T.length()-pl]=polyhash(S,p,x); 23 | ll y=1; 24 | for(ll i=1;i<=pl;i++) 25 | { 26 | y=((y)*(x))%p; 27 | } 28 | for(ll i=T.length()-pl-1;i>=0;i--) 29 | { 30 | ll prehash=(((((x)*(H[i+1])))+((T[i])))-(((y)*(T[i+pl])))); 31 | while(prehash<0) 32 | { 33 | prehash+=p; 34 | } 35 | H[i]=prehash%p; 36 | } 37 | return H; 38 | } 39 | bool areequal(string s1,string s2) 40 | { 41 | if(s1.length()!=s2.length()) 42 | { 43 | return false; 44 | } 45 | for(ll i=0;i RabinKarp(string T,string P) 53 | { 54 | ll p=1000000007; 55 | ll x=rand()%(p-1)+1; 56 | vector result; 57 | ll phash=polyhash(P,p,x); 58 | vector H; 59 | H=precomputehashes(T,P.length(),p,x); 60 | for(ll i=0;i<=(T.length()-P.length());i++) 61 | { 62 | if(phash!=H[i]) 63 | continue; 64 | if(areequal(T.substr(i,P.length()),P)) 65 | { 66 | result.push_back(i); 67 | } 68 | } 69 | return result; 70 | } 71 | int main() 72 | { 73 | ios_base::sync_with_stdio(false); 74 | cin.tie(NULL); 75 | cout.tie(NULL); 76 | string P,T; 77 | cin>>P>>T; 78 | vector result; 79 | result=RabinKarp(T,P); 80 | for(ll i=0;i 2 | 3 | #include 4 | 5 | #include 6 | 7 | #include 8 | 9 | #include 10 | 11 | #include 12 | 13 | #include 14 | 15 | #include 16 | 17 | #include 18 | 19 | #include 20 | 21 | #include 22 | 23 | #include 24 | 25 | #include 26 | 27 | #include 28 | 29 | using namespace std; 30 | 31 | #define ll long long 32 | 33 | #define MOD 1000000007 34 | 35 | #define MAX 1000000000000000000 36 | 37 | #define ln "\n" 38 | 39 | #define pb push_back 40 | 41 | #define pll pair 42 | 43 | #define f first 44 | #define s second 45 | 46 | #define TEST ll t;cin>>t; while(t--) 47 | 48 | #define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL); 49 | 50 | struct roop 51 | 52 | { 53 | 54 | ll key; 55 | 56 | ll left; 57 | 58 | ll right; 59 | 60 | }; 61 | 62 | ll n; 63 | 64 | struct roop r[100001]; 65 | 66 | void in_order(ll vertex) 67 | 68 | { 69 | 70 | if(vertex!=-1) 71 | 72 | { 73 | 74 | in_order(r[vertex].left); 75 | 76 | cout<>n; 126 | 127 | for(i=0;i>r[i].key>>r[i].left>>r[i].right; 132 | 133 | } 134 | 135 | in_order(0); 136 | 137 | cout< 2 | 3 | #include 4 | 5 | #include 6 | 7 | #include 8 | 9 | #include 10 | 11 | #include 12 | 13 | #include 14 | 15 | #include 16 | 17 | #include 18 | 19 | #include 20 | 21 | #include 22 | #include 23 | 24 | #include 25 | 26 | #include 27 | 28 | using namespace std; 29 | 30 | #define ll long long 31 | 32 | #define MOD 1000000007 33 | 34 | #define MAX 1000000000000000000 35 | 36 | #define ln "\n" 37 | 38 | #define pb push_back 39 | 40 | #define pll pair 41 | 42 | #define f first 43 | #define s second 44 | 45 | #define TEST ll t;cin>>t; while(t--) 46 | 47 | #define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL); 48 | 49 | struct roop 50 | 51 | { 52 | 53 | ll key; 54 | 55 | ll left; 56 | 57 | ll right; 58 | 59 | }; 60 | 61 | ll n; 62 | 63 | struct roop r[100001]; 64 | 65 | ll flag=1; 66 | 67 | bool is_binary_search_tree(ll node,ll maxi,ll mini) 68 | 69 | { 70 | 71 | if((node<0) || (node>=n)) 72 | 73 | return true; 74 | 75 | if((r[node].keymaxi)) 76 | 77 | return false; 78 | 79 | return is_binary_search_tree(r[node].left,r[node].key-1,mini) && is_binary_search_tree(r[node].right,maxi,r[node].key+1); 80 | 81 | } 82 | 83 | int main() 84 | 85 | { 86 | 87 | fast_io; 88 | 89 | ll i; 90 | 91 | cin>>n; 92 | 93 | for(i=0;i>r[i].key>>r[i].left>>r[i].right; 96 | 97 | if(is_binary_search_tree(0,MAX,-MAX)) 98 | 99 | cout<<"CORRECT"< 2 | 3 | #include 4 | 5 | #include 6 | 7 | #include 8 | 9 | #include 10 | 11 | #include 12 | 13 | #include 14 | 15 | #include 16 | 17 | #include 18 | 19 | #include 20 | 21 | #include 22 | 23 | #include 24 | 25 | #include 26 | 27 | #include 28 | 29 | using namespace std; 30 | 31 | #define ll long long 32 | 33 | #define MOD 1000000007 34 | 35 | #define MAX 1000000000000000000 36 | 37 | #define ln "\n" 38 | 39 | #define pb push_back 40 | 41 | #define pll pair 42 | 43 | #define f first 44 | 45 | #define s second 46 | 47 | #define TEST ll t;cin>>t; while(t--) 48 | 49 | #define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL); 50 | 51 | struct roop 52 | 53 | { 54 | 55 | ll key; 56 | 57 | ll left; 58 | 59 | ll right; 60 | 61 | }; 62 | 63 | ll n; 64 | 65 | struct roop r[100001]; 66 | 67 | ll flag=1; 68 | 69 | bool is_binary_search_tree(ll node,ll maxi,ll mini) 70 | 71 | { 72 | 73 | if((node<0) || (node>=n)) 74 | 75 | return true; 76 | 77 | if((r[node].keymaxi)) 78 | 79 | return false; 80 | 81 | return is_binary_search_tree(r[node].left,r[node].key-1,mini) && is_binary_search_tree(r[node].right,maxi,r[node].key); 82 | 83 | } 84 | 85 | int main() 86 | 87 | { 88 | fast_io; 89 | 90 | ll i; 91 | 92 | cin>>n; 93 | 94 | for(i=0;i>r[i].key>>r[i].left>>r[i].right; 97 | 98 | if(is_binary_search_tree(0,MAX,-MAX)) 99 | 100 | cout<<"CORRECT"<
7 | Please solve and implement algorithms yourself and if you get stuck, you can refer my solutions. 8 |
9 | 10 | ## Course 1: [Algorithmic Toolbox](https://www.coursera.org/learn/algorithmic-toolbox?specialization=data-structures-algorithms) 11 | **[Programming Assignment 1:](/Algorithmic%20Tool%20Box/week1_programming_challenges/week1_programming_challenges.pdf)** 12 |
13 | - [sum_of_two_digits](/Algorithmic%20Tool%20Box/week1_programming_challenges/1_sum_of_two_digits) 14 | - [maximum_pairwise_product](/Algorithmic%20Tool%20Box/week1_programming_challenges/2_maximum_pairwise_product)
15 | 16 | **[Programming Assignment 2:](/Algorithmic%20Tool%20Box/week2_algorithmic_warmup/week2_algorithmic_warmup.pdf)** 17 |
18 | - [fibonacci_number](/Algorithmic%20Tool%20Box/week2_algorithmic_warmup/1_fibonacci_number) 19 | - [last_digit_of_fibonacci_number](/Algorithmic%20Tool%20Box/week2_algorithmic_warmup/2_last_digit_of_fibonacci_number) 20 | - [greatest_common_divisor](/Algorithmic%20Tool%20Box/week2_algorithmic_warmup/3_greatest_common_divisor) 21 | - [least_common_multiple](/Algorithmic%20Tool%20Box/week2_algorithmic_warmup/4_least_common_multiple) 22 | - [fibonacci_number_again](/Algorithmic%20Tool%20Box/week2_algorithmic_warmup/5_fibonacci_number_again) 23 | - [last_digit_of_the_sum_of_fibonacci_numbers](/Algorithmic%20Tool%20Box/week2_algorithmic_warmup/6_last_digit_of_the_sum_of_fibonacci_numbers) 24 | - [last_digit_of_the_sum_of_fibonacci_numbers_again](/Algorithmic%20Tool%20Box/week2_algorithmic_warmup/7_last_digit_of_the_sum_of_fibonacci_numbers_again) 25 | - [last_digit_of_the_sum_of_squares_of_fibonacci_numbers](/Algorithmic%20Tool%20Box/week2_algorithmic_warmup/8_last_digit_of_the_sum_of_squares_of_fibonacci_numbers)
26 | 27 | **[Programming Assignment 3:](/Algorithmic%20Tool%20Box/week3_greedy_algorithms/week3_greedy_algorithms.pdf)** 28 |
29 | - [money_change](/Algorithmic%20Tool%20Box/week3_greedy_algorithms/1_money_change) 30 | - [maximum_value_of_the_loot](/Algorithmic%20Tool%20Box/week3_greedy_algorithms/2_maximum_value_of_the_loot) 31 | - [car_fueling](/Algorithmic%20Tool%20Box/week3_greedy_algorithms/3_car_fueling) 32 | - [maximum_advertisement_revenue](/Algorithmic%20Tool%20Box/week3_greedy_algorithms/4_maximum_advertisement_revenue) 33 | - [collecting_signatures](/Algorithmic%20Tool%20Box/week3_greedy_algorithms/5_collecting_signatures) 34 | - [maximum_number_of_prizes](/Algorithmic%20Tool%20Box/week3_greedy_algorithms/6_maximum_number_of_prizes) 35 | - [maximum_salary](/Algorithmic%20Tool%20Box/week3_greedy_algorithms/7_maximum_salary)
36 | 37 | **[Programming Assignment 4:](/Algorithmic%20Tool%20Box/week4_divide_and_conquer/week4_divide_and_conquer.pdf)** 38 |
39 | - [binary_search](/Algorithmic%20Tool%20Box/week4_divide_and_conquer/1_binary_search) 40 | - [majority_element](/Algorithmic%20Tool%20Box/week4_divide_and_conquer/2_majority_element) 41 | - [improving_quicksort](/Algorithmic%20Tool%20Box/week4_divide_and_conquer/3_improving_quicksort) 42 | - [number_of_inversions](/Algorithmic%20Tool%20Box/week4_divide_and_conquer/4_number_of_inversions) 43 | - [organizing_a_lottery](/Algorithmic%20Tool%20Box/week4_divide_and_conquer/5_organizing_a_lottery) 44 | - [closest_points](/Algorithmic%20Tool%20Box/week4_divide_and_conquer/6_closest_points)
45 | 46 | **[Programming Assignment 5:](/Algorithmic%20Tool%20Box/week5_dynamic_programming1/week5_dynamic_programming1.pdf)** 47 |
48 | - [money_change_again](/Algorithmic%20Tool%20Box/week5_dynamic_programming1/1_money_change_again) 49 | - [primitive_calculator](r/Algorithmic%20Tool%20Box/week5_dynamic_programming1/2_primitive_calculator) 50 | - [edit_distance](/Algorithmic%20Tool%20Box/week5_dynamic_programming1/3_edit_distance) 51 | - [longest_common_subsequence_of_two_sequences](/Algorithmic%20Tool%20Box/week5_dynamic_programming1/4_longest_common_subsequence_of_two_sequences) 52 | - [longest_common_subsequence_of_three_sequences](/Algorithmic%20Tool%20Box/week5_dynamic_programming1/5_longest_common_subsequence_of_three_sequences)
53 | 54 | **[Programming Assignment 6:](/Algorithmic%20Tool%20Box/week6_dynamic_programming2/week6_dynamic_programming2.pdf)** 55 |
56 | - [maximum_amount_of_gold](/Algorithmic%20Tool%20Box/week6_dynamic_programming2/1_maximum_amount_of_gold) 57 | - [partitioning_souvenirs](/Algorithmic%20Tool%20Box/week6_dynamic_programming2/2_partitioning_souvenirs) 58 | - [maximum_value_of_an_arithmetic_expression](/Algorithmic%20Tool%20Box/week6_dynamic_programming2/3_maximum_value_of_an_arithmetic_expression)
59 | 60 | 61 | ## Course 2: [Data Structures](https://www.coursera.org/learn/data-structures?specialization=data-structures-algorithms) 62 | **[Programming Assignment 1:](/Data%20Structures/week1_basic_data_structures/week1_basic_data_structures.pdf)** 63 |
64 | - [brackets_in_code](/Data%20Structures/week1_basic_data_structures/1_brackets_in_code) 65 | - [tree_height](/Data%20Structures/week1_basic_data_structures/2_tree_height) 66 | - [network_simulation](/Data%20Structures/week1_basic_data_structures/3_network_simulation) 67 | - [stack_with_max](/Data%20Structures/week1_basic_data_structures/4_stack_with_max) 68 | - [max_sliding_window](/Data%20Structures/week1_basic_data_structures/5_max_sliding_window)
69 | 70 | **[Programming Assignment 2:](/Data%20Structures/week2_priority_queues_and_disjoint_sets/week2_priority_queues_and_disjoint_sets.pdf)** 71 |
72 | - [make_heap](/Data%20Structures/week2_priority_queues_and_disjoint_sets/1_make_heap) 73 | - [merging_tables](/Data%20Structures/week2_priority_queues_and_disjoint_sets/3_merging_tables)
74 | 75 | **[Programming Assignment 3:](/Data%20Structures/week3_hash_tables/week3_hash_tables.pdf)** 76 |
77 | - [phone_book](/Data%20Structures/week3_hash_tables/1_phone_book) 78 | - [hash_chains](/Data%20Structures/week3_hash_tables/2_hash_chains) 79 | - [hash_substring](/Data%20Structures/week3_hash_tables/3_hash_substring)
80 | 81 | **[Programming Assignment 4:](/Data%20Structures/week4_binary_search_trees/week4_binary_search_trees.pdf)** 82 |
83 | - [tree_traversals](/Data%20Structures/week4_binary_search_trees/1_tree_traversals) 84 | - [is_bst](/Data%20Structures/week4_binary_search_trees/2_is_bst) 85 | - [is_bst_advanced](/Data%20Structures/week4_binary_search_trees/3_is_bst_advanced)
86 | 87 | 88 | ## Course 3: [Algorithms on Graphs](https://www.coursera.org/learn/algorithms-on-graphs?specialization=data-structures-algorithms) 89 | **[Programming Assignment 1:](/Algorithms%20on%20Graphs/week1_decomposition1/decomposition1.pdf)** 90 |
91 | - [reachability](/Algorithms%20on%20Graphs/week1_decomposition1/1_reachability) 92 | - [connected_components](/Algorithms%20on%20Graphs/week1_decomposition1/2_connected_components)
93 | 94 | **[Programming Assignment 2:](/Algorithms%20on%20Graphs/week2_decomposition2/decomposition2.pdf)** 95 |
96 | - [acyclicity](/Algorithms%20on%20Graphs/week2_decomposition2/1_acyclicity) 97 | - [toposort](/Algorithms%20on%20Graphs/week2_decomposition2/2_toposort) 98 | - [strongly_connected](/Algorithms%20on%20Graphs/week2_decomposition2/3_strongly_connected)
99 | 100 | **[Programming Assignment 3:](/Algorithms%20on%20Graphs/week3_paths1/paths1.pdf)** 101 |
102 | - [bfs](/Algorithms%20on%20Graphs/week3_paths1/1_bfs) 103 | - [bipartite](/Algorithms%20on%20Graphs/week3_paths1/2_bipartite)
104 | 105 | **[Programming Assignment 4:](/Algorithms%20on%20Graphs/week4_paths2/paths2.pdf)** 106 |
107 | - [dijkstra](/Algorithms%20on%20Graphs/week4_paths2/1_dijkstra) 108 | - [negative_cycle](/Algorithms%20on%20Graphs/week4_paths2/2_negative_cycle)
109 | 110 | **[Programming Assignment 5:](/Algorithms%20on%20Graphs/week5_mst/mst.pdf)** 111 |
112 | - [connecting_points](/Algorithms%20on%20Graphs/week5_mst/1_connecting_points) 113 | - [clustering](/Algorithms%20on%20Graphs/week5_mst/2_clustering)
114 | 115 | 116 | ## Course 4: [Algorithms on Strings](https://www.coursera.org/learn/algorithms-on-strings?specialization=data-structures-algorithms) 117 | **[Programming Assignment 1:](/Algorithm%20on%20Strings/Programming%20Assignment%201/_f8a4443f144319c6da63eeb31af4199b_Programming-Assignment-1.pdf)** 118 |
119 | - [trie](/Algorithm%20on%20Strings/Programming%20Assignment%201/trie) 120 | - [trie_matching](/Algorithm%20on%20Strings/Programming%20Assignment%201/trie_matching) 121 | - [trie_matching_extended](/Algorithm%20on%20Strings/Programming%20Assignment%201/trie_matching_extended) 122 | - [suffix_tree](/Algorithm%20on%20Strings/Programming%20Assignment%201/suffix_tree)
123 | 124 | **[Programming Assignment 2:](/Algorithm%20on%20Strings/Programming%20Assignment%202/Programming-Assignment-2.pdf)** 125 |
126 | - [bwt](/Algorithm%20on%20Strings/Programming%20Assignment%202/bwt) 127 | - [bwtinverse](/Algorithm%20on%20Strings/Programming%20Assignment%202/bwtinverse) 128 | - [bwmatching](/Algorithm%20on%20Strings/Programming%20Assignment%202/bwmatching) 129 | - [suffix_array](/Algorithm%20on%20Strings/Programming%20Assignment%202/suffix_array)
130 | 131 | **[Programming Assignment 3:](/Algorithm%20on%20Strings/Programming%20Assignment%203/Programming-Assignment-3.pdf)** 132 |
133 | - [kmp](/Algorithm%20on%20Strings/Programming%20Assignment%203/kmp) 134 | - [suffix_array_long](/Algorithm%20on%20Strings/Programming%20Assignment%203/suffix_array_long) 135 | - [suffix_array_matching](/Algorithm%20on%20Strings/Programming%20Assignment%203/suffix_array_matching) 136 | - [suffix_tree_from_array](/Algorithm%20on%20Strings/Programming%20Assignment%203/suffix_tree_from_array) 137 | 138 | 139 | 140 | --------------------------------------------------------------------------------