Company: Sap_20nov
Difficulty: medium
Max Distance Between Equal Elements Problem Description You are given an implementation of a function: int solution(vector &A); which accepts as input a non-empty zero-indexed array A consisting of N integers. The function works slowly on large input data and the goal is to optimize it so as to achieve better time and/or space complexity. The optimized function should return the same result as the given implementation for every input that satisfies the assumptions. In other words, A[k] = 2 for each K (0 #include int solution(vector &A) { int N = A.size(); int result = 0; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { if (A[i] == A[j]) result = max(result, abs(i - j)); } } return result; }