Skip to content

Instantly share code, notes, and snippets.

View Fredpwol's full-sized avatar
⚔️
Building a fortress

Fredrick Pwol Fredpwol

⚔️
Building a fortress
View GitHub Profile
@Fredpwol
Fredpwol / spacex-openapi-spec.yaml
Created February 22, 2023 16:05
Space X Rest Api OpenApi Spec
openapi: 3.0.3
info:
title: r/SpaceX API V4
version: 1.0.0
contact: {}
servers:
- url: https://api.spacexdata.com
paths:
/v4/capsules:
get:
@Fredpwol
Fredpwol / cyclepath.py
Created June 20, 2021 17:16
Find circle in a graph from a start point
def depth_first_search(map, key, start):
if key == None: return []
key = key.lower() if key.lower() in map else key.upper()
if not key in map: return []
if map[key] == None: return []
res = []
for point in map[key]:
if point.lower() == start.lower():
return [point]
path = depth_first_search(map, point, start)
@Fredpwol
Fredpwol / graphCycle.py
Last active June 10, 2021 06:24
Find if a graph contains cycle
def depth_first_search(map, key, visited):
if key == None: return None
key = key.lower() if key.lower() in map else key.upper()
if not key in map: return False
if map[key] == None: return False
for point in map[key]:
if point.lower() in visited:
return True
visited.add(key.lower())
if depth_first_search(map, point, visited):
@Fredpwol
Fredpwol / timediff.py
Last active May 27, 2021 17:43
Find Minimum Time Difference
def convert_minutes(time_string):
hour, min = time_string.split(":")
hour, min = int(hour), int(min)
hour *= 60
return hour + min
def findMinimumTimDiff(times):
if times == None or len(times) == 0: return 0
@Fredpwol
Fredpwol / shuffleclass.py
Last active May 18, 2021 07:45
Class Shuffle problem
from collections import deque
def shuffleClass(arr, n):
if arr is None or len(arr) == 0: return []
if n is None: return arr
arr = deque(arr)
if n >= 0:
for _ in range(n % len(arr)):
arr.appendleft(arr.pop())
@Fredpwol
Fredpwol / mergelist.py
Last active May 13, 2021 14:53
Merge Sorted List
def mergeSortedList(l1, l2):
if l1 == None and l2 == None:
return []
elif l1 != None and l2 == None:
return l1
elif l2 != None and l1 == None:
return l2
res = []
@Fredpwol
Fredpwol / products.py
Last active May 4, 2021 21:56
Find array value products
def arrayProducts(arr):
if arr == None: return []
if len(arr) == 1: return [0]
left_mul = 1 #this holds product so far from the left side
for i in range(len(arr)):
right_mul = 1
for j in range(i+1, len(arr)): # this loops from the index of the current value + 1 to the end
right_mul *= arr[j]
temp_v = arr[i]
@Fredpwol
Fredpwol / findpos.py
Created April 23, 2021 17:50
Find num start and end position in a list after sorting
def findSortedPosition(nums, val):
if nums == None: return [-1, -1]
if val == None: return [-1, -1]
prev_num = None
nums_less = 0
num_val = 0
for num in nums:
if num < val:
@Fredpwol
Fredpwol / findpos.py
Last active April 27, 2021 12:02
Find num start and end position in a list after sorting
def findSortedPosition(nums, val):
"This solution takes O(n) time complexity and O(1) space complexity"
if nums == None: return [-1, -1]
if val == None or type(val) != int: return [-1, -1]
nums_less = 0
num_val = 0
for num in nums:
if num < val:
@Fredpwol
Fredpwol / Instance.py
Last active April 27, 2021 14:38
Remove All Instance
def remove_all_instances(nums, val):
"""
This returns the number of values in num that isn't equal to val
its time complexity is O(n/2) because I used two pointers to navigate from left to right
and from right to left the both meet at p = n/2. while space O(1)
"""
if nums == None: return 0
if val == None: return 0