Sự hiểu biết của tôi là điều này sẽ hoạt động như thế này, mã sẽ bắt đầu với danh sách kiểm tra Danh sách phụ [1,2,3] và chuyển đến danh sách điểm cho đến khi tất cả các dòng được chạy và sau đó chuyển trở lại danh sách kiểm tra Danh sách phụ [2,5,2 ] và tiếp tục. Mục tiêu của tôi là có được một danh sách sẽ đọc như thế này; min_dist [[1,0], [2,0], [3,0]] vì khoảng cách tối thiểu giữa các điểm đó tất nhiên là cùng một điểm.
Tôi đang làm gì đó sai ở đây?
import math as m
test = [[1, 2,3], [2, 5,2],[3,6,8]]
points = [[1, 2,3],[2,5,2],[3,6,8]]
distance = []
min_dist = []
for i in test:
x1 = i[1]
y1 = i[2]
print i
for j in points:
x2 = j[1]
y2 = j[2]
ID = j[0]
print j
dist = m.sqrt[[x2-x1]*[x2-x1] + [y2-y1]*[y2-y1]]
distance.append[[ID,dist]]
min_dist.append[min[distance]]
del distance[:]
Cho một mảng chưa được phân loại ARR [] và hai số X và Y, tìm khoảng cách tối thiểu giữa X và Y trong ARR []. Mảng cũng có thể chứa các bản sao. Bạn có thể cho rằng cả X và Y đều khác nhau và hiện diện trong ARR [].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. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1
Phương pháp 1: & NBSP;
- Cách tiếp cận: Nhiệm vụ là tìm khoảng cách giữa hai số đã cho, vì vậy hãy tìm khoảng cách giữa bất kỳ hai phần tử nào bằng cách sử dụng các vòng lặp lồng nhau. Vòng ngoài để chọn phần tử đầu tiên [x] và vòng bên trong để đi qua mảng trong tìm kiếm phần tử khác [y] và lấy khoảng cách tối thiểu giữa chúng. The task is to find the distance between two given numbers, So find the distance between any two elements using nested loops. The outer loop for selecting the first element [x] and the inner loop for traversing the array in search for the other element [y] and taking the minimum distance between them.
- Algorithm:
- Tạo một biến M = int_max
- Chạy một vòng lặp lồng nhau, vòng ngoài chạy từ đầu đến cuối [Bộ đếm vòng I], vòng bên trong chạy từ I+1 đến cuối [Bộ đếm vòng lặp J].
- Nếu phần tử ith là phần tử x và jth là y hoặc ngược lại, hãy cập nhật m là m = min [m, j-i]
- In giá trị của M là khoảng cách tối thiểu
- Implementation:
C++
#include
using
namespace
std;
int
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 10
int
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 12
int
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 14
int
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 16__
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 19
Minimum distance between 3 and 6 is 40____9
Minimum distance between 3 and 6 is 42
Minimum distance between 3 and 6 is 40____9
Minimum distance between 3 and 6 is 45
Minimum distance between 3 and 6 is 40
Minimum distance between 3 and 6 is 47
Minimum distance between 3 and 6 is 48
Minimum distance between 3 and 6 is 49
Minimum distance between 3 and 6 is 47
Minimum distance between 3 and 6 is 11
Minimum distance between 3 and 6 is 12
Minimum distance between 3 and 6 is 13
Minimum distance between 3 and 6 is 14
Minimum distance between 3 and 6 is 15
Minimum distance between 3 and 6 is 16
Minimum distance between 3 and 6 is 17
Minimum distance between 3 and 6 is 18
Minimum distance between 3 and 6 is 19
Minimum distance between 3 and 6 is 40
Minimum distance between 3 and 6 is 17
Minimum distance between 3 and 6 is 42
Minimum distance between 3 and 6 is 19
Minimum distance between 3 and 6 is 44
Minimum distance between 3 and 6 is 12
Minimum distance between 3 and 6 is 46
Minimum distance between 3 and 6 is 49
Minimum distance between 3 and 6 is 46
Minimum distance between 3 and 6 is 40
Minimum distance between 3 and 6 is 46
Minimum distance between 3 and 6 is 40
Minimum distance between 3 and 6 is 13
#include
3Minimum distance between 3 and 6 is 49
#include
5 #include
6Minimum distance between 3 and 6 is 40
Minimum distance between 3 and 6 is 46
Minimum distance between 3 and 6 is 40
#include
5 using
1Minimum distance between 3 and 6 is 46
int
using
4
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 19
Minimum distance between 3 and 6 is 40____9
using
8Minimum distance between 3 and 6 is 40____9
namespace
1namespace
2namespace
3__72Minimum distance between 3 and 6 is 40____9
namespace
8Minimum distance between 3 and 6 is 40____9
std;
1Minimum distance between 3 and 6 is 40
std;
3std;
4 std;
5std;
6 std;
7std;
8std;
9int
0 int
1
Minimum distance between 3 and 6 is 46
C
int
3
int
4
int
5
int
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 10
int
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 12
int
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 14
int
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 16__
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 19
Minimum distance between 3 and 6 is 40____9
Minimum distance between 3 and 6 is 42
Minimum distance between 3 and 6 is 40____9
Minimum distance between 3 and 6 is 45
Minimum distance between 3 and 6 is 40
Minimum distance between 3 and 6 is 47
Minimum distance between 3 and 6 is 48
Minimum distance between 3 and 6 is 49
Minimum distance between 3 and 6 is 47
Minimum distance between 3 and 6 is 11
Minimum distance between 3 and 6 is 12
Minimum distance between 3 and 6 is 13
Minimum distance between 3 and 6 is 14
Minimum distance between 3 and 6 is 15
Minimum distance between 3 and 6 is 16
Minimum distance between 3 and 6 is 17
Minimum distance between 3 and 6 is 18
Minimum distance between 3 and 6 is 19
Minimum distance between 3 and 6 is 40
Minimum distance between 3 and 6 is 17
Minimum distance between 3 and 6 is 42
Minimum distance between 3 and 6 is 19
Minimum distance between 3 and 6 is 44
Minimum distance between 3 and 6 is 12
Minimum distance between 3 and 6 is 46
Minimum distance between 3 and 6 is 49
Minimum distance between 3 and 6 is 46
Minimum distance between 3 and 6 is 40
Minimum distance between 3 and 6 is 46
Minimum distance between 3 and 6 is 40
Minimum distance between 3 and 6 is 13
#include
3Minimum distance between 3 and 6 is 49
#include
5 #include
6Minimum distance between 3 and 6 is 40
Minimum distance between 3 and 6 is 46
Minimum distance between 3 and 6 is 40
#include
5 using
1Minimum distance between 3 and 6 is 46
int
using
4
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 19
Minimum distance between 3 and 6 is 40____9
using
8Minimum distance between 3 and 6 is 40____9
namespace
1namespace
2namespace
3__72Minimum distance between 3 and 6 is 40____9
namespace
8Minimum distance between 3 and 6 is 40____9
std;
1Minimum distance between 3 and 6 is 40
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 170
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 171
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 172
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 173
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 174
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 175
Minimum distance between 3 and 6 is 40
std;
3std;
4 std;
5std;
6 std;
7Minimum distance between 3 and 6 is 46
std;
8std;
9int
0 int
1
C
Minimum distance between 3 and 6 is 40____9
Minimum distance between 3 and 6 is 45
Minimum distance between 3 and 6 is 40
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 19
Minimum distance between 3 and 6 is 40____9
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 165
Minimum distance between 3 and 6 is 40
#include
5 Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 178
Java
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 180
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 181
Minimum distance between 3 and 6 is 40
int
____1010____9 Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 12
int
Minimum distance between 3 and 6 is 414
Minimum distance between 3 and 6 is 16
Minimum distance between 3 and 6 is 416
Minimum distance between 3 and 6 is 417
Minimum distance between 3 and 6 is 416
Minimum distance between 3 and 6 is 419
Minimum distance between 3 and 6 is 12
Minimum distance between 3 and 6 is 46
Minimum distance between 3 and 6 is 49
Minimum distance between 3 and 6 is 46
Minimum distance between 3 and 6 is 49
Minimum distance between 3 and 6 is 13
#include
3Minimum distance between 3 and 6 is 12
#include
5 Minimum distance between 3 and 6 is 429
Minimum distance between 3 and 6 is 409
Minimum distance between 3 and 6 is 431
Minimum distance between 3 and 6 is 49
Minimum distance between 3 and 6 is 46
Minimum distance between 3 and 6 is 49
#include
5 using
1Minimum distance between 3 and 6 is 40
Minimum distance between 3 and 6 is 46
Minimum distance between 3 and 6 is 40
Minimum distance between 3 and 6 is 440
Minimum distance between 3 and 6 is 441
Minimum distance between 3 and 6 is 442
Minimum distance between 3 and 6 is 443
Minimum distance between 3 and 6 is 40
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 19
Minimum distance between 3 and 6 is 49
Minimum distance between 3 and 6 is 447
Minimum distance between 3 and 6 is 448
Minimum distance between 3 and 6 is 449
E
Minimum distance between 3 and 6 is 49
int
Minimum distance between 3 and 6 is 479
Minimum distance between 3 and 6 is 49
int
Minimum distance between 3 and 6 is 482
Minimum distance between 3 and 6 is 404
Minimum distance between 3 and 6 is 431
Minimum distance between 3 and 6 is 49
int
Minimum distance between 3 and 6 is 487
Minimum distance between 3 and 6 is 461
Minimum distance between 3 and 6 is 431
Minimum distance between 3 and 6 is 49
Minimum distance between 3 and 6 is 491
std;
4 Minimum distance between 3 and 6 is 493
Minimum distance between 3 and 6 is 494
Minimum distance between 3 and 6 is 495
std;
6 Minimum distance between 3 and 6 is 497
int
0Minimum distance between 3 and 6 is 494
Minimum distance between 3 and 6 is 100
Minimum distance between 3 and 6 is 40
Minimum distance between 3 and 6 is 46
Minimum distance between 3 and 6 is 46
Python3
Minimum distance between 3 and 6 is 104
Minimum distance between 3 and 6 is 105
Minimum distance between 3 and 6 is 40
Minimum distance between 3 and 6 is 107
Minimum distance between 3 and 6 is 108
Minimum distance between 3 and 6 is 109
Minimum distance between 3 and 6 is 40
Minimum distance between 3 and 6 is 47
Minimum distance between 3 and 6 is 112.
Minimum distance between 3 and 6 is 49
Minimum distance between 3 and 6 is 47
Minimum distance between 3 and 6 is 118
Minimum distance between 3 and 6 is 113
Minimum distance between 3 and 6 is 114
Minimum distance between 3 and 6 is 121
Minimum distance between 3 and 6 is 122
Minimum distance between 3 and 6 is 409__
Minimum distance between 3 and 6 is 12
Minimum distance between 3 and 6 is 13
Minimum distance between 3 and 6 is 127
Minimum distance between 3 and 6 is 108
Minimum distance between 3 and 6 is 108
Minimum distance between 3 and 6 is 130
Minimum distance between 3 and 6 is 131
Minimum distance between 3 and 6 is 416
Minimum distance between 3 and 6 is 132
Minimum distance between 3 and 6 is 108
Minimum distance between 3 and 6 is 108
Minimum distance between 3 and 6 is 17____
Minimum distance between 3 and 6 is 107
Minimum distance between 3 and 6 is 108
Minimum distance between 3 and 6 is 19
Minimum distance between 3 and 6 is 150
Minimum distance between 3 and 6 is 429
Minimum distance between 3 and 6 is 159
Minimum distance between 3 and 6 is 49
#include
5 Minimum distance between 3 and 6 is 162
Minimum distance between 3 and 6 is 163
Minimum distance between 3 and 6 is 108
Minimum distance between 3 and 6 is 165
Minimum distance between 3 and 6 is 453__
Minimum distance between 3 and 6 is 190
Minimum distance between 3 and 6 is 108
Minimum distance between 3 and 6 is 192
Minimum distance between 3 and 6 is 193
Minimum distance between 3 and 6 is 143
Minimum distance between 3 and 6 is 108
Minimum distance between 3 and 6 is 453
Minimum distance between 3 and 6 is 132
Minimum distance between 3 and 6 is 108
Minimum distance between 3 and 6 is 461
Minimum distance between 3 and 6 is 400
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 171
std;
4Minimum distance between 3 and 6 is 403
std;
6Minimum distance between 3 and 6 is 405
Minimum distance between 3 and 6 is 406
Minimum distance between 3 and 6 is 407
Minimum distance between 3 and 6 is 408
Minimum distance between 3 and 6 is 409
C#
using
Minimum distance between 3 and 6 is 411
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 180
Minimum distance between 3 and 6 is 413
Minimum distance between 3 and 6 is 40
Minimum distance between 3 and 6 is 441
int
Minimum distance between 3 and 6 is 494
int
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 16
int
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 18
Minimum distance between 3 and 6 is 40
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 19
Minimum distance between 3 and 6 is 49
int
Minimum distance between 3 and 6 is 42
Minimum distance between 3 and 6 is 49
int
Minimum distance between 3 and 6 is 42
int
Minimum distance between 3 and 6 is 436
Minimum distance between 3 and 6 is 49
Minimum distance between 3 and 6 is 47
Minimum distance between 3 and 6 is 439
Minimum distance between 3 and 6 is 49
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 19
Minimum distance between 3 and 6 is 12
Minimum distance between 3 and 6 is 47
Minimum distance between 3 and 6 is 444
Minimum distance between 3 and 6 is 12
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 19
Minimum distance between 3 and 6 is 17
Minimum distance between 3 and 6 is 13
Minimum distance between 3 and 6 is 449
Minimum distance between 3 and 6 is 414
Minimum distance between 3 and 6 is 451
Minimum distance between 3 and 6 is 414
Minimum distance between 3 and 6 is 453
Minimum distance between 3 and 6 is 454
Minimum distance between 3 and 6 is 455
Minimum distance between 3 and 6 is 416
Minimum distance between 3 and 6 is 457
Minimum distance between 3 and 6 is 458
Minimum distance between 3 and 6 is 459
Minimum distance between 3 and 6 is 416
Minimum distance between 3 and 6 is 461
Minimum distance between 3 and 6 is 416
Minimum distance between 3 and 6 is 463
Minimum distance between 3 and 6 is 12
Minimum distance between 3 and 6 is 46
Minimum distance between 3 and 6 is 49
Minimum distance between 3 and 6 is 46
Minimum distance between 3 and 6 is 49
#include
5 using
1Minimum distance between 3 and 6 is 40
Minimum distance between 3 and 6 is 46
Minimum distance between 3 and 6 is 40
Minimum distance between 3 and 6 is 440
Minimum distance between 3 and 6 is 441
Minimum distance between 3 and 6 is 442
Minimum distance between 3 and 6 is 477
Minimum distance between 3 and 6 is 40
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 19
Minimum distance between 3 and 6 is 49
int
Minimum distance between 3 and 6 is 482
Minimum distance between 3 and 6 is 483
Minimum distance between 3 and 6 is 484
Minimum distance between 3 and 6 is 49
int
Minimum distance between 3 and 6 is 487
Minimum distance between 3 and 6 is 49____9
namespace
8Minimum distance between 3 and 6 is 49____9
std;
1Minimum distance between 3 and 6 is 49
Minimum distance between 3 and 6 is 495
Minimum distance between 3 and 6 is 496
Minimum distance between 3 and 6 is 497
Minimum distance between 3 and 6 is 495
Minimum distance between 3 and 6 is 499
std;
8#include
01std;
6
Minimum distance between 3 and 6 is 497
int
0Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 174
#include
06Minimum distance between 3 and 6 is 40
Minimum distance between 3 and 6 is 46
Minimum distance between 3 and 6 is 46
PHP
#include
10
Is
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 19
Minimum distance between 3 and 6 is 40
#include
23#include
24#include
25Minimum distance between 3 and 6 is 431
Minimum distance between 3 and 6 is 40
#include
28 #include
29Minimum distance between 3 and 6 is 40
Minimum distance between 3 and 6 is 47
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 171
#include
23Minimum distance between 3 and 6 is 40
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 19
Minimum distance between 3 and 6 is 49
Minimum distance between 3 and 6 is 47
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 171
#include
25Minimum distance between 3 and 6 is 49
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 19
Minimum distance between 3 and 6 is 12
Minimum distance between 3 and 6 is 13
#include
60__517Is
Các
Minimum distance between 3 and 6 is 12
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 19
Các
Minimum distance between 3 and 6 is 12
Minimum distance between 3 and 6 is 46
Minimum distance between 3 and 6 is 49
Minimum distance between 3 and 6 is 46
Minimum distance between 3 and 6 is 40
Minimum distance between 3 and 6 is 46
using
16
Minimum distance between 3 and 6 is 13
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 171
#include
28using
20#include
15#include
20Minimum distance between 3 and 6 is 406
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 19
Minimum distance between 3 and 6 is 49
#include
5 #include
6Minimum distance between 3 and 6 is 406
Minimum distance between 3 and 6 is 46
Minimum distance between 3 and 6 is 40
#include
5 #include
28Minimum distance between 3 and 6 is 431
Minimum distance between 3 and 6 is 46
Minimum distance between 3 and 6 is 40
#include
13 #include
47using
38using
39Minimum distance between 3 and 6 is 40
#include
15 #include
47using
43Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 171
#include
13using
09Minimum distance between 3 and 6 is 40
#include
17 using
49Minimum distance between 3 and 6 is 40
#include
19 using
52Minimum distance between 3 and 6 is 40
using
54 std;
4Minimum distance between 3 and 6 is 405
#include
17____254std;
6Minimum distance between 3 and 6 is 405
#include
19Minimum distance between 3 and 6 is 405
import math as m
test = [[1, 2,3], [2, 5,2],[3,6,8]]
points = [[1, 2,3],[2,5,2],[3,6,8]]
distance = []
min_dist = []
for i in test:
x1 = i[1]
y1 = i[2]
print i
for j in points:
x2 = j[1]
y2 = j[2]
ID = j[0]
print j
dist = m.sqrt[[x2-x1]*[x2-x1] + [y2-y1]*[y2-y1]]
distance.append[[ID,dist]]
min_dist.append[min[distance]]
del distance[:]
____Minimum distance between 3 and 6 is 431
Minimum distance between 3 and 6 is 40
using
54 Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 10
#include
13Minimum distance between 3 and 6 is 454
#include
15Minimum distance between 3 and 6 is 454
#include
17Minimum distance between 3 and 6 is 454__
using
76
JavaScript
using
77
#include
11 using
79
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 19
Minimum distance between 3 and 6 is 40
using
82 Minimum distance between 3 and 6 is 42
Minimum distance between 3 and 6 is 40
using
82 using
86Minimum distance between 3 and 6 is 40
Minimum distance between 3 and 6 is 47
Minimum distance between 3 and 6 is 439
Minimum distance between 3 and 6 is 40
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 19
Minimum distance between 3 and 6 is 49
Minimum distance between 3 and 6 is 47
Minimum distance between 3 and 6 is 444
Minimum distance between 3 and 6 is 49
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 19
Minimum distance between 3 and 6 is 12
Minimum distance between 3 and 6 is 13
using
99Minimum distance between 3 and 6 is 15
namespace
01Minimum distance between 3 and 6 is 15
namespace
03Minimum distance between 3 and 6 is 17
Minimum distance between 3 and 6 is 419
Minimum distance between 3 and 6 is 49
Minimum distance between 3 and 6 is 46
Minimum distance between 3 and 6 is 40
Minimum distance between 3 and 6 is 46
Minimum distance between 3 and 6 is 40
Minimum distance between 3 and 6 is 13
namespace
12Minimum distance between 3 and 6 is 406
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 19
Minimum distance between 3 and 6 is 49
#include
5 #include
6Minimum distance between 3 and 6 is 406
Minimum distance between 3 and 6 is 46
Minimum distance between 3 and 6 is 40
#include
5 using
1Minimum distance between 3 and 6 is 46
using
82 namespace
25
Minimum distance between 3 and 6 is 12
namespace
27using
82
Minimum distance between 3 and 6 is 479
using
82 namespace
8
using
82 std;
1
namespace
34std;
4 namespace
36
Minimum distance between 3 and 6 is 497
std;
6 Minimum distance between 3 and 6 is 497
int
0 Minimum distance between 3 and 6 is 122
Minimum distance between 3 and 6 is 497
namespace
43namespace
44
Đầu ra
Minimum distance between 3 and 6 is 4
- Phân tích độ phức tạp: & NBSP;
- Độ phức tạp về thời gian: O [n^2], vòng lặp lồng nhau được sử dụng để đi qua mảng. O[n^2], Nested loop is used to traverse the array.
- Độ phức tạp không gian: O [1], không cần thêm không gian. O[1], no extra space is required.
Phương pháp 2: & NBSP;
- Cách tiếp cận: Vì vậy, cách tiếp cận cơ bản là chỉ kiểm tra các cặp x và y liên tiếp. Đối với mỗi phần tử X hoặc Y, hãy kiểm tra chỉ số của sự xuất hiện trước đó của X hoặc Y và nếu phần tử xảy ra trước đó không giống với phần tử hiện tại Cập nhật khoảng cách tối thiểu. Nhưng một câu hỏi đặt ra nếu một X được đặt trước bởi X khác và điều đó được đi trước bởi Y, thì làm thế nào để có được khoảng cách tối thiểu giữa các cặp. Bằng cách phân tích chặt chẽ, có thể thấy rằng mỗi X theo sau là Y hoặc ngược lại chỉ có thể là cặp gần nhất [khoảng cách tối thiểu], vì vậy hãy bỏ qua tất cả các cặp khác. So the basic approach is to check only consecutive pairs of x and y. For every element x or y, check the index of the previous occurrence of x or y and if the previous occurring element is not similar to current element update the minimum distance. But a question arises what if an x is preceded by another x and that is preceded by a y, then how to get the minimum distance between pairs. By analyzing closely it can be seen that every x followed by a y or vice versa can only be the closest pair [minimum distance] so ignore all other pairs.
- Algorithm:
- Tạo một biến trước = -1 và m = int_max
- Đi qua mảng từ đầu đến cuối.
- Nếu phần tử hiện tại là x hoặc y, trước không bằng -1 và mảng [trước] không bằng phần tử hiện tại thì cập nhật m = max [current_index -pre, m], tức là tìm khoảng cách giữa các cặp liên tiếp và cập nhật m với nó.
- in giá trị của m
- Cảm ơn WGPSHASHANK đã đề xuất phương pháp này.
- Implementation.
C++
#include
using
namespace
std;
int
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 10
int
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 12
int
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 14
int
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 16__
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 19
Minimum distance between 3 and 6 is 40____9
namespace
62Minimum distance between 3 and 6 is 40
Minimum distance between 3 and 6 is 47
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 171
int
namespace
67Minimum distance between 3 and 6 is 40
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 19
Minimum distance between 3 and 6 is 49
Minimum distance between 3 and 6 is 13
namespace
72Minimum distance between 3 and 6 is 49
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 19
Minimum distance between 3 and 6 is 12
Minimum distance between 3 and 6 is 13
namespace
77Minimum distance between 3 and 6 is 17
namespace
79Minimum distance between 3 and 6 is 12
namespace
81Minimum distance between 3 and 6 is 49
Minimum distance between 3 and 6 is 46
Minimum distance between 3 and 6 is 40
Minimum distance between 3 and 6 is 46
Minimum distance between 3 and 6 is 40
Minimum distance between 3 and 6 is 13
namespace
88Minimum distance between 3 and 6 is 49
#include
5 #include
6Minimum distance between 3 and 6 is 40
#include
5 using
1Minimum distance between 3 and 6 is 46
Minimum distance between 3 and 6 is 46
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 19
using
82 namespace
25
using
82
Minimum distance between 3 and 6 is 479
using
82 namespace
8
using
82 std;
1
namespace
34std;
4 namespace
36
Minimum distance between 3 and 6 is 497
std;
6 Minimum distance between 3 and 6 is 497
int
0 Minimum distance between 3 and 6 is 122
std;
19std;
25
Đầu ra
Minimum distance between 3 and 6 is 46
Phân tích độ phức tạp: & NBSP;
int
4
std;
31
Độ phức tạp về thời gian: O [n^2], vòng lặp lồng nhau được sử dụng để đi qua mảng.
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 19
Minimum distance between 3 and 6 is 40
Minimum distance between 3 and 6 is 13
std;
41Độ phức tạp không gian: O [1], không cần thêm không gian.
Phương pháp 2: & NBSP;
Minimum distance between 3 and 6 is 46
int
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 10
int
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 12
int
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 14
int
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 16__
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 19
Minimum distance between 3 and 6 is 40____9
namespace
62Minimum distance between 3 and 6 is 40
Minimum distance between 3 and 6 is 47
std;
65Minimum distance between 3 and 6 is 40
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 19
Minimum distance between 3 and 6 is 49
Minimum distance between 3 and 6 is 13
std;
70Minimum distance between 3 and 6 is 49
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 19
Minimum distance between 3 and 6 is 12
Minimum distance between 3 and 6 is 13
std;
75Minimum distance between 3 and 6 is 17
std;
77Minimum distance between 3 and 6 is 12
namespace
81Minimum distance between 3 and 6 is 49
Minimum distance between 3 and 6 is 46
Minimum distance between 3 and 6 is 40
Minimum distance between 3 and 6 is 46
Minimum distance between 3 and 6 is 40
Minimum distance between 3 and 6 is 13
namespace
88Minimum distance between 3 and 6 is 40
Minimum distance between 3 and 6 is 47
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 171
int
namespace
67Minimum distance between 3 and 6 is 40
#include
5 using
1
Minimum distance between 3 and 6 is 46
Minimum distance between 3 and 6 is 46
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 19
using
82 namespace
25
using
82
Minimum distance between 3 and 6 is 479
using
82 namespace
8
using
82 std;
1
Minimum distance between 3 and 6 is 40
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 170
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 171
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 172
int
17Minimum distance between 3 and 6 is 12
namespace
43Đầu ra
Minimum distance between 3 and 6 is 46
Phân tích độ phức tạp: & NBSP;
Độ phức tạp về thời gian: O [n^2], vòng lặp lồng nhau được sử dụng để đi qua mảng.
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 19
Độ phức tạp không gian: O [1], không cần thêm không gian.
Minimum distance between 3 and 6 is 40
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 19
Phương pháp 2: & NBSP;
Cách tiếp cận: Vì vậy, cách tiếp cận cơ bản là chỉ kiểm tra các cặp x và y liên tiếp. Đối với mỗi phần tử X hoặc Y, hãy kiểm tra chỉ số của sự xuất hiện trước đó của X hoặc Y và nếu phần tử xảy ra trước đó không giống với phần tử hiện tại Cập nhật khoảng cách tối thiểu. Nhưng một câu hỏi đặt ra nếu một X được đặt trước bởi X khác và điều đó được đi trước bởi Y, thì làm thế nào để có được khoảng cách tối thiểu giữa các cặp. Bằng cách phân tích chặt chẽ, có thể thấy rằng mỗi X theo sau là Y hoặc ngược lại chỉ có thể là cặp gần nhất [khoảng cách tối thiểu], vì vậy hãy bỏ qua tất cả các cặp khác.
Minimum distance between 3 and 6 is 40
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 19
Minimum distance between 3 and 6 is 49
Minimum distance between 3 and 6 is 13
std;
70Minimum distance between 3 and 6 is 49
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 19
Tạo một biến trước = -1 và m = int_max
Minimum distance between 3 and 6 is 17
int
65Minimum distance between 3 and 6 is 12
namespace
81Minimum distance between 3 and 6 is 49
Minimum distance between 3 and 6 is 46
Minimum distance between 3 and 6 is 40
Minimum distance between 3 and 6 is 46
Minimum distance between 3 and 6 is 40
Minimum distance between 3 and 6 is 13
int
74std;
87#include
5
Minimum distance between 3 and 6 is 429
Minimum distance between 3 and 6 is 409
Minimum distance between 3 and 6 is 431
Minimum distance between 3 and 6 is 40
#include
5 using
1Minimum distance between 3 and 6 is 46
Minimum distance between 3 and 6 is 40
Minimum distance between 3 and 6 is 440
Minimum distance between 3 and 6 is 441
Minimum distance between 3 and 6 is 442
int
88Minimum distance between 3 and 6 is 49
Minimum distance between 3 and 6 is 447
Minimum distance between 3 and 6 is 448
Minimum distance between 3 and 6 is 449
Các
Minimum distance between 3 and 6 is 49
int
Minimum distance between 3 and 6 is 479
Minimum distance between 3 and 6 is 49
int
Minimum distance between 3 and 6 is 482
Minimum distance between 3 and 6 is 453
Minimum distance between 3 and 6 is 431
Minimum distance between 3 and 6 is 49
int
Minimum distance between 3 and 6 is 487
Minimum distance between 3 and 6 is 461
Minimum distance between 3 and 6 is 431
Minimum distance between 3 and 6 is 49
Minimum distance between 3 and 6 is 491
std;
4 Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1036
std;
6 Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1038
Minimum distance between 3 and 6 is 17
Minimum distance between 3 and 6 is 495
int
0 Minimum distance between 3 and 6 is 100
Minimum distance between 3 and 6 is 40
Minimum distance between 3 and 6 is 46
Minimum distance between 3 and 6 is 46
Python3
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1046
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1047
Minimum distance between 3 and 6 is 104
Minimum distance between 3 and 6 is 105
Minimum distance between 3 and 6 is 40
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1051
Minimum distance between 3 and 6 is 108
Minimum distance between 3 and 6 is 404
Minimum distance between 3 and 6 is 40
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1055
Minimum distance between 3 and 6 is 108
Minimum distance between 3 and 6 is 429
Minimum distance between 3 and 6 is 409
Minimum distance between 3 and 6 is 40
Minimum distance between 3 and 6 is 107
Minimum distance between 3 and 6 is 108
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1062
Minimum distance between 3 and 6 is 40
Minimum distance between 3 and 6 is 47
Minimum distance between 3 and 6 is 112.
Các
Minimum distance between 3 and 6 is 12
Minimum distance between 3 and 6 is 13
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1082
Minimum distance between 3 and 6 is 108
Các
Minimum distance between 3 and 6 is 12
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1055
Minimum distance between 3 and 6 is 108
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1051
Minimum distance between 3 and 6 is 40
Minimum distance between 3 and 6 is 13
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1103
Minimum distance between 3 and 6 is 108
Minimum distance between 3 and 6 is 108
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1106
std;
87#include
5
Minimum distance between 3 and 6 is 429
Minimum distance between 3 and 6 is 409
Minimum distance between 3 and 6 is 40
#include
5 Minimum distance between 3 and 6 is 162
Các
Minimum distance between 3 and 6 is 190
Minimum distance between 3 and 6 is 108
Minimum distance between 3 and 6 is 192
Minimum distance between 3 and 6 is 193
Minimum distance between 3 and 6 is 143
Minimum distance between 3 and 6 is 108
Minimum distance between 3 and 6 is 453
Minimum distance between 3 and 6 is 132
Minimum distance between 3 and 6 is 108
Minimum distance between 3 and 6 is 461
Minimum distance between 3 and 6 is 400
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 171
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 172
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1154
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1155
C#
using
Minimum distance between 3 and 6 is 411
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 180
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 181
Minimum distance between 3 and 6 is 40
Minimum distance between 3 and 6 is 441
int
Minimum distance between 3 and 6 is 454
int
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 16
int
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 18
Minimum distance between 3 and 6 is 40
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 19
Minimum distance between 3 and 6 is 40____9
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 11777____9____
Minimum distance between 3 and 6 is 436
Minimum distance between 3 and 6 is 40
Minimum distance between 3 and 6 is 47
std;
65Minimum distance between 3 and 6 is 40
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 19
Minimum distance between 3 and 6 is 49
Minimum distance between 3 and 6 is 13
std;
70Minimum distance between 3 and 6 is 49
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 19
Minimum distance between 3 and 6 is 12
Minimum distance between 3 and 6 is 13
std;
75Minimum distance between 3 and 6 is 17
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1194
Minimum distance between 3 and 6 is 12
namespace
81Minimum distance between 3 and 6 is 49
Minimum distance between 3 and 6 is 46
Minimum distance between 3 and 6 is 40
Minimum distance between 3 and 6 is 46
Minimum distance between 3 and 6 is 40
Minimum distance between 3 and 6 is 13
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1203
int
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1205
std;
87#include
5 #include
6
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1209
#include
5 using
1Minimum distance between 3 and 6 is 46
Minimum distance between 3 and 6 is 40
Minimum distance between 3 and 6 is 440
Minimum distance between 3 and 6 is 441
Minimum distance between 3 and 6 is 442
Minimum distance between 3 and 6 is 477
Minimum distance between 3 and 6 is 40
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 19
Minimum distance between 3 and 6 is 49
int
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1222
Minimum distance between 3 and 6 is 414
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1224
Minimum distance between 3 and 6 is 49
int
Minimum distance between 3 and 6 is 487
Minimum distance between 3 and 6 is 49____9
namespace
8Minimum distance between 3 and 6 is 49____9
std;
1Minimum distance between 3 and 6 is 49
Minimum distance between 3 and 6 is 495
std;
4 Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1036
std;
6 Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1038
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1240
Minimum distance between 3 and 6 is 495
int
0 #include
06Minimum distance between 3 and 6 is 40
Minimum distance between 3 and 6 is 46
Minimum distance between 3 and 6 is 46
PHP
#include
10
Is
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 19
Minimum distance between 3 and 6 is 40
#include
23Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1261
Minimum distance between 3 and 6 is 40
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1263
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1264
Minimum distance between 3 and 6 is 40
#include
28Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1267
Các
Minimum distance between 3 and 6 is 40
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 19
Các
Minimum distance between 3 and 6 is 49
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 19
Các
Các
Minimum distance between 3 and 6 is 12
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1263
Minimum distance between 3 and 6 is 108
#include
23Minimum distance between 3 and 6 is 431
Minimum distance between 3 and 6 is 49
Minimum distance between 3 and 6 is 46
Minimum distance between 3 and 6 is 40
Minimum distance between 3 and 6 is 46
Minimum distance between 3 and 6 is 40
Minimum distance between 3 and 6 is 13
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 171
#include
28Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1333
std;
87#include
5 #include
6
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1209
#include
5 using
1Minimum distance between 3 and 6 is 40
Minimum distance between 3 and 6 is 440
Minimum distance between 3 and 6 is 441
Minimum distance between 3 and 6 is 442
Minimum distance between 3 and 6 is 477
Minimum distance between 3 and 6 is 49
int
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1222
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1347
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1348
Minimum distance between 3 and 6 is 49
int
Minimum distance between 3 and 6 is 487
Minimum distance between 3 and 6 is 49____9
namespace
8Minimum distance between 3 and 6 is 49____9
std;
1Minimum distance between 3 and 6 is 49
Minimum distance between 3 and 6 is 495
std;
4 Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1036
std;
6 Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1038
std;
8
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1367
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1368
#include
13Minimum distance between 3 and 6 is 454
#include
15Minimum distance between 3 and 6 is 454
#include
17Minimum distance between 3 and 6 is 454
#include
19using
09using
76
JavaScript
using
77
#include
11
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1380
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 19
Minimum distance between 3 and 6 is 40
using
82 Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1384
Minimum distance between 3 and 6 is 40
Minimum distance between 3 and 6 is 47
std;
65Minimum distance between 3 and 6 is 40
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 19
Minimum distance between 3 and 6 is 49
Minimum distance between 3 and 6 is 13
std;
70Minimum distance between 3 and 6 is 49
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 19
Minimum distance between 3 and 6 is 49
Minimum distance between 3 and 6 is 13
std;
75Minimum distance between 3 and 6 is 12
int
65Minimum distance between 3 and 6 is 12
namespace
81Minimum distance between 3 and 6 is 49
Minimum distance between 3 and 6 is 46
Minimum distance between 3 and 6 is 40
Minimum distance between 3 and 6 is 46
Minimum distance between 3 and 6 is 40
Minimum distance between 3 and 6 is 13
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1408
std;
87#include
5 #include
6
Minimum distance between 3 and 6 is 40
#include
5 using
1Minimum distance between 3 and 6 is 46
Minimum distance between 3 and 6 is 40
using
82 Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1418
Minimum distance between 3 and 6 is 40
using
82 Minimum distance between 3 and 6 is 479
Minimum distance between 3 and 6 is 40
using
82 namespace
8Minimum distance between 3 and 6 is 40
using
82 std;
1Minimum distance between 3 and 6 is 40
namespace
34std;
4 Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1036
std;
6 Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1038
Minimum distance between 3 and 6 is 12
Minimum distance between 3 and 6 is 495
int
0 #include
06namespace
44
Đầu ra
Minimum distance between 3 and 6 is 1
- Phân tích độ phức tạp:
- Độ phức tạp về thời gian: O [n]. & Nbsp; chỉ cần một lần đi ngang của mảng. O[n].
Only one traversal of the array is needed. - Độ phức tạp không gian: O [1]. & NBSP; vì không cần thêm không gian. & NBSP; O[1].
As no extra space is required.
Phương pháp 3:
- Cách tiếp cận: & nbsp; Vấn đề nói rằng chúng tôi muốn khoảng cách tối thiểu giữa x và y. Vì vậy, cách tiếp cận là đi qua mảng và trong khi đi qua mảng nếu chúng ta có số là x hoặc y thì chúng ta sẽ lưu trữ sự khác biệt giữa các chỉ số của trước đây X hoặc Y và mới tìm thấy X hoặc Y và như thế này cho mỗi lần chúng ta sẽ thử để giảm thiểu sự khác biệt.: The problem says that we want a minimum distance between x and y. So the approach is traverse the array and while traversing in array if we got the number as x or y then we will store the difference between indices of previously found x or y and newly find x or y and like this for every time we will try to minimize the difference.
- Algorithm: :
- & nbsp; & nbsp; tạo các biến idx1 = -1, idx2 = -1 và min_dist = int_max;
- & nbsp; & nbsp; đi qua mảng từ i = 0 đến i = n-1 trong đó n là kích thước của mảng.
- & nbsp; & nbsp; trong khi đi qua nếu phần tử hiện tại là x thì lưu trữ chỉ mục của phần tử hiện tại trong IDX1 hoặc nếu hiện tại & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; phần tử là y sau đó lưu trữ chỉ mục của phần tử hiện tại trong IDX2.
- & nbsp; & nbsp; nếu biến IDX1 và IDX2 không bằng -1 sau đó lưu trữ tối thiểu của min_dist, sự khác biệt của idx1 và idx2 vào & nbsp; & nbsp; Ans.
- & nbsp; & nbsp; ở cuối đường truyền, nếu IDX1 hoặc IDX2 vẫn còn -1 [x hoặc y không tìm thấy trong mảng] thì hãy trả về -1 hoặc khác trả về & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; min_dist.
- Implementation:
C++
#include
using
namespace
std;
int
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 10
int
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 12
int
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 14
int
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 16__
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 19
Minimum distance between 3 and 6 is 40____9
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1456
Minimum distance between 3 and 6 is 40
Minimum distance between 3 and 6 is 47
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 171
int
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1461
Minimum distance between 3 and 6 is 40
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 19
std;
87
Minimum distance between 3 and 6 is 13
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1466
std;
87
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 19
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1469
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1470
std;
87
Minimum distance between 3 and 6 is 46
std;
87
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1474
Minimum distance between 3 and 6 is 13
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1476
std;
87
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 19
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1469
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1480
std;
87
Minimum distance between 3 and 6 is 46
std;
87
Minimum distance between 3 and 6 is 13
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1485
std;
87
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1487
Minimum distance between 3 and 6 is 19
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1489
Minimum distance between 3 and 6 is 40
Minimum distance between 3 and 6 is 46
Minimum distance between 3 and 6 is 40
Minimum distance between 3 and 6 is 13
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1494
Minimum distance between 3 and 6 is 40
#include
5 #include
6Minimum distance between 3 and 6 is 40
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1474
Minimum distance between 3 and 6 is 40
#include
5 using
1Minimum distance between 3 and 6 is 46
Minimum distance between 3 and 6 is 40
using
82 Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1418
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 19
Minimum distance between 3 and 6 is 40
using
82 Minimum distance between 3 and 6 is 479
Minimum distance between 3 and 6 is 40
using
82 namespace
8Minimum distance between 3 and 6 is 40
using
82 std;
1Minimum distance between 3 and 6 is 40
namespace
34std;
4 Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1036
std;
6 Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1038
Minimum distance between 3 and 6 is 12
Minimum distance between 3 and 6 is 495
int
0 #include
06Đầu ra
Minimum distance between 3 and 6 is 46
Phân tích độ phức tạp:
Độ phức tạp về thời gian: O [n]. & Nbsp; chỉ cần một lần đi ngang của mảng.
Độ phức tạp không gian: O [1]. & NBSP; vì không cần thêm không gian. & NBSP;
Minimum distance between 3 and 6 is 40
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 19
Phương pháp 3:
Minimum distance between 3 and 6 is 12
Minimum distance between 3 and 6 is 400
Cách tiếp cận: & nbsp; Vấn đề nói rằng chúng tôi muốn khoảng cách tối thiểu giữa x và y. Vì vậy, cách tiếp cận là đi qua mảng và trong khi đi qua mảng nếu chúng ta có số là x hoặc y thì chúng ta sẽ lưu trữ sự khác biệt giữa các chỉ số của trước đây X hoặc Y và mới tìm thấy X hoặc Y và như thế này cho mỗi lần chúng ta sẽ thử để giảm thiểu sự khác biệt.
& nbsp; & nbsp; tạo các biến idx1 = -1, idx2 = -1 và min_dist = int_max;
Minimum distance between 3 and 6 is 17
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1571
Minimum distance between 3 and 6 is 12
Minimum distance between 3 and 6 is 46
& nbsp; & nbsp; đi qua mảng từ i = 0 đến i = n-1 trong đó n là kích thước của mảng.
Minimum distance between 3 and 6 is 17
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1579
Minimum distance between 3 and 6 is 12
Minimum distance between 3 and 6 is 46
& nbsp; & nbsp; trong khi đi qua nếu phần tử hiện tại là x thì lưu trữ chỉ mục của phần tử hiện tại trong IDX1 hoặc nếu hiện tại & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; phần tử là y sau đó lưu trữ chỉ mục của phần tử hiện tại trong IDX2.
Minimum distance between 3 and 6 is 17
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1590
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1347
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1592
Minimum distance between 3 and 6 is 49
Minimum distance between 3 and 6 is 46
& nbsp; & nbsp; nếu biến IDX1 và IDX2 không bằng -1 sau đó lưu trữ tối thiểu của min_dist, sự khác biệt của idx1 và idx2 vào & nbsp; & nbsp; Ans.
& nbsp; & nbsp; ở cuối đường truyền, nếu IDX1 hoặc IDX2 vẫn còn -1 [x hoặc y không tìm thấy trong mảng] thì hãy trả về -1 hoặc khác trả về & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; min_dist.
Minimum distance between 3 and 6 is 49
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1474
using
namespace
std;
Minimum distance between 3 and 6 is 40
Minimum distance between 3 and 6 is 46
int
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 10
int
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 12
int
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 14
int
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 16__
Minimum distance between 3 and 6 is 40
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 19
Minimum distance between 3 and 6 is 40____9
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1456
Minimum distance between 3 and 6 is 40
Minimum distance between 3 and 6 is 47
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 171
int
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1461
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1469
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1470
std;
87
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1474
Minimum distance between 3 and 6 is 13
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1476
Minimum distance between 3 and 6 is 40
#include
5 #include
6int
using
4
Minimum distance between 3 and 6 is 494
#include
06Minimum distance between 3 and 6 is 40
Minimum distance between 3 and 6 is 46
Minimum distance between 3 and 6 is 46
Python3
Minimum distance between 3 and 6 is 40____9
using
8Minimum distance between 3 and 6 is 40____9
namespace
1namespace
2namespace
3__72Các
Minimum distance between 3 and 6 is 40
Minimum distance between 3 and 6 is 47
Minimum distance between 3 and 6 is 112
Minimum distance between 3 and 6 is 113
Minimum distance between 3 and 6 is 114
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1696
‘
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1469
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1680
Minimum distance between 3 and 6 is 108
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1051
std;
87
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1708
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1699
Minimum distance between 3 and 6 is 108
Minimum distance between 3 and 6 is 108
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1712
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1469
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1714
Minimum distance between 3 and 6 is 108
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1051
std;
87___
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 174
Minimum distance between 3 and 6 is 162
Minimum distance between 3 and 6 is 108
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1093
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1733
Minimum distance between 3 and 6 is 19
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1735
Minimum distance between 3 and 6 is 429
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1737
Is
Minimum distance between 3 and 6 is 49
#include
5 Minimum distance between 3 and 6 is 429
Minimum distance between 3 and 6 is 409
Minimum distance between 3 and 6 is 40
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1474
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1728
Minimum distance between 3 and 6 is 49
#include
5 Minimum distance between 3 and 6 is 162
Minimum distance between 3 and 6 is 13
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1763
Minimum distance between 3 and 6 is 108____
Minimum distance between 3 and 6 is 108
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1766
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1728
Minimum distance between 3 and 6 is 40
Minimum distance between 3 and 6 is 163____
Minimum distance between 3 and 6 is 108
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1771
Minimum distance between 3 and 6 is 453__
Minimum distance between 3 and 6 is 40
Minimum distance between 3 and 6 is 190
Minimum distance between 3 and 6 is 108
Minimum distance between 3 and 6 is 192
Minimum distance between 3 and 6 is 193
Minimum distance between 3 and 6 is 40
Minimum distance between 3 and 6 is 143
Minimum distance between 3 and 6 is 108
Minimum distance between 3 and 6 is 453
Minimum distance between 3 and 6 is 40
Minimum distance between 3 and 6 is 132____
Minimum distance between 3 and 6 is 108
Minimum distance between 3 and 6 is 461
Minimum distance between 3 and 6 is 40
Minimum distance between 3 and 6 is 400
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 171
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 172
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1154
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1155
C#
using
Minimum distance between 3 and 6 is 411
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 180
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 181
using
16
Minimum distance between 3 and 6 is 441
Minimum distance between 3 and 6 is 414
int
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 16
int
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 18
using
16
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 19
Minimum distance between 3 and 6 is 40____9
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1836
int
Minimum distance between 3 and 6 is 436
Minimum distance between 3 and 6 is 40
Minimum distance between 3 and 6 is 47
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 171
int
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1461
Minimum distance between 3 and 6 is 40
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 19
Minimum distance between 3 and 6 is 406
Minimum distance between 3 and 6 is 13
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1466
Minimum distance between 3 and 6 is 406
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 19
Minimum distance between 3 and 6 is 49
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1470
Minimum distance between 3 and 6 is 406
Minimum distance between 3 and 6 is 46
Minimum distance between 3 and 6 is 406
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1474
Minimum distance between 3 and 6 is 13
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1476
Minimum distance between 3 and 6 is 406
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 19
Minimum distance between 3 and 6 is 49
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1480
Minimum distance between 3 and 6 is 406
Minimum distance between 3 and 6 is 46
Minimum distance between 3 and 6 is 406
Minimum distance between 3 and 6 is 13
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1485
Minimum distance between 3 and 6 is 49
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1869
Minimum distance between 3 and 6 is 40
Minimum distance between 3 and 6 is 46
Minimum distance between 3 and 6 is 40
Minimum distance between 3 and 6 is 13
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1494
Minimum distance between 3 and 6 is 406
#include
5 #include
6Minimum distance between 3 and 6 is 40
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1474
Minimum distance between 3 and 6 is 406
#include
5 using
1using
16
Minimum distance between 3 and 6 is 46
using
16
Minimum distance between 3 and 6 is 440
Minimum distance between 3 and 6 is 441
Minimum distance between 3 and 6 is 442
Minimum distance between 3 and 6 is 477
using
16
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 19
Minimum distance between 3 and 6 is 40____9
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1894
Minimum distance between 3 and 6 is 40____9
Minimum distance between 3 and 6 is 487
Minimum distance between 3 and 6 is 40____9
namespace
8Minimum distance between 3 and 6 is 40____9
std;
1Minimum distance between 3 and 6 is 40
Minimum distance between 3 and 6 is 495
std;
4 Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1036
std;
6 Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1038
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1910
Minimum distance between 3 and 6 is 495
int
0 #include
06using
16
Minimum distance between 3 and 6 is 46
Minimum distance between 3 and 6 is 46
JavaScript
using
77
#include
11
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1380
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 19
Minimum distance between 3 and 6 is 40
using
82 Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1923
Minimum distance between 3 and 6 is 40
Minimum distance between 3 and 6 is 47
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 171
using
82 Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1461
Minimum distance between 3 and 6 is 40
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 19
std;
87
Minimum distance between 3 and 6 is 13
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1466
std;
87
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 19
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1469
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1470
std;
87
Minimum distance between 3 and 6 is 46
std;
87
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1474
Minimum distance between 3 and 6 is 13
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1476
std;
87
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 19
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1469
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1480
std;
87
Minimum distance between 3 and 6 is 46
std;
87
Minimum distance between 3 and 6 is 13
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1485
std;
87
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1954
Minimum distance between 3 and 6 is 40
Minimum distance between 3 and 6 is 46
Minimum distance between 3 and 6 is 40
Minimum distance between 3 and 6 is 13
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1494
Minimum distance between 3 and 6 is 40
#include
5 #include
6Minimum distance between 3 and 6 is 40
Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1474
Minimum distance between 3 and 6 is 40
#include
5 using
1Minimum distance between 3 and 6 is 46
Minimum distance between 3 and 6 is 40
using
82 Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1971
Minimum distance between 3 and 6 is 40
using
82 Minimum distance between 3 and 6 is 479
Minimum distance between 3 and 6 is 40
using
82 namespace
8Minimum distance between 3 and 6 is 40
using
82 std;
1Minimum distance between 3 and 6 is 40
namespace
34std;
4 Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1036
std;
6 Input: arr[] = {1, 2}, x = 1, y = 2 Output: Minimum distance between 1 and 2 is 1. Explanation: 1 is at index 0 and 2 is at index 1, so the distance is 1 Input: arr[] = {3, 4, 5}, x = 3, y = 5 Output: Minimum distance between 3 and 5 is 2. Explanation:3 is at index 0 and 5 is at index 2, so the distance is 2 Input: arr[] = {3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3}, x = 3, y = 6 Output: Minimum distance between 3 and 6 is 4. Explanation:3 is at index 0 and 6 is at index 5, so the distance is 4 Input: arr[] = {2, 5, 3, 5, 4, 4, 2, 3}, x = 3, y = 2 Output: Minimum distance between 3 and 2 is 1. Explanation:3 is at index 7 and 2 is at index 6, so the distance is 1038
Minimum distance between 3 and 6 is 12
Minimum distance between 3 and 6 is 495
int
0 #include
06namespace
44
Đầu ra
Minimum distance between 3 and 6 is 4
- Phân tích độ phức tạp:
- Độ phức tạp về thời gian: O [n]. & Nbsp; chỉ cần một lần đi ngang của mảng. O[n].
Only one traversal of the array is required. - Độ phức tạp không gian: O [1]. & NBSP; Không cần thêm không gian. O[1].
No extra space is required.
Vui lòng viết nhận xét nếu bạn tìm thấy các mã/thuật toán trên không chính xác hoặc tìm các cách khác để giải quyết cùng một vấn đề.