• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests
November 03, 2023 |1.8K Views
PROBLEM OF THE DAY: 02/11/2023 | Minimum distance between two numbers
Description
Discussion

Welcome to the daily solving of our PROBLEM OF THE DAY with Karan Mashru. We will discuss the entire problem step-by-step and work towards developing an optimized solution. This will not only help you brush up on your concepts of Arrays but will also help you build up problem-solving skills.

In this problem, we are given, an array a, of n elements. Find the minimum index-based distance between two distinct elements of the array, x and y. Return -1, if either x or y does not exist in the array.

Example :

Input:
N = 4
A[] = {1,2,3,2}
x = 1, y = 2
Output: 1

Explanation: x = 1 and y = 2. There are two distances between x and y, which are 1 and 3 out of which the least is 1.

Give the problem a try before going through the video. All the best!!!

Problem Link: https://www.geeksforgeeks.org/problems/minimum-distance-between-two-numbers/1
Solution IDE Link: https://ide.geeksforgeeks.org/online-cpp-compiler/6f62e8b4-01b5-4ea2-939b-db70e53add43