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
11 changes: 11 additions & 0 deletions challenges/LukeGavelWork/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Hello, this is my work on the backend and database problem.

It was the first time I coded API related software and was struggling to find
a way to test it while flask was running. I believe it is set up correctly,
but I'm not familiar enough with flask to trigger the post or get commands

Next I have a layout of relational model version of the NOSQL model. Again,
not extremely familiar with databases so from looking at examples of relational database
I think I understand the gist: grouping data based on its relation with each other.
Apologies if I missed the mark on that. I did not have enough time to work on
the second half of the challenge.
Binary file added challenges/LukeGavelWork/RelationalModel.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 32 additions & 0 deletions challenges/LukeGavelWork/restAPI.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from flask import Flask, request, jsonify

restAPI = Flask(__name__)

data_pool = [

]


@restAPI.post("/data")
def sendData():
if type(request) != list:
return {"Error": "list of numbers not submitted"}, 415
elif len(request) != 500:
return {"Error": "incorrect number of data entries"}, 415
elif not(all(item.isdigit() for item in request)):
return {"Error": "list contains none numeric values"}, 415
elif not(request.is_json):
return {"Error": "Request must be JSON"} , 415
else:
data = request.get_json()
data["id"] = _find_next_id()
data_pool.append(data)


@restAPI.get("/data")
def getData():
return jsonify(data_pool)

#@restAPI.patch("/data")


16 changes: 16 additions & 0 deletions challenges/LukeGavelWork/restAPI_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from restAPI import restAPI
from flask import json
from random import randint

def test_add():
d = []
for i in range(500):
d.append(i)


response = restAPI.test_client().post("/data", data = jsonify(d), content_type='application/json',)

data = json.loads(response.get_data(as_test=True))

assert response.status_code == 200
assert data['1'] == d
20 changes: 20 additions & 0 deletions interviews/python/Solve.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#values added to dictionary recursively to save some time over iterative
def encode(arr,dictionary,ind):
#if gone through whole array
if ind == len(arr):
return dictionary
#if the letter/number has been seen before and exists in dictionary, increase the value by 1
elif arr[ind] in dictionary:
dictionary[arr[ind]] = dictionary.get(arr[ind]) + 1
encode(arr,dictionary,ind+1)
#the value is not in the dictionary and therefore needs to be added
else:
dictionary[arr[ind]] = 1
encode(arr,dictionary,ind+1)

#empty dictionary and data set
dictionary = {}
data = ['t','t','t','t','b','c','c','a','a','d','r','r','r','r','d','y','x','x','y','j','q','u','i']

encode(data,dictionary,0)
print(dictionary)