1601. Maximum Number of Achievable Transfer Requests | Bit Manipulation

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

КОМЕНТАРІ • 10

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

    you have really good communication skills keep going

  • @invinishku1542
    @invinishku1542 Рік тому +3

    hi, bro your 2nd approach is still having space complexity of O(M+N). M=recursive call stack and N=indegree vector in each call to validate our answer. (Here, M=requests.size() and N= unique buildings)

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

      yes he said the time complexity will remain same

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

      @@I_Keshav_Prajapati I'm talking about space complexity...time complexity is same in both the approaches.

  • @DevanshAgarwal-tf7jt
    @DevanshAgarwal-tf7jt Рік тому

    Hello sir. Please make a video on yesterday's challenge. It would be of great help!

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

    In the first approach, if we take do not approve the request at first and then take the approved request, why is this method not working? Can anyone tell me the reason for this?

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

      It will work only if you update vector to original state
      See, try this way
      // Ignore this request and move on to the next request without incrementing the count.
      maxRequest(requests, indegree, n, index + 1, count);
      // Consider this request, increment and decrement for the buildings involved.
      indegree[requests[index][0]]--;
      indegree[requests[index][1]]++;
      // Move on to the next request and also increment the count of requests.
      maxRequest(requests, indegree, n, index + 1, count + 1);
      // Backtrack to the previous values to move back to the original state before the second recursion.
      indegree[requests[index][0]]++;
      indegree[requests[index][1]]--;
      This is because to backtrack, we need original vector, and not the updated one.

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

      I encountered the same problem ... it's because in his code ...he has declared indegree vector publicly...so after returning from 1 call it will still have previous value...to make it work you have to call compensatory part in the end explicitly.....else u can declare indegree vector in function and pass it as argument and then i suppose what u were trying to do..would work...i.e first calling not take part and then calling take part.

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

    approach1:
    class Solution {
    int ans = INT_MIN;
    public:
    void solve(int n, vector& req, vector &blocks, int ind, int count){
    if(ind==req.size()){
    for(int i=0; i