Skip to content

Instantly share code, notes, and snippets.

@Savion92
Savion92 / buy&SellStocks.md
Last active March 29, 2022 01:15 — forked from cieltan/buy&SellStocks.md
Day 2 - AsyncAlgos

Best Time to Buy and Sell Stock


Interviewer Prompt

Say you have an array for which the ith element is the price of a given stock on day i.

If you were only permitted to complete at most one transaction (i.e., buy one and sell one share of the stock), design an algorithm to find the maximum profit.

Note that you cannot sell a stock before you buy one.

Multiplicative Persistence


Interviewer Prompt

Given a non-negative integer, write a function that returns its multiplicative persistence--the number of times you must multiply the digits in a number together until you reach a single digit product.

Ex: 39 returns 3

Youngest Common Ancestor

PROMPT

You're given three inputs, all of which are instances of a class which has a 'name' property and an 'ancestor' property pointing to the node's immediate ancestor. The first input is the top ancestor in an ancestral tree (the only node that does not have an ancestor of its own), and the other two inputs are descendants in the ancestral tree. Write a function that returns the youngest common ancestor to the two descendents.

test cases