Skip to content

Instantly share code, notes, and snippets.

@omokehinde
omokehinde / flattenList.py
Created August 1, 2019 17:42
Theorem,LLC Software Enfineer Screener
# This is a method that returns a flatten list of list in python
# It also comtains a unit test to test that the method truly returns the flatten list of list
# the test i done with the unittest framework
# importing the unittest module
import unittest
# method definition
def flattenList(ls):
flat_list = []
# QUESTION 3
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(S):
# write your code in Python 3.6
iden=[]
index=0
for i in S:
if index==len(S)-1:
# Solution to Exercises in Data structure and Algorithms in Python
# R-1.1
def is_multiple(n,m):
return True if n%m == 0 else False
print(is_multiple(4,2))
print(is_multiple(4,3))
# R-1.2 this function is not to have the multiplication,modulo, division operator. So I need to rewrite this
def is_even(k):
return True if k%2 == 0 else False
amacat_id=23280666737962
def popularNToys(numToys, topToys, toys, numQuotes, quotes):
# WRITE YOUR CODE HERE
toy_count_dict = dict()
for toy in toys:
toy_count_dict[toy] = 0 # Initialize each toy to zero
for quote in quotes:
quote = quote.split()
for word in quote:
# Python3 program to find minimum number
# of swaps required to sort an array
# Function returns the minimum
# number of swaps required to sort the array
def minSwaps(arr):
n = len(arr)
# Create two arrays and use
def solution(A):
missing = 1
for i in sorted(A):
if i == missing:
missing += 1
if i > missing:
break
return missing
print (solution([1, 3, 6, 4, 1, 2]))
# Assume we have a list of words from the English dictionary, like:
# EnglishWords: "water","big","apple","watch","banana","york","amsterdam","orange","macintosh","bottle","book"
# And another long list of string to process, write a function to identify "compound words" and return them:
# input: "paris","applewatch","ipod","amsterdam","bigbook","orange","waterbottle"
# output: "applewatch","bigbook","waterbottle
def comp_wrd(engWords, inpWords):
output = []
from datetime import datetime, timedelta
import urllib.parse
import requests
def openAndClosePrices(firstDate, lastDate, weekDay):
hacker_stock='https://jsonmock.hackerrank.com/api/stocks/search?key=value'
page=1
url=hacker_stock+urllib.parse.urlencode({ 'page': page})
json_data=requests.get(url).json()
# Divide to even as part possible
# The method is to return a list of the even possible path
# This is the link to understand the algebra;
# https://math.stackexchange.com/questions/1791795/dividing-an-integer-into-a-fixed-number-of-integers
def splitInteger(num,parts):
if num > parts:
ls =[]
for i in range(1,parts+1):
ls.append(i*num//parts)
class ShoppingCart(object):
def __init__(self):
self.total = 0
self.items = {}
def add_item(self, item_name, quantity, price):
self.total += price*quantity
self.items.update({item_name: quantity})
def remove_item(self, item_name, quantity, price):