J.P. Morgan Interview Question

4 algorithms to write and 4 sql queries to write.