# Minimum Absolute Difference in an Array

### Problem Statement :

```The absolute difference is the positive difference between two values a and b, is written | a - b | or | b - a |  and they are equal. If a = 3 and  b = 20,  | 3 - 2 | = | 2 - 3 | = 1 . Given an array of integers, find the minimum absolute difference between any two elements in the array.

Function Description

Complete the minimumAbsoluteDifference function in the editor below. It should return an integer that represents the minimum absolute difference between any pair of elements.

minimumAbsoluteDifference has the following parameter(s):

int arr[n]: an array of integers
Returns

int: the minimum absolute difference found
Input Format

The first line contains a single integer n, the size of arr.
The second line contains n space-separated integers,  arr [ i ].

Constraints

2  <=  n   <=   10^5
- 10^9   <=   arr[ i ]   <=  10^9

Sample Input 0

3
3 -7 0
Sample Output 0

3```

### Solution :

```                            ```Solution in C :

In  C :

#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <stdbool.h>

int cmpfunc (const void * a, const void * b)
{
return ( *(int*)a - *(int*)b );
}

int main(){
int n,min,i;
scanf("%d",&n);
int a[n];
for(i=0;i<n;i++){
scanf("%d",&a[i]);
}
qsort(a, n, sizeof(int), cmpfunc);
min=a[1]-a[0];
for(i=0;i<n-1;i++){
if(min>(a[i+1]-a[i])){
min=(a[i+1]-a[i]);
}
}
printf("%d",min);
return 0;
}```
```

```                        ```Solution in C++ :

In  C++ :

#include<bits/stdc++.h>

using namespace std;

int main(){
int n;
cin >> n;
int a[n];
for(int i = 0; i < n; i++){
cin >> a[i];
}
sort(a, a + n);
int ans = 2000000001;
for(int i = 1; i < n; i++){
if(a[i] - a[i - 1] < ans){
ans = a[i] - a[i - 1];
}
}
cout << ans;
}```
```

```                        ```Solution in Java :

In  Java :

import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Solution {

public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int[] a = new int[n];
for(int a_i=0; a_i < n; a_i++){
a[a_i] = in.nextInt();
}
Arrays.sort(a);
int minimum=999999999;
for(int i = 1; i  <  (a.length - 1); i++){
int temp = Math.abs(a[i+1] - a[i]);
if (temp  <  minimum)
minimum = temp;
}
System.out.println(minimum);
}
}```
```

```                        ```Solution in Python :

In Python3 :

#!/bin/python3

import sys

n = int(input().strip())
a = list(map(int, input().strip().split(' ')))
a.sort()
m=a[-1]-a[0]
for i in range(1,n):
if a[i]-a[i-1]<m:
m=a[i]-a[i-1]
print(m)```
```

## Get Node Value

This challenge is part of a tutorial track by MyCodeSchool Given a pointer to the head of a linked list and a specific position, determine the data value at that position. Count backwards from the tail node. The tail is at postion 0, its parent is at 1 and so on. Example head refers to 3 -> 2 -> 1 -> 0 -> NULL positionFromTail = 2 Each of the data values matches its distance from the t

## Delete duplicate-value nodes from a sorted linked list

This challenge is part of a tutorial track by MyCodeSchool You are given the pointer to the head node of a sorted linked list, where the data in the nodes is in ascending order. Delete nodes and return a sorted list with each distinct value in the original list. The given head pointer may be null indicating that the list is empty. Example head refers to the first node in the list 1 -> 2 -

## Cycle Detection

A linked list is said to contain a cycle if any node is visited more than once while traversing the list. Given a pointer to the head of a linked list, determine if it contains a cycle. If it does, return 1. Otherwise, return 0. Example head refers 1 -> 2 -> 3 -> NUL The numbers shown are the node numbers, not their data values. There is no cycle in this list so return 0. head refer

## Find Merge Point of Two Lists

This challenge is part of a tutorial track by MyCodeSchool Given pointers to the head nodes of 2 linked lists that merge together at some point, find the node where the two lists merge. The merge point is where both lists point to the same node, i.e. they reference the same memory location. It is guaranteed that the two head nodes will be different, and neither will be NULL. If the lists share

## Inserting a Node Into a Sorted Doubly Linked List

Given a reference to the head of a doubly-linked list and an integer ,data , create a new DoublyLinkedListNode object having data value data and insert it at the proper location to maintain the sort. Example head refers to the list 1 <-> 2 <-> 4 - > NULL. data = 3 Return a reference to the new list: 1 <-> 2 <-> 4 - > NULL , Function Description Complete the sortedInsert function

## Reverse a doubly linked list

This challenge is part of a tutorial track by MyCodeSchool Given the pointer to the head node of a doubly linked list, reverse the order of the nodes in place. That is, change the next and prev pointers of the nodes so that the direction of the list is reversed. Return a reference to the head node of the reversed list. Note: The head node might be NULL to indicate that the list is empty.