From 2c3e38d63115aa73aa5f342c5aa96e1362470254 Mon Sep 17 00:00:00 2001 From: Ammarah Haynes Date: Tue, 30 Jun 2020 12:10:04 -0400 Subject: [PATCH 1/6] commits for week 2 and 4 --- week-2/C++/main.cpp | 24 ++++++++++++++++++++++++ week-4/C++/main.cpp | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/week-2/C++/main.cpp b/week-2/C++/main.cpp index e69de29..cb737d5 100644 --- a/week-2/C++/main.cpp +++ b/week-2/C++/main.cpp @@ -0,0 +1,24 @@ +#include +#include +using namespace std; + +int main(){ + string str = "ebcdcbn"; + int len = str.size()- 1; + int j = len; + int i = 0; + + while (i != j) { //str. for(int i = 0; i < str.size(); i++){ + if(str[i] == str[str.size()-1]){ + ++i; + --j; + } + else{ + str.erase(str[i]); + str.erase(str[j]); + } + } + cout << str; + + return 0; +} diff --git a/week-4/C++/main.cpp b/week-4/C++/main.cpp index e69de29..ccdc45b 100644 --- a/week-4/C++/main.cpp +++ b/week-4/C++/main.cpp @@ -0,0 +1,33 @@ +//Taken from geeksforgeeks +#include + +using namespace std; + +class node{ +public: + int data; + node* next; +}; + +int main(){ + + node* head = NULL; + node* second = NULL; + node* third = NULL; + + //creates 3 nodes + head = new node(); + second = new node(); + third = new node(); + + head->data = 1; //assign 1 to data in first node + head->next = second; //link first node to second node + + second->data = 2; // assign 2 to data in second node + second->next = third; //link second node to third node + + third->data = 3; //assign 3 to data in third node + third-> next = NULL; //makes third node the last one + + return 0; +} From 8864dbbb95051fb144f6d6c494a681bb750da5ae Mon Sep 17 00:00:00 2001 From: Ammarah Haynes Date: Wed, 1 Jul 2020 22:43:30 -0400 Subject: [PATCH 2/6] update --- week-2/C++/{main.cpp => Ammarah-Haynes.cpp} | 5 ++- week-3/C++/Ammarah-Haynes.cpp | 35 +++++++++++++++ week-3/C++/main.cpp | 0 week-4/C++/{main.cpp => Ammarah-Haynes.cpp} | 0 week-5/C++/Ammarah-Haynes.cpp | 48 +++++++++++++++++++++ week-5/C++/main.cpp | 0 6 files changed, 86 insertions(+), 2 deletions(-) rename week-2/C++/{main.cpp => Ammarah-Haynes.cpp} (87%) create mode 100644 week-3/C++/Ammarah-Haynes.cpp delete mode 100644 week-3/C++/main.cpp rename week-4/C++/{main.cpp => Ammarah-Haynes.cpp} (100%) create mode 100644 week-5/C++/Ammarah-Haynes.cpp delete mode 100644 week-5/C++/main.cpp diff --git a/week-2/C++/main.cpp b/week-2/C++/Ammarah-Haynes.cpp similarity index 87% rename from week-2/C++/main.cpp rename to week-2/C++/Ammarah-Haynes.cpp index cb737d5..e4c38e1 100644 --- a/week-2/C++/main.cpp +++ b/week-2/C++/Ammarah-Haynes.cpp @@ -2,6 +2,7 @@ #include using namespace std; +//palindrome int main(){ string str = "ebcdcbn"; int len = str.size()- 1; @@ -14,11 +15,11 @@ int main(){ --j; } else{ - str.erase(str[i]); - str.erase(str[j]); + } } cout << str; return 0; } +//Permutations diff --git a/week-3/C++/Ammarah-Haynes.cpp b/week-3/C++/Ammarah-Haynes.cpp new file mode 100644 index 0000000..6a306c8 --- /dev/null +++ b/week-3/C++/Ammarah-Haynes.cpp @@ -0,0 +1,35 @@ +//hacker rank +#include +#include +#include +#include +using namespace std; + +int maxSpread(){ + + int array [3] = {4,9,28}; + int size = sizeof(array)/ sizeof(array[0]); + int temp = 0; + int max = -1; + + for (int i = 1; i < size; i++){ + cout << "Hello i = " << i << endl; + + for (int j = i; j >= 0; j--){ + if (array[i] > array[j]){ + temp = array[i] - array[j]; + if (temp > max) + max = temp; + } + cout << "node = " << array[i] << endl; + cout << "Previous = " << array[j] << endl; + } + } + return max; +} +int main(){ + + cout << maxSpread(); + + return 0; +} diff --git a/week-3/C++/main.cpp b/week-3/C++/main.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/week-4/C++/main.cpp b/week-4/C++/Ammarah-Haynes.cpp similarity index 100% rename from week-4/C++/main.cpp rename to week-4/C++/Ammarah-Haynes.cpp diff --git a/week-5/C++/Ammarah-Haynes.cpp b/week-5/C++/Ammarah-Haynes.cpp new file mode 100644 index 0000000..70fc0f7 --- /dev/null +++ b/week-5/C++/Ammarah-Haynes.cpp @@ -0,0 +1,48 @@ +#include +#include +#include +#include +using namespace std; + +int main (){ + int n, value, finalprice = 0; + vector prices; + vector fullPrice; + vector discountedPrices; + + + cout << "Enter the size of the vector: " << endl; + cin >> n; + + for(int i = 0; i < n; i++){ + cin >> value; + prices.push_back(value); + } + + for(int i = 0; i < n; i++){ + bool found = true; + for(int j = i+1; j < n; j++){ + if(prices[j] <= prices[i]){ + discountedPrices.push_back(prices[i] - prices[j]); + found = false; + break; + } + } + if(found == true){ + discountedPrices.push_back(prices[i]); + fullPrice.push_back(prices[i]); + } + } + for(int i = 0; i < n; i++){ + finalprice += discountedPrices[i]; + } + cout << finalprice << endl; + + sort(fullPrice.begin(), fullPrice.end()); + for(int i = 0; i < fullPrice.size(); i++){ + cout << fullPrice[i] << " "; + } + + return 0; + +} diff --git a/week-5/C++/main.cpp b/week-5/C++/main.cpp deleted file mode 100644 index e69de29..0000000 From 23bbf0e8caacb6a9e33a59c3f77873f84cca46c3 Mon Sep 17 00:00:00 2001 From: Ammarah Haynes Date: Mon, 20 Jul 2020 18:25:22 -0400 Subject: [PATCH 3/6] week 6 commit --- week-6/C++/Ammarah-Haynes.cpp | 69 +++++++++++++++++++++++++++++++++++ week-6/C++/main.cpp | 0 2 files changed, 69 insertions(+) create mode 100644 week-6/C++/Ammarah-Haynes.cpp delete mode 100644 week-6/C++/main.cpp diff --git a/week-6/C++/Ammarah-Haynes.cpp b/week-6/C++/Ammarah-Haynes.cpp new file mode 100644 index 0000000..bffca93 --- /dev/null +++ b/week-6/C++/Ammarah-Haynes.cpp @@ -0,0 +1,69 @@ +//constructed nodes from geeksforgeeks + +//leaf to root path problem +#include +#include +#include + +using namespace std; + +struct node{ + int data; + struct node *left; + struct node *right; +}; + +void printLeaftoRoot(vectorlist){ + for(int i = list.size() - 1; i >= 0; i--){ + if(i == 0) + cout << list[i]; + else + cout << list[i] << "->"; + } + cout << endl; +} + +void leaftoRoot(node* root, vector list){ + if (root == NULL) + return; + list.push_back(root->data); + if (root->left == NULL && root->right == NULL) + printLeaftoRoot(list); + leaftoRoot(root->left, list); + leaftoRoot(root->right, list); +} + +void printPath(node* root){ + vector list; + leaftoRoot(root,list); +} + + struct node* newNode(int data){ + // Allocate memory for new node + struct node* node = (struct node*)malloc(sizeof(struct node)); + + // Assign data to this node + node->data = data; + + // Initialize left and right children as NULL + node->left = NULL; + node->right = NULL; + return(node); + } + /* Binary tree + 1 + /\ + 2 3 + / \ + 4 5 + */ +int main(){ + struct node *root = newNode(1); + root->left = newNode(2); + root->right = newNode(3); + root->left->left = newNode(4); + root->left->right = newNode(5); + printPath(root); + + return 0; +} diff --git a/week-6/C++/main.cpp b/week-6/C++/main.cpp deleted file mode 100644 index e69de29..0000000 From 1ff53b9979627011cc5a8a728b4bc7d47906f6c9 Mon Sep 17 00:00:00 2001 From: Ammarah Haynes Date: Wed, 22 Jul 2020 18:13:50 -0400 Subject: [PATCH 4/6] Week 8 commit --- week-8/C++/Ammarah-Haynes.cpp | 90 +++++++++++++++++++++++++++++++++++ week-8/C++/main.cpp | 0 2 files changed, 90 insertions(+) create mode 100644 week-8/C++/Ammarah-Haynes.cpp delete mode 100644 week-8/C++/main.cpp diff --git a/week-8/C++/Ammarah-Haynes.cpp b/week-8/C++/Ammarah-Haynes.cpp new file mode 100644 index 0000000..96a7887 --- /dev/null +++ b/week-8/C++/Ammarah-Haynes.cpp @@ -0,0 +1,90 @@ +//FIRST PROMPT +#include +#include +#include + +using namespace std; + +int main() { + int num, q, m, s; + cin >> num; + cin >> q; + + vector second; + vector third; + + for(int i = 0; i < num; i++){ + cin >> m; + second.push_back(m); + } + for(int i = 0; i < q; i++){ + cin >> s; + third.push_back(s); + + } + + for(int i = 0; i < q; i++){ + int sum = 0; + for(int j = 0; j < num; j++){ + sum +=second.at(j); + if (sum >= third.at(i)){ + cout << j + 1 << endl; + break; + } + + } + } + /* +sample input: +5 4 +1 2 3 4 5 +3 8 10 14 + +sample output: +2 +4 +4 +5 +*/ + +//Second prompt(NOT FINISHED) +#include +#include +#include +#include + + +using namespace std; + +int main() { + vector list; + int num, value, k, + int seen = 0; + cin >> num; + //cout << num << endl; + + for(int i = 0; i < num; i++){ + cin >> value; + list.push_back(value); + } + // for(int i = 0; i < num; i++){ + // cout << list.at(i) << " "; + // } + // cout << endl; + + cin >> k; + // cout << k; + + // # of times integer repeats + sort(list.begin(), list.end()); + for(int i = 0; i < num; i++){ + if(list.at(i) == list.at(i+1)) + + /* +TO FINISH, I WOULD KEEP TRACK OF THE NUMBER OF OCCURRENCES FOR EACH NUMBER, THEN +COMPARE THAT NUMBER TO K. LASTLY, FIND THE SMALLEST NUMBER THAT OCCURS K # OF TIMES + */ + + } + return 0; +} diff --git a/week-8/C++/main.cpp b/week-8/C++/main.cpp deleted file mode 100644 index e69de29..0000000 From b19b06f3c1f6ce7aa6cb6db665436d6267a1149b Mon Sep 17 00:00:00 2001 From: Ammarah Haynes Date: Wed, 22 Jul 2020 18:14:08 -0400 Subject: [PATCH 5/6] Week 7 commit --- week-7/C++/Ammarah-Haynes.cpp | 43 +++++++++++++++++++++++++++++++++++ week-7/C++/main.cpp | 0 2 files changed, 43 insertions(+) create mode 100644 week-7/C++/Ammarah-Haynes.cpp delete mode 100644 week-7/C++/main.cpp diff --git a/week-7/C++/Ammarah-Haynes.cpp b/week-7/C++/Ammarah-Haynes.cpp new file mode 100644 index 0000000..eb9903f --- /dev/null +++ b/week-7/C++/Ammarah-Haynes.cpp @@ -0,0 +1,43 @@ +//hacker rank problem. Solved 11/15 test cases + +#include +#include +#include + +using namespace std; + +string partitioningArray(int k, vector numbers){ + int size = numbers.size(); + if (size % k == 0){ + for(int i = 0; i < size; i+=2){ + for(int j = i+1; j < size; j+=2){ + if(numbers[j] == numbers[i]) + return "No"; + break; + } + } + return "Yes"; + } + return "No"; +} + +int main(){ + int k, n, values = 0; + vector numbers; + + cout << "Enter k: "; + cin >> k; + + cout << "Enter size of vector: "; + cin >> n; + + cout << "Enter vector values: "; + for(int i = 0; i < n; i++){ + cin >> values; + numbers.push_back(values); + } + + cout << partitioningArray(k, numbers); + + return 0; +} diff --git a/week-7/C++/main.cpp b/week-7/C++/main.cpp deleted file mode 100644 index e69de29..0000000 From 1006de9e3a331b0b4e6a7e7dec9e1cfe5d690f7e Mon Sep 17 00:00:00 2001 From: Ammarah Haynes Date: Thu, 23 Jul 2020 16:36:53 -0400 Subject: [PATCH 6/6] Week 8 Updated --Finished second prompt. --- week-8/C++/Ammarah-Haynes.cpp | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/week-8/C++/Ammarah-Haynes.cpp b/week-8/C++/Ammarah-Haynes.cpp index 96a7887..432a5af 100644 --- a/week-8/C++/Ammarah-Haynes.cpp +++ b/week-8/C++/Ammarah-Haynes.cpp @@ -51,15 +51,15 @@ sample output: #include #include #include -#include +#include using namespace std; int main() { vector list; - int num, value, k, - int seen = 0; + int num, value, k; + int count = 1; cin >> num; //cout << num << endl; @@ -78,13 +78,14 @@ int main() { // # of times integer repeats sort(list.begin(), list.end()); for(int i = 0; i < num; i++){ - if(list.at(i) == list.at(i+1)) - - /* -TO FINISH, I WOULD KEEP TRACK OF THE NUMBER OF OCCURRENCES FOR EACH NUMBER, THEN -COMPARE THAT NUMBER TO K. LASTLY, FIND THE SMALLEST NUMBER THAT OCCURS K # OF TIMES - */ - + if(list.at(i) == list.at(i+1)) + count++; + else if(count == k){ + cout << list.at(i); + break; + } + else + count = 1; } return 0; }