From ca4728eefb8eb4da5dd3b439931431fa724a9c29 Mon Sep 17 00:00:00 2001 From: vikas chaurasiya Date: Sat, 6 Oct 2018 10:23:26 +0530 Subject: [PATCH 1/3] Create migratory_Birds.cpp --- Algorithms/Implementation/migratory_Birds.cpp | 82 +++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 Algorithms/Implementation/migratory_Birds.cpp diff --git a/Algorithms/Implementation/migratory_Birds.cpp b/Algorithms/Implementation/migratory_Birds.cpp new file mode 100644 index 0000000..570146c --- /dev/null +++ b/Algorithms/Implementation/migratory_Birds.cpp @@ -0,0 +1,82 @@ +#include + +using namespace std; + +vector split_string(string); + +// Complete the migratoryBirds function below. +int migratoryBirds(vector ar) { + int A[6] = {0}; + for (int i = 0; i < ar.size(); ++i) { + A[ar[i] - 1] += 1; + } + int min_index = 0, max = INT_MIN; + for (int i = 0; i < 5; ++i) { + if (A[i] > max) { + max = A[i]; + min_index = i; + } else if (A[i] == max) { + min_index = min(min_index, i); + } + } + return min_index + 1; +} + +int main() +{ + ofstream fout(getenv("OUTPUT_PATH")); + + int ar_count; + cin >> ar_count; + cin.ignore(numeric_limits::max(), '\n'); + + string ar_temp_temp; + getline(cin, ar_temp_temp); + + vector ar_temp = split_string(ar_temp_temp); + + vector ar(ar_count); + + for (int i = 0; i < ar_count; i++) { + int ar_item = stoi(ar_temp[i]); + + ar[i] = ar_item; + } + + int result = migratoryBirds(ar); + + fout << result << "\n"; + + fout.close(); + + return 0; +} + +vector split_string(string input_string) { + string::iterator new_end = unique(input_string.begin(), input_string.end(), [] (const char &x, const char &y) { + return x == y and x == ' '; + }); + + input_string.erase(new_end, input_string.end()); + + while (input_string[input_string.length() - 1] == ' ') { + input_string.pop_back(); + } + + vector splits; + char delimiter = ' '; + + size_t i = 0; + size_t pos = input_string.find(delimiter); + + while (pos != string::npos) { + splits.push_back(input_string.substr(i, pos - i)); + + i = pos + 1; + pos = input_string.find(delimiter, i); + } + + splits.push_back(input_string.substr(i, min(pos, input_string.length()) - i + 1)); + + return splits; +} From eefc4534ef42c3d99e8fea43996058f7ad7c0252 Mon Sep 17 00:00:00 2001 From: vikas chaurasiya Date: Sat, 6 Oct 2018 10:30:30 +0530 Subject: [PATCH 2/3] Create tree-top-view.cpp --- DataStructures/Trees/tree-top-view.cpp | 39 ++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 DataStructures/Trees/tree-top-view.cpp diff --git a/DataStructures/Trees/tree-top-view.cpp b/DataStructures/Trees/tree-top-view.cpp new file mode 100644 index 0000000..af3552d --- /dev/null +++ b/DataStructures/Trees/tree-top-view.cpp @@ -0,0 +1,39 @@ +/* +struct node +{ + int data; + node* left; + node* right; +}; + +*/ +void callLeft(node *n) { + if (n == NULL) { + return; + } + callLeft(n -> left); + cout << n -> data << " "; +} + +void callRight(node *t) { + if (t == NULL) { + return; + } + cout << t -> data << " "; + callRight(t -> right); +} + +void topView(node *root) { + node *temp = root; + if (root == NULL) { + return; + } + if (temp -> left) { + callLeft(temp -> left); + } + cout << root -> data << " "; + if (temp -> right) { + callRight(temp -> right); + } +} + From fd5f8fd5e56235713f7464af66d0fa652c90bf68 Mon Sep 17 00:00:00 2001 From: vikas chaurasiya Date: Tue, 25 Dec 2018 11:04:09 +0530 Subject: [PATCH 3/3] Create README.md --- README.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..a29e2fb --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# Hackerrank + +Solution of problems!