Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions .idea/cs-module-project-algorithms.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 21 additions & 5 deletions eating_cookies/eating_cookies.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,30 @@
'''
"""
Input: an integer
Returns: an integer
'''
"""


def eating_cookies(n):
# Your code here
"""
Cookie Monster can eat either 1, 2, or 3 cookies at a time
Implement a function eating_cookies that counts the number of possible ways Cookie Monster
can eat all of the cookies in the jar.
"""
# Plan: Use Recursion until you hit the base cases
if n == 3:
return 4
if n == 2:
return 2
if n == 1:
return 1
if n <= 0:
return 1
if n > 3:
return eating_cookies(n - 3) + eating_cookies(n - 2) + eating_cookies(n - 1)

pass

if __name__ == "__main__":
# Use the main function here to test out your implementation
num_cookies = 5
num_cookies = 4

print(f"There are {eating_cookies(num_cookies)} ways for Cookie Monster to each {num_cookies} cookies")
20 changes: 14 additions & 6 deletions moving_zeroes/moving_zeroes.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
'''
Input: a List of integers
Returns: a List of integers
'''
def moving_zeroes(arr):
# Your code here
"""
Write a function that takes an array of integers and moves each non-zero integer
to the left side of the array, then returns the altered array.
The order of the non-zero integers does not matter in the mutated array.
Input: a List of integers
Returns: a List of integers
"""
# so could append to the end if it equals zero
for i in arr:
if i == 0:
# remove so that we don't have leftover zeroes
arr.remove(i)
arr.append(i)

pass
return arr


if __name__ == '__main__':
Expand Down
30 changes: 23 additions & 7 deletions product_of_all_other_numbers/product_of_all_other_numbers.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
'''
Input: a List of integers
Returns: a List of integers
'''
# https://discuss.codecademy.com/t/challenge-product-of-everything-else/176317
def product_of_all_other_numbers(arr):
# Your code here

pass
"""
Write a function that receives an array of integers and returns an array
consisting of the product of all numbers in the array except the number at that index.
:param arr: a list of integers
:return: a list of integers
"""
# so someway to exclude the index while we are doing multiplying
# results to keep the result of all the products except index
result = 1
# product_list to put each product for each value
product_list = []
# loop through the arr
for i in range(len(arr)):
# access each number in the arr
for n in arr:
if n != arr[i]:
# if n doesn't equal the current number for i then multiple it
result *= n
product_list.append(result)
# restart
result = 1
return product_list


if __name__ == '__main__':
Expand Down
21 changes: 12 additions & 9 deletions single_number/single_number.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
'''
Input: a List of integers where every int except one shows up twice
Returns: an integer
'''
def single_number(arr):
# Your code here

pass

"""
Given a non-empty array of integers where every element appears twice except for one. Find that single number.
Input: a List of integers where every int except one shows up twice
Returns: an integer
"""
# isn't there a way to take the item in the list then iterate over it until it finds it another pair?
# iterate
for i in arr:
# if the number of values is 1 return the single value
if arr.count(i) == 1:
return i

if __name__ == '__main__':
# Use the main function to test your implementation
arr = [1, 1, 4, 4, 5, 5, 3, 3, 9, 0, 0]

print(f"The odd-number-out is {single_number(arr)}")
print(f"The odd-number-out is {single_number(arr)}")
48 changes: 42 additions & 6 deletions sliding_window_max/sliding_window_max.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,47 @@
'''
Input: a List of integers as well as an integer `k` representing the size of the sliding window
Returns: a List of integers
'''
from _collections import deque
def sliding_window_max(nums, k):
# Your code here
"""
Given an array of integers, there is a sliding window of size k which is moving from the left side of the array
to the right, one element at a time. You can only interact with the k numbers in the window. Return an array
consisting of the maximum value of each window of elements.
Input: a List of integers as well as an integer `k` representing the size of the sliding window
Returns: a List of integers
"""
# result for max inside the windows
# array that will hold the list of maximums
# divide as you iterate over the arr to get a new subarray each time
# window - nums[n:k + n]

max_vals = [0 for _ in range(len(nums) - k + 1)]
for i in range(len(max_vals)):
current_elem = nums[i]
for j in range(1, k):
if nums[i +j] > current_elem:
current_elem = nums[i + j]
max_vals[i] = current_elem
return max_vals

# remove all elems from a queue
# max_vals = []
# q = deque()
# # remove all elems from a queue
# for i, n in enumerate(nums):
# while len(q) > 0 and n > q[-1]:
# q.pop()
# q.append(n)
# # calc the window range
# window_range = i - k + 1
# # as long as our windows range == k, then we will add elements to the queue
# if window_range >= 0:
# # add the max elem (in this case first in the queue) to the max_vals
# max_vals.append(q[0])
# # check num on the left needs to be evicted
# # if so take it out of the start of the queue
# if nums[window_range] == q[0]:
# q.popleft()
# return max_vals


pass


if __name__ == '__main__':
Expand Down