I couldn't find any discussion or editorial blog, so am creating a new one.
Was able to solve the 2nd problem with Segment Tree (standard stuff) and attempted to solve the first one with 6D DP (wasn't able to debug an RE).
It would be great if you could share your approaches for the four problems.
Do you have questions? Can you post?
No, I don't have them. Thought they'd post an editorial or something.
The IDE was kind of unintuitive as well, had to rewrite more than 60 lines of code because the text-area wouldn't accept any text that I had written in my editor.
Plus there was a grey area around whether one could create additional functions and classes, or only the solution function could be modified.
The testing apparatus could have also been better.
Overall, not a great experience.
I also hate the IDE of InterviewBit. Worst experience I have with the IDE.
Exactly its soo hard to debug there!
First Problem___
You are given a range l,r. We have to count total no of beautiful numbers in that range.
Numbers are beautiful if, xor of all digits of that number is greater than the avg(max digit of that number + min digit of that number)
return result%1e9+7
Could someone share the intended approach / an elegant solution?
Mine was clumsy and complicated and full of bugs; 6D DP's never a good idea, ig.
Mine was 5D digit dp and cancerous as it involved finding the maximum and least set bit of a number. The 6d digit dp is better and easier to write.
Did u get ac for this?
yes
can you share the solution of 6-D dp?
do you have any idea what will be the final cutoff for the shortlisting process?
Could you please share the DP approach?
I dont know what is wrong with my code, but I have used 5-D dp and used digit DP . Is there any silly mistake? or some wrong approach?
You need one more state known to handle cases where you haven't started building numbers. For example if you start building from the second digit and put a 0 there it is not considered a part of the number as it is a leading zero.
What was the constraint over l and r
(1, 10^18)
Btw, what is the selection criteria for the Online Round?
Is it based on the number of problems solved, or quality of submissions, or something else?
There wasn't even a rankings page, afaik.
Ig first they will go with number of problems with 100% acceptance rate, then quality of code. Then rest others.
I think they take various factors into account like your resume quality, college, CGPA, branch etc.
its based on points scored
I solved 3 and submitted 4th at the end (don't know if it was accepted or not as the test ended while compiling) and I got the clearance of Online Round mail.
The ranking should be the only selection criteria I think which will be based on the points scored, in case of a tie, time will be considered.
From Interview-Bit or from Trilogy?
I have received one for successful completion from Interview-Bit.
Don't know if it's in any way related to the actual selection process.
From Trilogy, for completing the aptitude test as the next round.
first was digit dp, second was usual prefix sum, third I did using Manachers algo.
Manacher's Algo?
Just found something new to learn.
Thought of applying KMP or ZF in some way, but knew it wouldn't work.
which one you did by prefix sum?the problem in which we need to give x1^x2 where x1 and x2 are bitwise and of range l1,r1,l2 and r2?
If yes how?I did it using seg trees.
upd got it from a below comment.
Simple method: We have to find the values of x1 and x2 then xor them. So, first we create a prefix array pref[i][j] of size n*32 which represents the sum of jth bit of the indices in the range [0, i]. Now, when we want to calculate value of x1, we find the number of set bits of the jth bit and check if it is equal to r1 — l1 + 1 (size), because for bitwise and to be 1, we need all the bits to be equal to 1. Similarly, we can find x1 and x2, then xor them
Third problem can be also done by some simple string hashing and binary search.
Make prefix and suffix hash using some mod value (I used 1e9+9). Now just binary search on the length uptil which the string [i,i+mid] from prefix hash and [i-mid,i] from suffix hash is same. This problem can be solved using binary search in log(n) time.
can you please share some similar question like this?
3rd Problem
Given a string s and a vector Q containing queries. For each element i in Q we have to find the length of longest odd palindrome whose middle index is i in string s. 1 <= Len(s), Len(Q) <= 1e5. We have to return vector of results of each query
Does Q representing the indexes i?
yes
In second problem just store prefix of every bit for all element and check if bit[r][j] — bit[l-1][j] == r-l+1...if yes add that bit to answer. Calculate the same for both given range and store the xor of both!!
Here are the problems:
how did u get them
telegram xd:
https://leetcode.com/discuss/interview-question/2924881/intern-hunt-challenge-trilogy-innovations-2023/
Don't directly jump to conclusions idiot!
From here:
https://leetcode.com/discuss/interview-question/2924881/intern-hunt-challenge-trilogy-innovations-2023/
Here is my approaches...
I solved it with digit dp with 6 states dp[index][xorsum][maximum][minimum][zero][tight]
It's kinda easy one.. segtree is just overkill.. I solved it with 2d prefix sum. As for being a bit set in bitwise AND in a interval [L..R] pref[R][j] — pref[L — 1][j] == R — L + 1 should hold.
It is a binary search problem with string hashing. I used Polynomial Hashing to solve it
Couldn't solve it :(
Just an addition, C was basically a direct implementation of Manacher's algo, which gives linear runtime.
did u solution for the problem c got ac i got tle for a few tc.My code get 286/300.
This was my code for 3rd problem and I got an AC for that.
thanks.
Yeah, my binary search + hashing solution gave 296/300 initially, then I removed the unecessary
%mod
operations during addition, i.e (a%m + b%m > m) ? (a%m + b%m — m) : (a%m + b%m). that was enough for my submission to then get a full score.oh i see.Thanks for the reply..
Can You Please share Your approach for problem C of binary search with hashing
Sure! so I just hashed the string in both the directions i.e. forward and backward/reverse. Then for a query of 'i' I searched for the maximum length that has the center 'i' and is odd. i.e. maximum x for [i — x... i + x] is palindrome. you may check palindrome nature by taking hash between [i — x .... i] for reverse hash table and [i ... i + x] for forward hash table and just compare the result. They should be equal for a substring being palindrome!
thanks
In C, in test cases where the density of palindromes is high, wouldn't the effective complexity of Polynomial Hashing with Verification on Match be O(N*(LogN)*N)?
The probability of hash collision is extremely low, I know, especially if a large prime is used, but still, without verification wouldn't it be non-deterministic?
Ig test cases in problem C are weak
Usually if we do single hash for a string with (p = 31, mod = 1e9 + 7) it don't get collision for a string of length N <= 1e5 but may fail for N <= 1e6 (would need double hash there).
And I optimised my code to work in O(N * log(N)) with some precomputations.
Was anyone able to solve the 4th problem.. The expected value one? If yes please share your approach.
How was your CCAT?
Also, Did you get a mail for the interview?
I didn't appear for the test.
Is solving 1 problem enough to get selection mail?
I solved 2 problems(digit-dp and seg-tree) and got a mail for CCAT(Aptitude Test).
what was the criteria for the selection process.I solved 2nd, 3rd and 200 pts for 1st but no mail for interviews.
not sure either, I guess they also looked for code quality or something. I might be wrong.
As usual I fucked up CCAT yet another time!
Anyone who successfully cleared CCAT. Any tips?
have you received CCAT mail??
Yup! I guess everyone who were shortlisted had to complete ccat by 6pm ist 19 dec