-
-
Notifications
You must be signed in to change notification settings - Fork 47k
Project Euler Problems in Hackerrank solved! #852
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
03297c8
add-binary-exponentiation
junthbasnet 8d89e6d
Project Euler (Hackerrank) - added
junthbasnet 22f8af0
Project Euler from Hackerrank - added
junthbasnet b1a9e71
Delete ProjectEuler1-Multiples-of-3-and-5.py
junthbasnet d28dbd5
Project Euler From Hackerrank - added
junthbasnet f39cdef
Quick- sort added
junthbasnet 6b16484
Delete BinaryExponentiation.py
cclauss File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
HackerRank/Project Euler/ProjectEuler1-Multiples-of-3-and-5.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Author : Junth Basnet | ||
""" | ||
https://www.hackerrank.com/contests/projecteuler/challenges/euler001/problem | ||
""" | ||
def S(n): | ||
return (n * (n + 1)) // 2 | ||
|
||
for _ in range(int(input())): | ||
|
||
n = int(input()) | ||
#Sum of natural numbers below the given number | ||
n -= 1 | ||
|
||
result = (S(n // 3) * 3) + (S(n // 5) * 5) - (S(n // 15) * 15) | ||
print(result) | ||
|
||
|
||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Author : Junth Basnet | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. LGTM. This can be merged. |
||
|
||
""" | ||
Implementation of Quick Sort Algorithm with middle element as pivot element | ||
Time Complexity : O(nlogn) - O(n^2) | ||
""" | ||
|
||
def QuickSortFirst(array): | ||
return QuickSort(array, 0, len(array) - 1) | ||
|
||
def QuickSort(array, left, right): | ||
if left >= right: | ||
return array | ||
pivot = array[(left + right) // 2] | ||
index = Partition(array, left, right, pivot) | ||
QuickSort(array, left, index - 1) | ||
QuickSort(array, index, right) | ||
return array | ||
|
||
def Partition(array, left, right, pivot): | ||
while left <= right: | ||
while array[left] < pivot: | ||
left += 1 | ||
while array[right] > pivot: | ||
right -= 1 | ||
if left <= right: | ||
array[left], array[right] = array[right], array[left] | ||
left += 1 | ||
right -= 1 | ||
return left | ||
|
||
array = [1, 6, 4, 10, 7, 30, 25] | ||
print(array) | ||
sorted_array = QuickSortFirst(array) | ||
print(sorted_array) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a
project_euler
folder in root. Please put this into one of the folders inside.