Move Zeroes to the front of an Integer Array

Given an array of integers, move all the zeroes to the beginning of the array, leaving the order of the other integers unaltered. This operation has to be done in place.

Time Complexity O(n)
Java

Output

JavaScript

Demo


Follow Up
To do the opposite and move zeroes to the end of the array we need to start from the beginning with the counter at 0.

Maximum Water Capacity in a Histogram

bar graph

Calculate the maximum amount of water that can held within a bar graph without overflow.
The amount of water that can be held at any point is the difference of the minimum of the maximum of left bars and maximum of right bars and the height of that point.
If we don’t precompute the maximum values on left and right for every index, the time complexity becomes O(n^2). So we go with the precompute option.

Time Complexity O(n)
Space Complexity O(n)

Code

Output

Find the maximum product of 3 integers in a list

The following code handles negatives as well.

Time Complexity O(n)
Space Complexity O(1)

Code

Output

code jam Tidy Numbers

Question

Demo

Find the maximum size of square of side ‘X’ in a matrix

We use dynamic programming to solve this.
Space complexity = O(2*n)
Time complexity = O(n^3).

Output