What is the difference between bottom-up and top-down?

The bottom-up approach (to dynamic programming) consists in first looking at the “smaller” subproblems, and then solve the larger subproblems using the solution to the smaller problems. The top-down consists in solving the problem in a “natural manner” and check if you have calculated the solution to the subproblem before. I’m a little confused. What … Read more

Get the time difference between two datetimes

I know I can do anything and some more envolving Dates with momentjs. But embarrassingly, I’m having a hard time trying to do something that seems simple: geting the difference between 2 times. Example: var now = “04/09/2013 15:00:00”; var then = “04/09/2013 14:20:30”; //expected result: “00:39:30” what I tried: var now = moment(“04/09/2013 15:00:00”); … Read more

Java 8: Difference between two LocalDateTime in multiple units

I am trying to calculate the difference between two LocalDateTime. The output needs to be of the format y years m months d days h hours m minutes s seconds. Here is what I have written: import java.time.Duration; import java.time.Instant; import java.time.LocalDateTime; import java.time.Period; import java.time.ZoneId; public class Main { static final int MINUTES_PER_HOUR = … Read more