Find the smallest distance between two neighboring numbers in an array
Answers
Answered by
33
Step-by-step explanation:
Given an unsorted array arr[] and two numbers x and y, find the minimum distance between x and y in arr[]. The array might also contain duplicates. You may assume that both x and y are different and present in arr[].
Examples:
Input: arr[] = {1, 2}, x = 1, y = 2
Output: Minimum distance between 1 and 2 is 1.
Input: arr[] = {3, 4, 5}, x = 3, y = 5
Output: Minimum distance between 3 and 5 is 2.
Similar questions
Computer Science,
5 months ago
Math,
5 months ago
Physics,
11 months ago
English,
1 year ago
Science,
1 year ago