[Leetcode]1553. Minimum Number of Days to Eat N Oranges

LeetCode_logo
There are n oranges in the kitchen and you decided to eat some of these oranges every day as follows:
Eat one orange.
If the number of remaining oranges (n) is divisible by 2 then you can eat  n/2 oranges.
If the number of remaining oranges (n) is divisible by 3 then you can eat  2*(n/3) oranges.
You can only choose one of the actions per day.
Return the minimum number of days to eat n oranges.
Constraints:
1 <= n <= 2*10^9
Continue reading “[Leetcode]1553. Minimum Number of Days to Eat N Oranges”

[Leetcode problems] 45 Jump Game II

LeetCode_logo
Given an array of non-negative integers, you are initially positioned at the first index of the array. Each element in the array represents your maximum jump length at that position.
Your goal is to reach the last index in the minimum number of jumps.
Example:
Input: [2,3,1,1,4] 
Output: 2 
Explanation: The minimum number of jumps to reach the last index is 2. 
Jump 1 step from index 0 to 1, then 3 steps to the last index.
Note:
You can assume that you can always reach the last index.
Continue reading “[Leetcode problems] 45 Jump Game II”

Intro to Graph Algorithms – BFS & DFS

Graphs are a pervasive data structure in computer science, and algorithms for working with them are fundamental to the field.

Cormen, Thomas H., et al. Introduction to algorithms. MIT press, 2009.

Given a graph defined as G=(V,E) which is a set of vertices and edges, we’d be curious about how to represent it and how to search it systematically so as to visit the vertices following the edges. This blog will briefly introduce two ways of representations of a graph, and then will dive deep into two graph search algorithms: Breadth-First-Search (BFS) and Depth-First-Search (DFS).

Continue reading “Intro to Graph Algorithms – BFS & DFS”