{"id":18463,"date":"2021-08-26T10:39:23","date_gmt":"2021-08-26T05:09:23","guid":{"rendered":"https:\/\/python-programs.com\/?p=18463"},"modified":"2021-11-22T18:37:16","modified_gmt":"2021-11-22T13:07:16","slug":"python-program-for-maximum-distance-between-two-occurrences-of-same-element-in-array-list","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-for-maximum-distance-between-two-occurrences-of-same-element-in-array-list\/","title":{"rendered":"Python Program for Maximum Distance between Two Occurrences of Same Element in Array\/List"},"content":{"rendered":"

In the previous article, we have discussed Python Program for Leonardo Number Series<\/a>
\nDictionaries:<\/strong><\/p>\n

Python dictionaries are mutable collections of things that contain key-value pairs. The dictionary contains two main components: keys and values. These keys must be single elements, and the values can be of any data type, such as list, string, integer, tuple, and so on. The keys are linked to their corresponding values. In other words, the values can be retrieved using their corresponding keys.<\/p>\n

A dictionary is created in Python by enclosing numerous key-value pairs in curly braces.<\/p>\n

Given a list, the task is to find the greatest distance between two occurrences of an element in a given list of repeated elements.<\/p>\n

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

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

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

Given List =  [1, 2, 3, 7, 8, 9, 2, 1, 4, 3]<\/pre>\n

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

The greatest distance between two occurrences of an element in a given list of repeated elements = 7<\/pre>\n

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

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

Given List = [6, 7, 8, 2, 1, 6, 8, 9]<\/pre>\n

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

The greatest distance between two occurrences of an element in a given list of repeated elements = 5<\/pre>\n

Program for Maximum Distance between Two Occurrences of the Same Element in Array\/List in Python<\/h2>\n

Below are the ways to find the greatest distance between two occurrences of an element in a given list of repeated elements:<\/p>\n