Unacademy Hiring challenge [Debugging - Cpp - Q2]

Anyone got called???how many of you got 700 out of 700?

Mine 300 only :frowning_face:

1 Like

Where did they invite you? Did they mail you?

I got 700 as well

2 Likes

U have to said this earlier your name should be in above meme. :stuck_out_tongue_winking_eye:

I solved Decomposition problem using Segment Tree with Max Query but I got only 52 points due to which i scored 352 only!!!..here’s the code

#include<bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// #define int long long
#define ll long long
#define vi vector<int>
#define pb push_back
#define endl "\n"
#define mod 1000000007

int n, q, t;
ll quality[100005], quantity[100005];
ll tree[500005];
map<ll, int> mp;

void buildTree(int v, int l, int r)
{
    if(l == r)
    {
        tree[v] = quality[l-1];
    }
    else
    {
        int mid = (l + r)/2;
        buildTree(2 * v, l, min(mid, r));
        buildTree(2 * v + 1, max(mid + 1, l), r);
        tree[v] = max(tree[2 * v], tree[2*v + 1]);        
    }
    
}

ll get(int v, int l, int r, int start, int end)
{
    if ((l > r) || (l > end) || (r < start))
        return 0;
    if (l == start && r == end)
        return tree[v];
    int mid = (l + r) / 2;
    return max(get(2 * v, l, mid, start, min(mid, end)), get(2 * v + 1, mid + 1, r, max(start, mid + 1), end));
}


int32_t main()
{
    IOS
    cin>>t;
    while(t--)
    {
    cin>>n>>q;
    for(int i = 0; i<n; i++)
    {
        cin>>quality[i];
        mp.insert({quality[i], i});
    }
    for(int i = 0; i<n; i++)
    {
        cin>>quantity[i];
    }

    buildTree(1, 1, n);
    while(q--)
    {
        int type;
        cin>>type;

        if(type == 1)
        {
            int l, r;
            ll addQ;
            cin>>l>>r>>addQ;
            ll maxQuality = get(1, 1, n, l, r);
            int idx = mp[maxQuality];
            quantity[idx] += addQ;
        }
        else
        {
            int v, idx;
            ll takeQ, thrus;
            cin>>v>>idx>>takeQ>>thrus;
            int l = max(idx-v, 1);
            int r = min(idx+v, n);

            ll maxQuality = get(1, 1, n, l, r);
            int maxId = mp[maxQuality];

            if( (quantity[maxId] < takeQ) || (maxQuality < thrus))
            {
                cout<<"No purchase"<<endl;
            }
            else
            {
                int p = maxId + 1;
                cout<<p<<endl;
                quantity[maxId] -= takeQ;
            }
            
        }
        

    }
    }
    
}


// code by mayank chaudhary
// chaudhary_19

can anyone please help me why I was getting wrong answer on 2 testcases…
(according to me it is some int-long problem but not sure)
and Did anyone get any call from them especially who have scored > 500 :slight_smile:

The implemented algorithm was Kosaraju though.

achcha thnax

Did anybody got any mail for further rounds?

DO you have other problems too?

They said that they will contact the shortlisted people for full time in few days and the part time in coming weeks.

Clear the map

Yes, I recieved it now.

Yes, I got the same mail

Thank you :slight_smile: this small skip costs me 48 points…will try to never do this mistake in future again

I always make clear / reset function in which I cleared all the adjacency list , vis, parent arrau , map , and all other things , Ricks nhi lene ka. :stuck_out_tongue_winking_eye:

1 Like

Literally I was in hurry that day, I started 40 min late this contest and looked on coding problems only (not a single debugging problem ) . If ye hojata complete to 400 pts to hote …but let’s see when will the result come

1 Like

Can anyone share their algorithm for that XOR problem.

Here’s the link

yeah, i know that but not able to understand that algorithm. Can you explain it to me in easy words