We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • HackerRank Home

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Apply
  • Hiring developers?
  1. Minimum Absolute Difference in an Array

Minimum Absolute Difference in an Array

Problem
Submissions
Leaderboard
Discussions
Editorial

The absolute difference is the positive difference between two values and , is written or and they are equal. If and , . Given an array of integers, find the minimum absolute difference between any two elements in the array.

Example.

There are pairs of numbers: and . The absolute differences for these pairs are , and . The minimum absolute difference is .

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 , the size of .
The second line contains space-separated integers, .

Constraints

Author

shashank21j

Difficulty

Easy

Max Score

100

Submitted By

6082

Need Help?


View discussions
View editorial
View top submissions

rate this challenge

MORE DETAILS

Download problem statement
Download sample test cases
Suggest Edits
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy