• Courses
  • Tutorials
  • DSA
  • Data Science
  • Web Tech
October 11, 2024 |390 Views

PROBLEM OF THE DAY : 10/10/2024 | Max distance between same elements

  Share   Like
Description
Discussion

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

Given an array arr[] with repeated elements, the task is to find the maximum distance between two occurrences of an element.

Note: You may assume that every input array has repetitions.

Examples:

Input: arr = [1, 1, 2, 2, 2, 1] Output: 5 Explanation: distance for 1 is: 5-0 = 5, distance for 2 is : 4-2 = 2, So max distance is 5.
 

Give the problem a try before going through the video. All the best!!!
Problem Link: https://practice.geeksforgeeks.org/problems/max-distance-between-same-elements/1