Solving array related problems with two indices.