Convert an array to reduced form | Set 1 (Simple and Hashing) | GeeksforGeeks

Find Complete Code at GeeksforGeeks Article: www.geeksforgeeks.org/convert-...
Practice Problem Online Judge: practice.geeksforgeeks.org/pro...
This video is contributed by Aditi Bainss
Please Like, Comment and Share the Video among your friends.
Also, Subscribe if you haven't already! :)

Пікірлер: 7

  • @gabrielzaragoza8220
    @gabrielzaragoza82205 жыл бұрын

    On one hand your code has std:unordered_map which seems relatively modern. On the other hand you pass a C style array with the length, which seems older and error prone. Is there some reason you mix the two styles? Did you want to pass std::vector ?

  • @youd87
    @youd874 жыл бұрын

    Why do we need a map? Cant we just sort the array and then assign them values from 0 to n-1?

  • @gauravkvtamboli2660
    @gauravkvtamboli26603 жыл бұрын

    An alternate thing which can be done is, after sorting elements, instead of using Hashing, we can do a binary search of the element in sorted temp array 1. After Sorting the temp array, iterate over the original array 2. pick an element of the original array and search in a sorted array 3. return index from binary search and update the same in the original array Hashing takes O(n) space and searching becomes O(1) and in Binary search, search time is O(log(n)) and space - O(1)

  • @sandeepvy1347

    @sandeepvy1347

    3 жыл бұрын

    Yeah it's a nice way

  • @wecan2729
    @wecan27293 жыл бұрын

    void convert(int arr[], int n) { int t[n]; for(int i=0;i

  • @gauravanand6937
    @gauravanand69376 жыл бұрын

    What about the duplicates??

  • @GeeksforGeeksVideos

    @GeeksforGeeksVideos

    6 жыл бұрын

    It is mentioned in the problem statement that the array has distinct elements. :)