diff --git a/MinimumSpanningTrees b/MinimumSpanningTrees new file mode 160000 index 0000000..fab2141 --- /dev/null +++ b/MinimumSpanningTrees @@ -0,0 +1 @@ +Subproject commit fab2141102b0719270b47e6281c52545d55a93da 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; +} 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; +} 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; +}