Answer:
Create a variable m = INT_MAX.
Run a nested loop, the outer loop runs from start to end (loop counter i), the inner loop runs from i+1 to end (loop counter j)
If the ith element is x and jth element is y or vice versa, update m as m = min(m,j-i)
Print the value of m as minimum distance
Copyright © 2024 EHUB.TIPS team's - All rights reserved.
Answers & Comments
Verified answer
Answer:
Create a variable m = INT_MAX.
Run a nested loop, the outer loop runs from start to end (loop counter i), the inner loop runs from i+1 to end (loop counter j)
If the ith element is x and jth element is y or vice versa, update m as m = min(m,j-i)
Print the value of m as minimum distance