POTD- 01/11/2023 | Frequencies of Limited Range Array Elements | Problem of the Day GeeksforGeeks

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

КОМЕНТАРІ • 12

  • @kumarqwerty4452
    @kumarqwerty4452 8 місяців тому +3

    Karan Mashru is the best teacher GfG has ever produced.Thanks man for wonderful explanation.

  • @jyoti3427
    @jyoti3427 2 місяці тому +1

    great explanation

  • @himansuiii
    @himansuiii 3 місяці тому +2

    for(int i=0;iN)
    arr[i]=0;
    int i=0;
    while(i

  • @prateekbhaisora
    @prateekbhaisora 11 місяців тому +6

    A cleaner code using modular arithematic:
    void frequencyCount(vector& arr,int n, int p)
    {
    p++;
    for(int i=0; i= n)
    continue;
    int cnt = arr[ind] / p;
    int ele = arr[ind] % p;
    cnt ++;
    arr[ind] = cnt * p + ele;
    }
    for (int i=0; i

  • @daaamn6414
    @daaamn6414 4 місяці тому +1

    Solution giving Run time error.

  • @miracleguy1330
    @miracleguy1330 Місяць тому

    Easiest Solution -> int[] freq = new int[N + 1];
    // Counting the frequency of each element
    for (int i = 0; i < N; i++) {
    if (arr[i]

    • @antimr2808
      @antimr2808 Місяць тому

      Your answer is right and easy but there is a little point I want to make
      They mentioned time complexity as O(1) that means we can not use extra space (int[] freq = new int[N + 1];) becasue this will make the time complexity as O(n).

    • @miracleguy1330
      @miracleguy1330 Місяць тому

      @@antimr2808 ya I didn't take that in account. As It was accepted on gfg. 🥲

    • @zeeshanali4502
      @zeeshanali4502 5 днів тому

      wow you give new meaning to Inplace 😆

  • @srinijabhogoju9033
    @srinijabhogoju9033 4 місяці тому

    Thank you. Very well explained.

  • @chandruram7553
    @chandruram7553 Місяць тому

    Tq💖