# Array - Data Structure

In this section we will get in depth knowledge of Array Data Structure, including Array interview questions with solution and Array based logical problems.

We will also look into time and space complexity of different algorithms and problems based on Arrays.

These Array based data structures and algorithms questions with complete explanation and implementation in Java are very helpful in cracking any software engineering interview.

## Find subarrays with given sum in an array

Given an array A with length N, the task is to print all possible subarrays whose sum is equals to a given number "sum".

## Find index that divides an array into two subarrays of equal sum

Find index that divides an array into two subarrays of equal sum, The task is to find the index that divides the array into two subarrays of equal sum. If the array can not be divided in equal sum the method should return -1

## Check for duplicate elements within a given range k in an array

Given an array A with length n, the task is to find duplicates within a given range k in the array. We can solve this problem in O(n) time using O(n) extra space.

## Merge two sorted arrays in O(n+m) time and O(m+n) extra space

Given two sorted arrays, A1, A2 the task is to merge them in a sorted manner. We can solve this problem in O(n1+n2) time and O(n1+n2) extra space.

## Segregate positive and negative numbers in Array

Given an array arr[] with length n, the task is to rearrange the array is such a way so that the output array should contain all the negative elements in the starting of the array followed by all positive integers.

## Print Largest Sum Contiguous Subarray

Given an array arr[] of length n, the task is to find the contiguous subarray within the array which has the largest sum. We can solve this problem in O(n) time complexity using Kadane's Algorithm.

## Activity Selection Problem

In and Activity Selection Problem we are given a set of activities with their start and finish time, the task is to find out the maximum number of activities completed by a single person.

## Array Left rotation by k elements using extra space

In this article we will see how to left rotate an array by k elements using extra space O(k) and in O(n) time complexity, lets assume the given array is: Input: int [] arr = {1,2,3,4,5,6,7};

## Array Left rotation by k elements one by one

In this article we will see how to left rotate an array by k elements using constant space space O(1) and in O(k*n) time complexity, lets assume the given array is:

Input: int [] arr = {1,2,3,4,5,6,7};
k=3
Output: int [] arr = {4,5,6,7,1,2,3};

## Array Left rotation by k elements using reversal algorithm

In this article we will see how to left rotate an array by k elements using reversal algorithm, it takes constant space space O(1) and in O(n) time complexity

## Arrange elements in an array based on their index

In this article we will solve a problem where we need to place elements in an array in their matching indexes, in case a matching element is not available for the index, -1 will be placed there.

## Write a program to reverse an array in Java

In this article we will see how to reverse an array using both iterative and recursive method, lets assume we have an array as shown below:

## Move all zero in an array to the end in Java

Lets assume we have given an array as shown below, the task is to move all zero elements to the end of array while non zero elements to the left of them.

## Rearrange elements in an array in max, min order in Java

In this article we will see how to rearrange an array to store elements in max, min order, lets assume we have an array as shown below:

## Find all pair of elements in an array whose sum is equals to a given number

Today we will see how to find all pair of elements in an array whose sum is equals to a given number, lets assume we are given an input array as: