Snippets Collections
class Solution{
    
    //Function to find minimum adjacent difference in a circular array.
    // arr[]: input array
    // n: size of array
    public static int minAdjDiff(int arr[], int n) {
    
       int min=Math.abs(arr[0]-arr[n-1]),diff;
        for(int i=0;i<n-1;i++)
        {
            diff=Math.abs(arr[i]-arr[i+1]);
            if(diff<min)
            min=diff;
        }
        return min;
       
    }
}
star

Tue Feb 08 2022 06:10:45 GMT+0000 (Coordinated Universal Time) https://practice.geeksforgeeks.org/problems/minimum-absloute-difference-between-adjacent-elements-in-a-circular-array-1587115620/1/?track=DSASP-Arrays&batchId=190

#java #gfg #geeksforgeeks #arrays #practice #circulararray #adjacentdifference #minimumadjacentdifference

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension