Lets first solve the problem for normal array-

Example —

Given array [4, 6, 7, -2, –3, –4, 20, -10]

Max Sum sub-array = (4+6+7–2–3–4+20) = 28

Solution —

Lets have currMaxSum & maxSum variables where currMaxSum will calculate max subarray including current element while maxSum will be sum in…

Problem Statement

Distribute data between servers/cache such that removal & addition server can be done efficiently & minimum data transfer should be there between servers. Also, we need to make sure data is distributed evenly b/w servers


Single machine solution -

We will store data in hashmap which will do the below…

A median of a population is any value such that at most half of the population is less than the proposed median and at most half is greater than the proposed median

It is a value which divides an array into 2 equal parts

As the name suggests collection is the group of objects & java collection framework provides implementations that can hold the group of objects.

some random image from google because people want to read an article which has good visual image. LOL

Java collection is divided into 4 main sections-

SET — It is a data structure that stores unique objects. …

Let's take the “Rat in a maze” problem, which is a common example, to understand backtracking

We have given a maze that consists of 1’s & 0’s elements. Element 1 represents the empty cell while element 0 is a wall from which the rat can not pass.

A rat starts…

Problem Statement — check whether an element is present in a matrix of size n*m in which rows & columns are sorted in increasing order.

Sample Input -

[ [1, 3, 12],

[2, 4 , 20],

[5, 10, 30]]




Solution :

The initial thought is to apply…

Prefix sum is the technique where you precompute & store the cumulative sum of the sequence of elements that allows fast sum calculation of any range.

Let's say we have a sequence of elements A as mentioned below-

A = {a0, a1, a2, a3, a4, a5}

so Prefix Sum P…

Data Structures

Array — prefix sum, 2 pointers, sliding window technique

Matrix — Search in the sorted matrix, find the kth smallest element in the sorted matrix


Stack — balanced parenthesis, expression evaluation, implement stack using queue, design stack with operation getMin(), stock span, celebrity problem, trapping rain water, max rectangle…

Jackie Vaswani

Finding peace in the chaos

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store