diff --git a/.gitignore b/.gitignore index e7b7452..b6e4761 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,129 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class -aaasample.py +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +pip-wheel-metadata/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +.python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ diff --git a/1. solveMeFirst/solution.cpp b/1. solveMeFirst/solution.cpp new file mode 100644 index 0000000..0a2305f --- /dev/null +++ b/1. solveMeFirst/solution.cpp @@ -0,0 +1,28 @@ +/* + * Topic : Algorithms + * Subtopic : SolveMeFirst + * Language : c++ + * Problem Statement : sum of the above two integers + * Url : https://www.hackerrank.com/challenges/solve-me-first/problem +*/ + +#include +#include +#include +#include +#include +using namespace std; + +int solveMeFirst(int a, int b) { + // Hint: Type return a+b; below: + return a + b; +} + +int main() { + int num1, num2; + int sum; + cin>>num1>>num2; + sum = solveMeFirst(num1,num2); + cout< +#include + +using namespace std; + +vector split_string(string); + +/* + * Complete the simpleArraySum function below. + */ +int simpleArraySum(vector ar) { + /* + * Write your code here. + */ + return accumulate(ar.begin(), ar.end(), 0); + +} + +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 ar_itr = 0; ar_itr < ar_count; ar_itr++) { + int ar_item = stoi(ar_temp[ar_itr]); + + ar[ar_itr] = ar_item; + } + + int result = simpleArraySum(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; +} diff --git a/Solution/SimpleArraySum.py b/2. simpleArraySum/solution.py similarity index 96% rename from Solution/SimpleArraySum.py rename to 2. simpleArraySum/solution.py index 3a380da..2691e06 100644 --- a/Solution/SimpleArraySum.py +++ b/2. simpleArraySum/solution.py @@ -1,6 +1,7 @@ ''' Topic : Algorithms Subtopic : SimpleArraySum + Language : Python Problem Statement : Print the sum of the array's elements as a single integer. Url : https://www.hackerrank.com/challenges/simple-array-sum/problem ''' diff --git a/Solution/CompareTheTriplet.py b/3. CompareTheTriplet/CompareTheTriplet.py similarity index 100% rename from Solution/CompareTheTriplet.py rename to 3. CompareTheTriplet/CompareTheTriplet.py diff --git a/Solution/AVeryBigSum.py b/4. AVeryBigSum/AVeryBigSum.py similarity index 100% rename from Solution/AVeryBigSum.py rename to 4. AVeryBigSum/AVeryBigSum.py diff --git a/Solution/DiagonalDifference.py b/5. DiagonalDifference/DiagonalDifference.py similarity index 100% rename from Solution/DiagonalDifference.py rename to 5. DiagonalDifference/DiagonalDifference.py diff --git a/Solution/PlusMinus.py b/6. PlusMinus/PlusMinus.py similarity index 100% rename from Solution/PlusMinus.py rename to 6. PlusMinus/PlusMinus.py diff --git a/Solution/Staircase.py b/7. Staircase/Staircase.py similarity index 100% rename from Solution/Staircase.py rename to 7. Staircase/Staircase.py diff --git a/Solution/Mini-MaxSum.py b/8. Mini-MaxSum/Mini-MaxSum.py similarity index 100% rename from Solution/Mini-MaxSum.py rename to 8. Mini-MaxSum/Mini-MaxSum.py diff --git a/Solution/BirthdayCakeCandles.py b/9. BirthdayCakeCandles/BirthdayCakeCandles.py similarity index 100% rename from Solution/BirthdayCakeCandles.py rename to 9. BirthdayCakeCandles/BirthdayCakeCandles.py