LeetCode 223 Rectangle Area in Java

In this post we will solve LeetCode 223 Rectangle Area in Java.

Given the coordinates of two rectilinear rectangles in a 2D plane, 
return the total area covered by the two rectangles.

The first rectangle is defined by its bottom-left corner (ax1, ay1) and its top-right corner (ax2, ay2).

The second rectangle is defined by its bottom-left corner (bx1, by1) and its top-right corner (bx2, by2).

Constraints:

o -10^4 <= ax1, ay1, ax2, ay2, bx1, by1, bx2, by2 <= 10^4

Related Topics:

o Math
o Geometry

We are given the coordinates of two rectilinear rectangles in a 2D plane and are asked to return the total area covered by the two rectangles. Continue reading “LeetCode 223 Rectangle Area in Java”

LeetCode 872. Leaf-Similar Trees in Java

In this post we will be solving LeetCode 872. Leaf-Similar Trees. As usual, if interested, please visit the LeetCode site and read the current version of the problem to make sure all is well before you start developing code.

Consider all the leaves of a binary tree, 
from left to right order, 
the values of those leaves form a leaf value sequence.

Two binary trees are considered leaf-similar if their leaf value sequence is the same.

Return true if and only if the two given trees with head nodes root1 and root2 are leaf-similar.

Constraints:

o The number of nodes in each tree will be in the range [1, 200].
o Both of the given trees will have values in the range [0, 200].

Related Topics:

o Tree
o Depth-First Search
o Binary Tree

We are given two binary trees. We need to determine if the sequence of leaf nodes match or not. Seems like an in-order tree traversal problem. We could populate a list with the leaf nodes of the first tree and repeat with the nodes of the second tree. Our answer will be based on the contents of both lists. Continue reading “LeetCode 872. Leaf-Similar Trees in Java”

LeetCode 1185 Day of the Week in Java

In this post we will attempt to solve the LeetCode 1185 Day of the Week problem.

Given a date, return the corresponding day of the week for that date.

The input is given as three integers representing the day, month and year respectively.

Return the answer as one of the following values {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}.

In a nutshell we are given a date in day, month, and year and we need to return a string that contains the name of the day. The problem is very easy to understand. Continue reading “LeetCode 1185 Day of the Week in Java”

Merge Sort Revisited

Good morning! Hope your day has started on the right note. Yesterday was quite hectic for me. Hopefully the day will go as smooth as possible. Continue reading “Merge Sort Revisited”