Super Hard Amazon OA | 50LPA | Diwali Special Solution By Kumar K | Asked in October

Поделиться
HTML-код
  • Опубликовано: 25 дек 2024

Комментарии • 31

  • @mentanagavenkatasrinivas9245
    @mentanagavenkatasrinivas9245 Месяц назад +6

    We can calculate the sum(A) and from sorted(B), start from the left and decrement the value B[i] from sum(A) until B[i] 0 and i == len(A)].

    • @SelvaArumugam-xq5mf
      @SelvaArumugam-xq5mf 12 дней назад

      This is the same approach i came with bro this seems to be easy to crack with some observation until we realise we can pick any i and j and there is no contidition such that i

  • @Karandeep_3154
    @Karandeep_3154 Месяц назад +5

    Mind Blowing Approach 😍😍😍😍

  • @tejaltatiwar4682
    @tejaltatiwar4682 Месяц назад +4

    On Diwali also u r working for us

  • @ayaaniqbal3531
    @ayaaniqbal3531 Месяц назад +5

    The Time Complexity is not O(2N) but O(NlogN ) because we are sorting the array.

    • @PrajwalCoding
      @PrajwalCoding Месяц назад

      and we can sort both the arrays since we can change a[i] and a[j] how ever we want. the optimal approach can be using nextgreater and next smaller element

  • @awangandas1700
    @awangandas1700 Месяц назад +2

    brilliant and intuitive solution

  • @Harsh-og5xr
    @Harsh-og5xr Месяц назад +2

    Sir is never off duty🔥🔥

  • @amitthapliyal5018
    @amitthapliyal5018 Месяц назад +2

    Great approach sir ❤

  • @mehulgujar3013
    @mehulgujar3013 Месяц назад +2

    Happy diwali sir ❤🎉

  • @purvansh6256
    @purvansh6256 Месяц назад +2

    Amazing explanation sir👏👏

  • @balajibali2890
    @balajibali2890 Месяц назад +1

    Brilliant kumar K sir🎉🎉🎉🎉❤❤

  • @yeswanthh5068
    @yeswanthh5068 Месяц назад +2

    Thankyou very much ❤

  • @yerramarun2K05
    @yerramarun2K05 Месяц назад +4

    nice

  • @allinonemoviesyt
    @allinonemoviesyt Месяц назад +1

    very nice explanation sir

  • @talkswithprabh5374
    @talkswithprabh5374 Месяц назад

    Please also provide code

  • @abcefg7045
    @abcefg7045 Месяц назад +1

    1. calculate prefix sum of sorted array B
    2. find sum of array A
    2.a. if sum(A) > sum(B) ans = n - 1 // here n is the size of array
    2.b. if sum(A) == sum(B) ans = n
    2.c. if Sum(A) < Sum(B) ans = upper_bound(pref.begin(), pref.end(), Sum(A)) // pref stores the prefix sum of array B assuming 0th index following
    sir ( @Kumar K ) please check if this approach is correct
    Intuation of approach:-
    as we allowed as many operations we want in array A, so first of all, we will make n - 1 indexes of Array A 0, and take all the sum to the last index
    then we will sort array B and try to make elements of array A equal to array B
    eg :- A = [1, 2, 4] B = [1, 3, 1]
    op1 :- A = [0, 2, 5]
    op2 :- [0, 1, 6]
    op3 :- [0, 0, 7]
    sort Array B:- [1, 1, 3]
    now trying to make elements equal to B's elements from the smallest to largest elements
    op4:- [1, 0, 6]
    op5:- [1, 1, 5]
    Ans :- 2

    • @soyachap681
      @soyachap681 Месяц назад

      i think this feels write

    • @phanibhusan6538
      @phanibhusan6538 Месяц назад

      But iska answer to 1 hoga shayad!!!!!

    • @abcefg7045
      @abcefg7045 Месяц назад

      @@phanibhusan6538 why 1?

    • @abcefg7045
      @abcefg7045 Месяц назад

      @@phanibhusan6538 yeah I stopped after 5th step you can continue 2 steps more to get array A as 1 3 3

    • @kumarkdsa
      @kumarkdsa  Месяц назад

      Maybe you are correct :)

  • @talkswithprabh5374
    @talkswithprabh5374 Месяц назад

    Can someone tell, is this code correct:
    int maxSimilarity(const vector& inv1, const vector& inv2) {
    int n = inv1.size();
    vector diff(n);
    // Calculate the difference between corresponding elements
    for (int i = 0; i < n; ++i) {
    diff[i] = inv2[i] - inv1[i];
    }
    // Sort the difference array in ascending order
    sort(diff.begin(), diff.end());
    int positiveSum = 0, operations = 0;
    for (int i = 0; i < n; ++i) {
    if (diff[i] > 0) {
    if (positiveSum > 0) {
    positiveSum--;
    } else {
    operations++;
    }
    } else {
    positiveSum += diff[i];
    }
    }
    return operations;
    }

  • @HeetVichhivora
    @HeetVichhivora Месяц назад +2

    wow

  • @HimanshuSingh-iw2te
    @HimanshuSingh-iw2te Месяц назад

    So I'm writing this comment before seeing the solution. So what I'm getting intution that We can simply get the subtract the 1st array from 2nd get the net sum if the sum is odd then n-1 element can be equal. otherwise all n elements can be equal. Let me know if I'm thinking in correct manner?

    • @kumarkdsa
      @kumarkdsa  Месяц назад

      Maybe you are correct :)

  • @phanibhusan6538
    @phanibhusan6538 Месяц назад

    How can the maximum answer can be N???

    • @kumarkdsa
      @kumarkdsa  Месяц назад +1

      When elements of both the arrays match.