Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions week-2/C++/Ammarah-Haynes.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include <iostream>
#include <string>
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
35 changes: 35 additions & 0 deletions week-3/C++/Ammarah-Haynes.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//hacker rank
#include <iostream>
#include <string>
#include <string.h>
#include <array>
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;
}
Empty file removed week-3/C++/main.cpp
Empty file.
33 changes: 33 additions & 0 deletions week-4/C++/Ammarah-Haynes.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//Taken from geeksforgeeks
#include <iostream>

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;
}
48 changes: 48 additions & 0 deletions week-5/C++/Ammarah-Haynes.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include <iostream>
#include <string>
#include <vector>
#include <algortithm>
using namespace std;

int main (){
int n, value, finalprice = 0;
vector<int> prices;
vector<int> fullPrice;
vector<int> 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;

}
Empty file removed week-5/C++/main.cpp
Empty file.
69 changes: 69 additions & 0 deletions week-6/C++/Ammarah-Haynes.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
//constructed nodes from geeksforgeeks

//leaf to root path problem
#include <iostream>
#include<string>
#include<vector>

using namespace std;

struct node{
int data;
struct node *left;
struct node *right;
};

void printLeaftoRoot(vector<int>list){
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<int> 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<int> 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;
}
Empty file removed week-6/C++/main.cpp
Empty file.
43 changes: 43 additions & 0 deletions week-7/C++/Ammarah-Haynes.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//hacker rank problem. Solved 11/15 test cases

#include <iostream>
#include<string>
#include<vector>

using namespace std;

string partitioningArray(int k, vector<int> 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<int> 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;
}
Empty file removed week-7/C++/main.cpp
Empty file.
91 changes: 91 additions & 0 deletions week-8/C++/Ammarah-Haynes.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
//FIRST PROMPT
#include <iostream>
#include<string>
#include<vector>

using namespace std;

int main() {
int num, q, m, s;
cin >> num;
cin >> q;

vector<int> second;
vector<int> 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 <iostream>
#include<vector>
#include<string>
#include<algorithm>


using namespace std;

int main() {
vector<int> 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;
}
Empty file removed week-8/C++/main.cpp
Empty file.