please convert the code to C language   // C++ program to find maximum distance between  // two occurrences of same element in array #include using namespace std; int maximum_distance_bw_occurences(vector arr, int n) {     //create a hash table where for each key the      //hash function is h(arr[i])=arr[i]     //we will use stl map as hash table and      //will keep i stored(i of arr[i])     //so say two keys arr[0] and arr[5] are mapping      //to the same location, then the location will have value 0,5     //instead of the keys itself     map > hash;     //for each number     for (int i = 0; i < arr.size(); i++) {         hash[arr[i]].push_back(i);     }     //now to find max distance b/w two occurrences     //we need to check difference b/w first and      //last position for each unique keys     //maxdiff=max(last-first) for each unique key     int maxdiff = 0;     for (auto it = hash.begin(); it != hash.end(); it++) {         int first = it->second[0];         int last = it->second[it->second.size() - 1];         if (last - first > maxdiff) {             maxdiff = last - first;         }     }     //so ans will be updated maxdiff     return maxdiff; } int main() {     int n;       cout << "Enter number of elements\n";     cin >> n;     vector arr(n, 0);     cout << "Input the array elements\n";     for (int i = 0; i < n; i++) {         cin >> arr[i];     }     cout << "Minimum number of deletion required to make all elements same is: ";     cout << maximum_distance_bw_occurences(arr, n) << endl;          return 0; }

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

please convert the code to C language

 

// C++ program to find maximum distance between 
// two occurrences of same element in array
#include <bits/stdc++.h>
using namespace std;

int maximum_distance_bw_occurences(vector<int> arr, int n)
{
    //create a hash table where for each key the 
    //hash function is h(arr[i])=arr[i]
    //we will use stl map as hash table and 
    //will keep i stored(i of arr[i])
    //so say two keys arr[0] and arr[5] are mapping 
    //to the same location, then the location will have value 0,5
    //instead of the keys itself

    map<int, vector<int> > hash;

    //for each number
    for (int i = 0; i < arr.size(); i++) {
        hash[arr[i]].push_back(i);
    }

    //now to find max distance b/w two occurrences
    //we need to check difference b/w first and 
    //last position for each unique keys
    //maxdiff=max(last-first) for each unique key
    int maxdiff = 0;
    for (auto it = hash.begin(); it != hash.end(); it++) {
        int first = it->second[0];
        int last = it->second[it->second.size() - 1];
        if (last - first > maxdiff) {
            maxdiff = last - first;
        }
    }

    //so ans will be updated maxdiff
    return maxdiff;
}

int main()
{
    int n;
 
    cout << "Enter number of elements\n";
    cin >> n;

    vector<int> arr(n, 0);

    cout << "Input the array elements\n";

    for (int i = 0; i < n; i++) {
        cin >> arr[i];
    }

    cout << "Minimum number of deletion required to make all elements same is: ";
    cout << maximum_distance_bw_occurences(arr, n) << endl;
    
    return 0;
}

 

Output:

 

Enter number of elements
10
Input the array elements
1 2 3 1 2 4 5 6 2 3
Minimum number of deletion required to make all elements same is: 7
Transcribed Image Text:Enter number of elements 10 Input the array elements 1 2 3 1 2 4 5 6 2 3 Minimum number of deletion required to make all elements same is: 7
Expert Solution
steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY