Posts

Minimum adjacent difference in a circular array

  Minimum adjacent difference in a circular array   Easy  Accuracy:   54.61%  Submissions:   16413  Points:   2 Given an array  Arr  of  n  integers arranged in a  circular  fashion. Your task is to find the minimum absolute difference between adjacent elements. Example 1: Input: n = 7 Arr[] = {8,-8,9,-9,10,-11,12} Output: 4 Explanation: The absolute difference between adjacent elements in the given array are as such: 16 17 18  19 21 23 4 (first and last). Among the calculated absolute difference the minimum is 4. Example 2: Input: n = 8 Arr[] = {10,-3,-4,7,6,5,-4,-1} Output: 1 Explanation: The absolute difference between adjacent elements in the given array are as such: 13 1 11 1 1 9 3 11 (first and last). Among the calculated absolute difference, the minimum is 1. Your Task: The task is to complete the function  minAdjDiff () which returns the minimum difference between adjacent elements in circular array. Expected Time Complexity:  O(n). Expected Auxiliary Space:  O(1). Co

Rotate Array

  Given an unsorted array  arr[]  of size  N.  Rotate the array to the left (counter-clockwise direction) by  D  steps, where  D  is a positive integer.  Example 1: Input: N = 5, D = 2 arr[] = {1,2,3,4,5} Output: 3 4 5 1 2 Explanation: 1 2 3 4 5  when rotated by 2 elements, it becomes 3 4 5 1 2. Example 2: Input: N = 10, D = 3 arr[] = {2,4,6,8,10,12,14,16,18,20} Output: 8 10 12 14 16 18 20 2 4 6 Explanation: 2 4 6 8 10 12 14 16 18 20  when rotated by 3 elements, it becomes 8 10 12 14 16 18 20 2 4 6. Your Task: Complete the function  rotateArr () which takes the array, D and N as input parameters and rotates the array by D elements. The array must be modified in-place without using extra space.    Expected Time Complexity:  O(N) Expected Auxiliary Space:  O(1)   Constraints: 1 <= N <= 10 7 1 <= D <= N 0 <= arr[i] <= 10 5 Solution // { Driver Code Starts #include<bits/stdc++.h> using namespace std;  // } Driver Code Ends class Solution{     public:          voi