What is an Array?
In computer science, an array data structure, or simply an array, is a data structure consisting of a collection of elements (values or variables), each identified by at least one array index or key. An array is stored such that the position of each element can be computed from its index tuple by a mathematical formula.[1][2][3] The simplest type of data structure is a linear array, also called a one-dimensional array.Programming Questions on Arrays
1)Given an array find the sum of array.
Input array is {1,2,3,4,5,-4} output: 11
2)Find the missing number in a given array.
Input array is {7,3,4,5,2} output: 6
Input array is {7,3,4,5,2} output: 6
3)Find the first missing positive number in a given array.
Test case 1: input{-1,-2,0,1,2,4} output: 3
Test case 2: input{-1,-2,0,1,2,3} output: 4
4)Find the maximum and minimum element in a given array.
Input {99,0,101,-2,2,47,57,35,10} output: min = -2 max = 101
5)Find the Equilibrium index of an array.
Equilibrium index of an array is an index such that the sum of elements at lower indexes is equal to the sum of elements at higher indexes.
Ex: arr={-7, 1, 5, 2, -4, 3, 0} output: 3
3 is an equilibrium index, because: A[0] + A[1] + A[2] = A[4] + A[5] + A[6]
6)Find the nth largest element in a given array.
Input array = {10,4,5,2,11,99,57} and n=2 output: 57
7)Find the maximum time from a given array.
Input array = {1,2,3,4} output: 2341 because maximum time is 23:59
8)Given an array of strings that contains a-z return which is having maximum weight if two or more strings having the same weights return any longest array among them.
weights are a=1,b=2,c=3,..........z=26
Test case 1: input {"abc","xyz","ghij"} output: "xyz"
9)Given an array check weather, a given array is a palindrome or not.
Test case 1: input array = {10,15,25,15,10} output : Palindrome
Test case 2: input array = {30,40,50,0,40,30} output : Not a Palindrome
10)Sort the given Array
Given an array that contains both even and odd numbers in it.
Sort even numbers in increasing order and odd numbers in decending order.
Ex:- input: {6,3,1,5,4,7,8,2}
output:{2,7,5,3,4,1,6,8}
Explanation :
In an given array, even numbers are 6,4,2,8 sorted in there positions -> 2,4,6,8
Odd number are 3,1,5,7 sorted in there positions -> 7,5,3,1 final array will be {2,7,5,3,4,1,6,8}
11)Given an array find the frequency of a number K
input: arr = {1,3,5,1,2,5,7,12,5,50} and K = 5
output: 3
Cheers keep coding.
Comments
Post a Comment