From 4d3acebc36e62fa13ad2d1c9554c657e3a129879 Mon Sep 17 00:00:00 2001 From: Amar Shankar Date: Sun, 24 Oct 2021 15:57:06 +0530 Subject: [PATCH 1/4] update --- MinimumSpanningTrees | 1 + 1 file changed, 1 insertion(+) create mode 160000 MinimumSpanningTrees diff --git a/MinimumSpanningTrees b/MinimumSpanningTrees new file mode 160000 index 0000000..fab2141 --- /dev/null +++ b/MinimumSpanningTrees @@ -0,0 +1 @@ +Subproject commit fab2141102b0719270b47e6281c52545d55a93da From 51c51d0e09aca5967ba5aaed845762cb920732c6 Mon Sep 17 00:00:00 2001 From: Amar Shankar Date: Tue, 26 Oct 2021 14:57:37 +0530 Subject: [PATCH 2/4] hackerrank Solved Questions --- hackerrank/The Hurdle Race.cpp | 99 ++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 hackerrank/The Hurdle Race.cpp diff --git a/hackerrank/The Hurdle Race.cpp b/hackerrank/The Hurdle Race.cpp new file mode 100644 index 0000000..208e547 --- /dev/null +++ b/hackerrank/The Hurdle Race.cpp @@ -0,0 +1,99 @@ +#include + +using namespace std; + +string ltrim(const string &); +string rtrim(const string &); +vector split(const string &); + +/* + * Complete the 'hurdleRace' function below. + * + * The function is expected to return an INTEGER. + * The function accepts following parameters: + * 1. INTEGER k + * 2. INTEGER_ARRAY height + */ + +int hurdleRace(int k, vector height) { + int max1 = *max_element(height.begin(),height.end()); + if( max1 > k){ + return max1 - k; + }else { + return 0; + } +} + +int main() +{ + ofstream fout(getenv("OUTPUT_PATH")); + + string first_multiple_input_temp; + getline(cin, first_multiple_input_temp); + + vector first_multiple_input = split(rtrim(first_multiple_input_temp)); + + int n = stoi(first_multiple_input[0]); + + int k = stoi(first_multiple_input[1]); + + string height_temp_temp; + getline(cin, height_temp_temp); + + vector height_temp = split(rtrim(height_temp_temp)); + + vector height(n); + + for (int i = 0; i < n; i++) { + int height_item = stoi(height_temp[i]); + + height[i] = height_item; + } + + int result = hurdleRace(k, height); + + fout << result << "\n"; + + fout.close(); + + return 0; +} + +string ltrim(const string &str) { + string s(str); + + s.erase( + s.begin(), + find_if(s.begin(), s.end(), not1(ptr_fun(isspace))) + ); + + return s; +} + +string rtrim(const string &str) { + string s(str); + + s.erase( + find_if(s.rbegin(), s.rend(), not1(ptr_fun(isspace))).base(), + s.end() + ); + + return s; +} + +vector split(const string &str) { + vector tokens; + + string::size_type start = 0; + string::size_type end = 0; + + while ((end = str.find(" ", start)) != string::npos) { + tokens.push_back(str.substr(start, end - start)); + + start = end + 1; + } + + tokens.push_back(str.substr(start)); + + return tokens; +} From 145d08271010c2d0e80c380ca36836628d691675 Mon Sep 17 00:00:00 2001 From: Amar Shankar Date: Tue, 26 Oct 2021 15:27:10 +0530 Subject: [PATCH 3/4] hackerrank Solved - Designer PDF Viewer --- hackerrank/Designer PDF Viewer.cpp | 92 ++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 hackerrank/Designer PDF Viewer.cpp diff --git a/hackerrank/Designer PDF Viewer.cpp b/hackerrank/Designer PDF Viewer.cpp new file mode 100644 index 0000000..d7446fa --- /dev/null +++ b/hackerrank/Designer PDF Viewer.cpp @@ -0,0 +1,92 @@ +#include + +using namespace std; + +string ltrim(const string &); +string rtrim(const string &); +vector split(const string &); + +/* + * Complete the 'designerPdfViewer' function below. + * + * The function is expected to return an INTEGER. + * The function accepts following parameters: + * 1. INTEGER_ARRAY h + * 2. STRING word + */ + +int designerPdfViewer(vector h, string word) { + vector ans; + for( int i =0;i h_temp = split(rtrim(h_temp_temp)); + + vector h(26); + + for (int i = 0; i < 26; i++) { + int h_item = stoi(h_temp[i]); + + h[i] = h_item; + } + + string word; + getline(cin, word); + + int result = designerPdfViewer(h, word); + + fout << result << "\n"; + + fout.close(); + + return 0; +} + +string ltrim(const string &str) { + string s(str); + + s.erase( + s.begin(), + find_if(s.begin(), s.end(), not1(ptr_fun(isspace))) + ); + + return s; +} + +string rtrim(const string &str) { + string s(str); + + s.erase( + find_if(s.rbegin(), s.rend(), not1(ptr_fun(isspace))).base(), + s.end() + ); + + return s; +} + +vector split(const string &str) { + vector tokens; + + string::size_type start = 0; + string::size_type end = 0; + + while ((end = str.find(" ", start)) != string::npos) { + tokens.push_back(str.substr(start, end - start)); + + start = end + 1; + } + + tokens.push_back(str.substr(start)); + + return tokens; +} From 0f5085b048b8c74db29a4f0184b1143de61c4796 Mon Sep 17 00:00:00 2001 From: Amar Shankar Date: Tue, 26 Oct 2021 15:37:47 +0530 Subject: [PATCH 4/4] hackerrank Solved - Utopian Tree --- hackerrank/Utopian Tree.cpp | 72 +++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 hackerrank/Utopian Tree.cpp diff --git a/hackerrank/Utopian Tree.cpp b/hackerrank/Utopian Tree.cpp new file mode 100644 index 0000000..e111f39 --- /dev/null +++ b/hackerrank/Utopian Tree.cpp @@ -0,0 +1,72 @@ +#include + +using namespace std; +#define ll long long +string ltrim(const string &); +string rtrim(const string &); + +/* + * Complete the 'utopianTree' function below. + * + * The function is expected to return an INTEGER. + * The function accepts INTEGER n as parameter. + */ + +int utopianTree(int n) { + ll ht = 1; + for( int i = 0 ; i < n ; i++ ){ + if(i%2==0){ + ht = ht*2; + }else { + ht += 1; + } + } + return ht; +} + +int main() +{ + ofstream fout(getenv("OUTPUT_PATH")); + + string t_temp; + getline(cin, t_temp); + + int t = stoi(ltrim(rtrim(t_temp))); + + for (int t_itr = 0; t_itr < t; t_itr++) { + string n_temp; + getline(cin, n_temp); + + int n = stoi(ltrim(rtrim(n_temp))); + + int result = utopianTree(n); + + fout << result << "\n"; + } + + fout.close(); + + return 0; +} + +string ltrim(const string &str) { + string s(str); + + s.erase( + s.begin(), + find_if(s.begin(), s.end(), not1(ptr_fun(isspace))) + ); + + return s; +} + +string rtrim(const string &str) { + string s(str); + + s.erase( + find_if(s.rbegin(), s.rend(), not1(ptr_fun(isspace))).base(), + s.end() + ); + + return s; +}