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
// basic arithmetic calculator without a frontend | |
var operations = ["+", "-", "*", "/", "**", "%"] | |
let operation = prompt("Please enter operation"); | |
// check if operation is valid | |
while (true){ | |
if (!(operations.includes(operation))){ | |
operation = prompt("Invalid operation: Enter operation again") | |
} | |
else { |
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
// JavaScript code that prints out my name, height, and country on the screen | |
console.log("Name: Julius Odunuga") | |
console.log("Height: 1.7m"); | |
console.log("Country: Nigeria"); |
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
import networkx as nx | |
def isThereCycle(graph): | |
if graph==None or type(graph) != dict or len(graph)<0: return False | |
edges = [(a.upper(),b.upper()) for a in graph for b in graph[a]] | |
G = nx.DiGraph(edges) | |
if list(nx.simple_cycles(G)): | |
return True | |
else: | |
return False |
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
# First define the list of chars for all digits | |
num_dict = {'2': ['a', 'b', 'c'], | |
'3': ['d', 'e', 'f'], | |
'4': ['g', 'h', 'i'], | |
'5': ['j', 'k', 'l'], | |
'6': ['m', 'n', 'o'], | |
'7': ['p', 'q', 'r', 's'], | |
'8': ['t', 'u', 'v'], | |
'9': ['w', 'x', 'y', 'z'], | |
# just incase 0 and 1 is part of input, we can safely skip |
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
def shortest_interval(time_arr = []): | |
if time_arr == None or not isinstance(time_arr, list): | |
return 0 | |
else: | |
# convert time_array to minutes | |
timeInMin = [] | |
for time in time_arr: | |
try: | |
h,m = time.split(':') | |
if int(h)<24 and int(m)<60: |
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
def shiftLeft(arr, numm): | |
for _ in range(numm): # O(k) | |
temp = arr[0] | |
for i in range(len(arr)-1): # O(n) | |
arr[i] = arr[i+1] | |
arr[-1] = temp | |
return arr | |
def shiftRight(arr, numm): | |
for _ in range(numm): # O(k) |
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
def merge_sorted_list(a=[],b=[]): | |
try: | |
if (a == None or len(a)==0) and (b== None or len(b)==0): | |
return [] | |
elif a==None or len(a)==0: | |
return b | |
elif b==None or len(b)==0: | |
return a | |
# if last element in a is not greater than first element in b, then append b to a | |
elif a[-1]<=b[0]: |
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
def get_product(nums=[]): | |
""" | |
Given an integer array nums, | |
returns an arry products, such that each entry at position i, in products is a produc of all the other lements in nms except num[i] | |
Examle: nums=[4,5,10,2] | |
Output: [100,80,40,200] | |
""" | |
try: |
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
def remove_instance(nums, val): | |
""" | |
Given an array nums, and a value val, returns the new length of the array with the value removed | |
i.e. the number of items in nums with val | |
Input: nums=[5, 2, 2, 5, 3] and val = 5 | |
Output: 3 | |
""" | |
try: | |
#check for cases of an empty array | |
if len(nums) == 0: |
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
def remove_duplicates(input_array): | |
""" | |
Given a sorted array containing duplicates this function | |
returns the length of the array without the duplicates | |
i.e. the number of unique items in the array | |
Input: nums=[0,0,1,1,2,2,3,3,4] | |
Output: 5 | |
# O(n) time, O(1) space complexity |