Arrays Conceptual Questions

Hello Geeks , I am going to discuss important concepts based on array questions . Try to do code by yourself these questions . As i am not going in Algorithms ,so i will explain some basic concepts. These questions are basic for beginners , So if you know solutions of questions then don’t think that it is enough. For any Query, do comment .

Before go into questions , let’s take look about array .

Array is linear indexed based data structure which allocate memory location based on type of data , if it is integer then each cell will allocate memory cell of 4 byte. Let’s take example , I assume that you know about declaration of array .

int arr[] = new int[5] , here we are creating an array of size 5 which will allocate 5 memory locations of 4 bytes , if we want to fetch data then arr[i] will help to fetch it . Rest of information , you can get from https://www.geeksforgeeks.org/ .

Important Basic Concepts :

Qusetion1 : Given an array [1,2,3,4] , you need to change this array by performing following operation , You need to update i_th index with value of multiplication of all elements except itself but constraint is you can not use divide operator here .

Let’s take example , A[1,2,3,4] then updated array will be A[24, 12, 8, 6] . It means that A[0] = A[1] * A[2] * A[3]

A[1] = A[0] * A[2] * A[3]

A[2] = A[0] * A[1] * A[3]

A[3] = A[0] * A[1] * A[2] , This operation you have to perform , so write a program to update this array.


Question2 : Given an array A contains positive integers , you need to find pairs whose sum is divisible by K .

example :- A[1, 3, 6, 7] K= 2

here pairs will be (1, 3), (1, 7), (3, 7) so ans will be 3 because sum of all pairs is divisible by 2.


Question3 : Given an array A and integer d we need to left rotate our array by d times.

example : A[1,0,9,10] d = 3 , We need to left rotate our array by 3 times, So our new rotated array should be A[10,1,0,9] .

after 1rotation

A[0, 9, 10, 1]

after 2rotation

A[9,10, 1, 0]

after 3rotation

A[10, 1, 0, 9] will be our answer….


Question4 : Given an array A ,every element repeats twice but there is only element which occurred once , So find that one element.

example:- A[1, 3, 4, 3, 1] , So answer should be 4 as it is occurred for once.


Question5 : Given two sorted array A and B , we need to merge these two arrays and return new Array contains all elements of A and B in sorted order.

example:- A[0, 2, 4, 7, 9] , B[4, 5, 7, 11, 27] So we have these two arrays and need to merge these two array and return ans[0,2,4,4,5,7,7,9,11,27] as answer.


Question6 : I am doing a variation in qus5 is that , you need to return a new array which contains all elements without duplicacy .

example:- A[0, 2, 4, 7, 9], B[4, 5, 7, 11, 27] So we need to return our ans as ans[0, 2, 4, 5, 7, 9, 11, 27] . It means that you need to return only unique elements which are present in both A and B arrays.


Question7 : Given an array a containing integers , you need to return maximum sum of any sub-array.

example:- A[1, 2, -1, 4, 5, -10, 4] ,here ans will be 1 + 2 + (-1) + 4 + 5 = 11 .


Question8 : Given an array A contain duplicate integers , you need to find the majority element which appears greater than n/2 time where n is length of array.

example: A[1,1,1,2,3,3,1], here majority element is 1 because 1 apprear greater than (7/2)->3.


Question9 : Given an array containing 0s, 1s and 2s , you need to update array so that every 0s , 1s and 2s will come together .

Twist is that you can not use any sorting algorithms on given array.

example: A[0, 0, 1, 2, 2, 0, 1, 2, 0] -> A[0, 0, 0, 0, 1, 1, 2, 2, 2] , here All 0s ,1s and 2s came together and return new update array.


Question10 : Find a triplet in an array whose sum is closest to K .

example: A[-1, 2, 1, -4], K = 1 so ans will be 2 which is very closest to 1.


Get Some useful video resources for solutions….

Question7
Question3
Question4
Question10
Question8

Geeks , comment your queries or ping me on Linkedin . Keep doing great ……..

Follow My Blog

Subscribe and Share ,So every beginner will get sharp shape in Ds Questions.

  1. Pradhuman Shankar's avatar
  2. Shubhangi Verma's avatar

    This was really helpful….like a written version of all the advices you gave me sir!

  3. Abhishek's avatar

    Nice and simple explanation

Design a site like this with WordPress.com
Get started