graph

[Leetcode 403] Frog Jump

Question Leetcode 403: Frog Jump A frog is crossing a river. The river is divided into x units and at each unit there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water. Given a list of stones’ positions (in units) in sorted ascending order, determine if the frog is able to cross the river by landing on the last stone.

Create tree from tuples

This is a coding problem from Uber onsite interview found here. Question: Given a list of pairs (tuples), each of them represents a connection from parent to it’s child in a tree. In this list, nodes will have edges not only for their direct children, but also all of it’s descendants (i.e. children’s children, and their children etc). If we have the following tree as an example: A / \ B C / \ D E Then the list given it will be