Array ProblemsThis is arrays page Array rotation-II (Juggling Algorithm)Given an zero indexed array and positive integer d,rotate the array by d-steps to the left. Array rotation-III (Reversal Algorithm)Given an zero indexed array and positive integer d,rotate the array by d-steps to the left. Array rotation-IV (Block Swap Algorithm)Given an zero indexed array and positive integer d,rotate the array by d-steps to the left. Array rotation-IGiven an zero indexed array and positive integer d,rotate the array by d-steps to the left. Segregate 0s on left side and 1s on right side in given arrayGiven an array of 0s and 1s in random order.Segregate 0s on left side and 1s on right side of the array. Brute-force: Count 0s and rewrite array first with c... Segregate and put all 0s first, then all 1s and all 2s in lastGiven an array A[] consisting 0s, 1s and 2s, put all 0s first, then all 1s and all 2s in last. Brute-force: Count 0s and 1s (using 2 varibales)and rewrite ar... Equilibrium Index in an arrayGiven an zero indexed unsorted array find(if exists) the equilibrium index. Equilibrium index of an array is an index such that the sum of elements at lower ... Leaders in an arrayGiven an zero indexed unsorted array find(if exist) the leaders in an array. An element is leader if it is greater than all the elements to its right side,th... Majority Element in an ArrayFind majority element(if exists) in a given array. Maximum j – i such that arr[j] > arr[i].Given an array arr[], find the maximum j – i such that arr[j] > arr[i]. Maximum sum with no two adjacent elementsGiven an array of positive numbers,find the maximum possible sum such that no two chosen numbers are adjacent Median of two sorted arraysere are 2 sorted arrays A and B of size n each. find the median of the array obtained after merging the above 2 arrays(i.e. array of length 2n). e.g. [[1,2,3... Move all zeros to endGiven an array of random numbers, Push all the zero’s of a given array to the end of the array Algorithm Pair with sum equal to given valueGiven an array A[] and a number x, check for pair in A[] with sum as x Print 2D-array in spiral orderGiven a matrix(2D array),print all of its elements in spiral order. e.g. [[1,2,3].[4,,5,6],[7,8,9]] => 1 2 3 6 9 8 7 4 5 Create a product array from a given arrayGiven an array ‘a’,create a product array where product[i]==product of all elements except a[i] Time-complexity: O(n) Space-complexity: O(n){for product arra... Replace every element by product of previous and nextGiven an array replace every element by product of previous and next Note: first element is replaced by product of first and second and last element by produ... Reverse an arrayGiven a zero index array reverse the order of elements Shuffling an arrayKnuth Shuffling Algorithm Choose random number between i and n-i and swap Smallest and second smallest in an arrayGiven an array of elements,Find the smallest and second smallest element. Swapping two elementsMethod 1 (using temporary variable) Union And Intersection of two arraysGiven two sorted arrays ,Print the elements in the union and intersection of these arrays Time-complexity:O(n+m)(n=length of array1 and m=length of array2) A...
Array rotation-II (Juggling Algorithm)Given an zero indexed array and positive integer d,rotate the array by d-steps to the left.
Array rotation-III (Reversal Algorithm)Given an zero indexed array and positive integer d,rotate the array by d-steps to the left.
Array rotation-IV (Block Swap Algorithm)Given an zero indexed array and positive integer d,rotate the array by d-steps to the left.
Array rotation-IGiven an zero indexed array and positive integer d,rotate the array by d-steps to the left.
Segregate 0s on left side and 1s on right side in given arrayGiven an array of 0s and 1s in random order.Segregate 0s on left side and 1s on right side of the array. Brute-force: Count 0s and rewrite array first with c...
Segregate and put all 0s first, then all 1s and all 2s in lastGiven an array A[] consisting 0s, 1s and 2s, put all 0s first, then all 1s and all 2s in last. Brute-force: Count 0s and 1s (using 2 varibales)and rewrite ar...
Equilibrium Index in an arrayGiven an zero indexed unsorted array find(if exists) the equilibrium index. Equilibrium index of an array is an index such that the sum of elements at lower ...
Leaders in an arrayGiven an zero indexed unsorted array find(if exist) the leaders in an array. An element is leader if it is greater than all the elements to its right side,th...
Maximum j – i such that arr[j] > arr[i].Given an array arr[], find the maximum j – i such that arr[j] > arr[i].
Maximum sum with no two adjacent elementsGiven an array of positive numbers,find the maximum possible sum such that no two chosen numbers are adjacent
Median of two sorted arraysere are 2 sorted arrays A and B of size n each. find the median of the array obtained after merging the above 2 arrays(i.e. array of length 2n). e.g. [[1,2,3...
Move all zeros to endGiven an array of random numbers, Push all the zero’s of a given array to the end of the array Algorithm
Pair with sum equal to given valueGiven an array A[] and a number x, check for pair in A[] with sum as x
Print 2D-array in spiral orderGiven a matrix(2D array),print all of its elements in spiral order. e.g. [[1,2,3].[4,,5,6],[7,8,9]] => 1 2 3 6 9 8 7 4 5
Create a product array from a given arrayGiven an array ‘a’,create a product array where product[i]==product of all elements except a[i] Time-complexity: O(n) Space-complexity: O(n){for product arra...
Replace every element by product of previous and nextGiven an array replace every element by product of previous and next Note: first element is replaced by product of first and second and last element by produ...
Smallest and second smallest in an arrayGiven an array of elements,Find the smallest and second smallest element.
Union And Intersection of two arraysGiven two sorted arrays ,Print the elements in the union and intersection of these arrays Time-complexity:O(n+m)(n=length of array1 and m=length of array2) A...