Frequency of each element in an integer array | Brute force | JAVA interview question

Поділитися
Вставка
  • Опубліковано 29 вер 2024

КОМЕНТАРІ • 22

  • @NirajKumar-n9f2d
    @NirajKumar-n9f2d 21 день тому

    public class count {
    public static void main(String[]args){
    int []arr={1,2,3,4,2,2,3,1};
    int []freq=new int[arr.length];
    int visited = -1;
    for(int i=0;i

  • @Caped_Crusader7
    @Caped_Crusader7 3 місяці тому

    why visited = -1?

  • @AkashYadav-tc2lo
    @AkashYadav-tc2lo 2 роки тому +5

    very well explained. Thanks, but still i have a confusion on why we have stored visited in arr[j] ??

    • @TechnosageLearning
      @TechnosageLearning  2 роки тому +2

      We have set freq[j] = visited....because we have already updated the count of that element(freq[j]) and we dont want to visit that element again
      Otherwise same element's frequency will be updated again and again and it wont provide the required result.

  • @rajrawat6376
    @rajrawat6376 2 роки тому +2

    How to do it if time complexity O(N) using brute force

    • @TechnosageLearning
      @TechnosageLearning  2 роки тому +1

      ua-cam.com/video/pzQvKGcze3A/v-deo.html
      Checkout this video

    • @rajrawat6376
      @rajrawat6376 2 роки тому

      @@TechnosageLearning yeah i hve checked out this but the concept of has map isn't thought to us yet so i was asking if there was any other way

  • @basithnizam
    @basithnizam Рік тому +1

    what will happen if the give array has value of visited that is "-1"

    • @yashas1322
      @yashas1322 6 місяців тому

      it will not print(exclude)

  • @kalpshah2070
    @kalpshah2070 Рік тому

    i have doubt related that you have print elements and their frequency for unique elements that not visited but what about that elements that stored in freq[j] how they print?

  • @mdaquibahmed3567
    @mdaquibahmed3567 29 днів тому

    Well explained maam

  • @myviewyt3332
    @myviewyt3332 2 роки тому +1

    Well explained

  • @naushadalam5129
    @naushadalam5129 Рік тому +1

    8
    2 0 1 1 1 0 3 1
    ans=2 4 1 1
    code output=2 4 1 0
    how can i handle this case

  • @ImrojShaik-l4c
    @ImrojShaik-l4c 9 місяців тому

    same as the code in the internet

  • @Riteshpc-c3x
    @Riteshpc-c3x 2 місяці тому

    thanks

  • @politics2198
    @politics2198 Рік тому

    very Awesome explaination.

  • @supriya_codes
    @supriya_codes 2 роки тому

    which screen recorder u r using??

  • @samdarsh3795
    @samdarsh3795 2 роки тому +2

    Well explained mam 👍