diff --git a/week-2/C++/Ammarah-Haynes.cpp b/week-2/C++/Ammarah-Haynes.cpp new file mode 100644 index 0000000..e4c38e1 --- /dev/null +++ b/week-2/C++/Ammarah-Haynes.cpp @@ -0,0 +1,25 @@ +#include +#include +using namespace std; + +//palindrome +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{ + + } + } + 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++/Ammarah-Haynes.cpp b/week-4/C++/Ammarah-Haynes.cpp new file mode 100644 index 0000000..ccdc45b --- /dev/null +++ b/week-4/C++/Ammarah-Haynes.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; +} 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 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 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 diff --git a/week-8/C++/Ammarah-Haynes.cpp b/week-8/C++/Ammarah-Haynes.cpp new file mode 100644 index 0000000..432a5af --- /dev/null +++ b/week-8/C++/Ammarah-Haynes.cpp @@ -0,0 +1,91 @@ +//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 count = 1; + 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)) + count++; + else if(count == k){ + cout << list.at(i); + break; + } + else + count = 1; + } + return 0; +} diff --git a/week-8/C++/main.cpp b/week-8/C++/main.cpp deleted file mode 100644 index e69de29..0000000