{"id":10667,"date":"2021-09-30T16:00:38","date_gmt":"2021-09-30T10:30:38","guid":{"rendered":"https:\/\/python-programs.com\/?p=10667"},"modified":"2021-11-22T18:34:25","modified_gmt":"2021-11-22T13:04:25","slug":"python-program-to-find-the-minimum-difference-between-the-index-of-two-given-elements-present-in-an-array","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-find-the-minimum-difference-between-the-index-of-two-given-elements-present-in-an-array\/","title":{"rendered":"Python Program to Find the Minimum Difference Between the Index of Two Given Elements Present in an Array"},"content":{"rendered":"

If you are new to Java and want to learn the java coding skills too fast. Try practicing the core java programs with the help of the Java basic programs list<\/a> available.<\/p>\n

Lists in Python:<\/strong><\/p>\n

Lists are one of Python\u2019s most commonly used built-in data structures. You can make a list by putting all of the elements inside square brackets[ ] and separating them with commas. Lists can include any type of object, making them extremely useful and adaptable.<\/p>\n

Given a list\/array, the task is to find the minimum difference between the index of given two elements present in a list in Python.<\/p>\n

Examples:<\/strong><\/p>\n

Example1:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

given list =[1, 3, 7, 10, 11, 13, 5, 4, 8, 2, 4, 3, 6, 5, 21, 8, 9]\r\ngiven first element =2\r\ngiven second element =5<\/pre>\n

Output:<\/strong><\/p>\n

The minimum difference between the elements 2 and 5 = 3<\/pre>\n

Example2:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

given list =[7, 9, 6, 8, 7, 5, 9, 4, 3, 2, 11, 19, 23, 4, 5, 8, 6, 3 ,2, 9, 7,]\r\ngiven first element =7\r\ngiven second element =8<\/pre>\n

Output:<\/strong><\/p>\n

The minimum difference between the elements 7 and 8 = 1<\/pre>\n

Program to Find the Minimum Difference Between the Index of Two Given Elements Present in an Array in Python<\/h2>\n

Below is the full approach for finding the minimum difference between the index of given two elements present in a list in Python.<\/p>\n