Problems
Array insert at end Array insert at index Median of an array Mean of an array Second Largest in an array Strongest Neighbour Reverse array in groups Rotate arrayMinimum absolute difference of adjacent elements in a Circular Array
Given a circular array arr[] of length N, the task is to find the minimum absolute difference between any adjacent pair. If there are many optimum solutions, output any of them.
Examples:
Input: arr[] = {10, 12, 13, 15, 10}
Output: 0
Explanation: |10 β 10| = 0 is the minimum possible difference.
Input: arr[] = {10, 20, 30, 40}
Output: 10
Explanation: |10 β 20| = 10 is the minimum, 20 30 or 30 40 could be the answer too.
Check if an array is sorted and rotated
Given an array arr[] of size n, the task is to return true if it was originally sorted in non-decreasing order and then rotated (including zero rotations). Otherwise, return false. The array may contain duplicates.
Examples:
Input: arr[] = { 3, 4, 5, 1, 2 }
Output: YES
Explanation: The above array is sorted and rotated
Sorted array: {1, 2, 3, 4, 5}
Rotating this sorted array clockwise
by 3 positions, we get: { 3, 4, 5, 1, 2}
Input: arr[] = {3, 4, 6, 1, 2, 5}
Output: NO
Explanation: The above array canβt be rotated clockwise to form the sorted array.
Longest subarray with all even or all odd elements
Given an array A[ ] of N non-negative integers, the task is to find the length of the longest sub-array such that all the elements in that sub-array are odd or even.
Examples:
Input: A[] = {2, 5, 7, 2, 4, 6, 8, 3}
Output: 4
Explanation: Sub-array {2, 4, 6, 8} of length 4 has all even elements
Input: A[] = {2, 3, 2, 5, 7, 3}
Output: 3
Explanation: Sub-array {5, 7, 3} of length 3 has all odd elements