Garvit_2013's blog

By Garvit_2013, history, 2 years ago, In English

Can anybody give me the iterative DP solution for the problem ?

I have solved using Memoization but unable to make a tabulation solution using same concept.

Problem: https://leetcode.com/problems/two-city-scheduling/

My Memoization Solution: https://leetcode.com/playground/SaUz7Rr6

Thanks in Advance

Full text and comments »

  • Vote: I like it
  • -12
  • Vote: I do not like it

By Garvit_2013, history, 2 years ago, In English

Can anybody help me with the following problem ? What I am missing . Thanks

Sort Integers by The Number of 1 Bits

Code Link: https://leetcode.com/playground/YGNUSzLx

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it

By Garvit_2013, history, 2 years ago, In English

Can anybody tell me Time complexity of my code? I am confused a lot about this . I think it should be 14! or 14^14 or something else. Please help me and tell me If I am wrong.

Code Link https://codeforces.com/contest/1646/submission/148429105

Thanks in advance

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it

By Garvit_2013, history, 2 years ago, In English

K stones

AC: https://atcoder.jp/contests/dp/submissions/28762970

Why it is giving wrong ? It has exact same logic that of AC one. Can anybody help me? Thanks in advance.

WA: https://atcoder.jp/contests/dp/submissions/28762899

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it

By Garvit_2013, history, 3 years ago, In English

Can anybody tell me what I am missing so that following 2 codes gives different results.

Problem C

Code 1 : Accepted

Code 2 : Wrong Answer

Thanks in advance

Full text and comments »

  • Vote: I like it
  • +3
  • Vote: I do not like it

By Garvit_2013, history, 3 years ago, In English

Problem Link: https://www.codechef.com/problems/CHEFDQE

Tle Solution: https://www.codechef.com/viewsolution/50428881

Can anybody help me why it is giving Tle?

Thanks in advance.

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it

By Garvit_2013, history, 3 years ago, In English

Can anybody tell me why my code is incorrect?

Thanks in advance.

Question link: https://practice.geeksforgeeks.org/problems/boolean-parenthesization5610/1

int solve(int i,int j, string &s,  vector<vector<vector<int>>> &v,bool flag)
{
 
    if(i==j)
    {
        if(flag)
        return s[i]=='T';
        else
         return s[i]=='F';
    }
    if(v[i][j][flag]==-1)
    {
        
        int ans=0;
        if(flag)
        {
            for(int k=i+1;k<j;k=k+2)
    {
        if(s[k]=='&')
        {
            ans+= solve(i,k-1,s,v,flag)*solve(k+1,j,s,v,flag);
        }
        else if(s[k]=='|')
        {
             ans+= solve(i,k-1,s,v,flag)*solve(k+1,j,s,v,!flag);
             ans+= solve(i,k-1,s,v,!flag)*solve(k+1,j,s,v,flag);
             ans+= solve(i,k-1,s,v,flag)*solve(k+1,j,s,v,flag);
        }
        else
        {
             ans+= solve(i,k-1,s,v,flag)*solve(k+1,j,s,v,!flag);
             ans+= solve(i,k-1,s,v,!flag)*solve(k+1,j,s,v,flag);
        }
       
    }
        }
        else
        {
            for(int k=i+1;k<j;k=k+2)
    {
        if(s[k]=='&')
        {
             ans+= solve(i,k-1,s,v,flag)*solve(k+1,j,s,v,flag);
             ans+= solve(i,k-1,s,v,flag)*solve(k+1,j,s,v,!flag);
             ans+= solve(i,k-1,s,v,!flag)*solve(k+1,j,s,v,flag);
        }
        else if(s[k]=='|')
        {
             ans+= solve(i,k-1,s,v,flag)*solve(k+1,j,s,v,flag);
        }
        else
        {
             ans+= solve(i,k-1,s,v,flag)*solve(k+1,j,s,v,flag);
             ans+= solve(i,k-1,s,v,!flag)*solve(k+1,j,s,v,!flag);
        }
       
    }
    }
     v[i][j][flag]=ans;
}
      return v[i][j][flag];
}

class Solution{
public:
    int countWays(int N, string S){
        // code here
        //cout<<S.size();
        vector<vector<vector<int>>> v(N,vector<vector<int>> (N,vector<int> (2,-1)));
        return solve(0,N-1,S,v,true);
    }
};

Full text and comments »

  • Vote: I like it
  • -7
  • Vote: I do not like it

By Garvit_2013, history, 3 years ago, In English

Code link :https://codeforces.com/contest/1549/submission/124673267

Please help me I am trying to find it since last night and I am not able till now .

Thanks in advance.

Full text and comments »

  • Vote: I like it
  • +1
  • Vote: I do not like it

By Garvit_2013, history, 3 years ago, In English

Can anybody help me? Please tell me is my approch is wrong or there is problem in my implemention so that some test cases are not passing.

Question:https://leetcode.com/problems/maximum-performance-of-a-team/

My Code: https://leetcode.com/problems/maximum-performance-of-a-team/discuss/1255705/can-anybody-help-me

Thanks in advance

Full text and comments »

  • Vote: I like it
  • -3
  • Vote: I do not like it