Use DFS to flatten Javascript Objects

This is straight forward implementation of the DFS (Depth First Search) traversal algorithm using recursion.

Output

Demo

Get maximum sum rectangle sub matrix in a 2D matrix

This problem can be solved using Kadane’s Algorithm.
We start by taking an empty array of zeros of size of the number of rows of input matrix.
We move from left to right columns and calculate max for every column and update up, down, left, right accordingly.
Input matrix mxn
Time = O(m*n*n)
Space = O(m)

Output

Kadane’s Algorithm for maximum sum subarray with Indices [Handles Negatives] O(n)

This algorithm can be used to calculate the maximum sum subarray with indices in any given array (length=n) of integers in 0(n) Time and O(1) space.

Output

This algorithm can be used to find out the maximum sum rectangular sub-matrix in an mxn matrix in O(n*n*m) time and O(m) space.

Sorting Objects in a Priority Queue

This is an implementation that shows you how to override the comparator to sort objects by a property in a Priority Queue. You can use Priority Queues in algorithms like Dijkstra’s and A* to remove the element with the least f(n) value in each iteration. Overriding the compare method can be used to sort ArrayLists (Dynamic Arrays in Java) with sort() method.

Comparator

Output:
John
Shiva

Lambda Functions

If you want to use a more shorter format you can use lambda functions

Output:
John
Shiva