Guys please share your approaches for the problems you solved. How many did you guys solve?
№ | Пользователь | Рейтинг |
---|---|---|
1 | ecnerwala | 3648 |
2 | Benq | 3580 |
3 | orzdevinwang | 3570 |
4 | cnnfls_csy | 3569 |
5 | Geothermal | 3568 |
6 | tourist | 3565 |
7 | maroonrk | 3530 |
8 | Radewoosh | 3520 |
9 | Um_nik | 3481 |
10 | jiangly | 3467 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | maomao90 | 174 |
2 | adamant | 164 |
2 | awoo | 164 |
4 | TheScrasse | 160 |
5 | nor | 159 |
6 | maroonrk | 156 |
7 | -is-this-fft- | 150 |
8 | SecondThread | 147 |
9 | pajenegod | 145 |
9 | orz | 145 |
Guys please share your approaches for the problems you solved. How many did you guys solve?
Название |
---|
Can anyone share the problems?
I solved first with Sliding window Maintaining a hashmap of size two for tracking Frequency and checking for additional N/3 minimum Frequency requirement ,
I guess it can be solved by simply checking all substrings of size 3.
It can be solved by checking every substring of length 3 only also, no need to use sliding window.
Now, question arises why only length 3 , it can be more than that , right?
So, here is the answer ....
suppose if length is greater than 3 then also one can verify that it will contains a golden string of length 3 in it. Try dry running the algorithm.
what about abca , you have to check substring of size 5.
means if there exists two indices(i,j) such that s[i]=s[j] and abs(i-j)<=4 then answer is true(if string size is greater than 3) else answer is false.
NO. abca has 3 different characters in every window so no golden string.
oh yes i forgot this condition.
There is a condition that golden string should contains exactly 2 distinct characters. So, checking only substrings of length 3 will work
It could be also proved by let's say there exists a golden string of length>4 that is golden than it will surely contain {i,i+1} such that si != si+1
and therfore{i-1,i+1} or {i,i+2} substring will also be golden whichever exists.
How to approach the problem with the rocket jumping in powers of two? I tried simulating it with bruteforce but always WA
In that you could easily compute xj array and let dp[i] be the answer for musk rocket to come at i hence the problem reduced to for each i given k disjoint intervals [l_i,r_i] and value of k would be atmost 20(actually less than that too) and if we are at i then just update all the intervals that could be done by segment tree or fenwick tree but could also be done by some ranged update in a query (like updating for [l_i,r_i] by adding dp[i] to it ->dp[l_i]+=dp[i] and dp[r_i+1]-=dp[i] then if we are at i then we no the answer available at i by just summing over values before that or just adding the initials.
Yeah thats pretty obvious and this is what I was doing but my answer was wrong from n >= 6. Maybe I had implementation issues.
As the range update queries will always be to the right of the current index i, we can use a difference array and keep taking its prefix sum while traversing from left to right. The implementation will be much shorter and easier.
To solve DP integers
: I just applied dp with recursion:f(a, b) = min{
if (a == 0 and b == 0) return 0;
if (a != b) return f(sqrt(a*b), sqrt(a*b) + 2;
if (a > 0) return f(a/2, b) + 1;
if (b > 0) return f(a, b/2) + 1;
}
To solve Two summations: Used greedy: sorting
.Observation: a_i + b_j dominates b_i + a_j when a_i + b_j > b_i + a_j
Rearrange the equation and apply sort function.
a_i — b_i > a_j — b_j
After sorting, calculate the contribution of each number, since i < j and j will dominate i.
Where I can see scoreboard or standings ?
I solved 3. A lot of people whom I know solved 4 or more.
How to solve 3rd or 4th one ?? (whichever you solved :_:)
Can anyone share the approach for the last problem?
did you get 4th question ? I solved it in o(n*n) . Please share the approach! Thanks in advance
My friend has received an email stating the test cases of DP integers have changed,before for 0 0,output was given as 2 and I think everyone wrote the solution accordingly,but then after the contest I came to know that it was changed,is there anyone with the same scenario ?
This contest was a crap. Wasted 4 hours
why tho? too easy for you?
Absolutely not. You know the test cases issue with the second problem. I still don't understand what we are supposed to do in the third problem. There was an option like see expected output for custom input, for third problem when I gave 9 9 1 as input the output was 1 but according to the sample test cases it should be 0. O(nlogn) doesn't pass for the fourth problem. I had to optimize it to O(n). For fifth problem, the problems statement is somewhat wrong.
What approach did you follow in 4th question?
I don't think we can view our solutions. I initially solved the problem using maps. After I got TLE, I used arrays instead of maps. Hashed negative values to positive indices by adding -min.
I coded 4th in nlogn and it passed.
Maybe my O(nlogn) implementation was a mess.
can you please share the solution?
I calculated number of times ai and bi will occur in the answer. Just multiplied the count obtained with ai and bi to get the final answer (Contribution technique).
Now, for ai to appear in the summation this condition must be true :
ai + bj >= aj + bi
=> ai-bi >= aj-bj
Make a vector of ai-bi values and then sort it. Use binary search to count the occurences with the above condition (for count of bi inequality will be reversed).
metoo
can you send the code of 4th quesiton? So that i can see what is the approach of the quesion...
Could you please tell what part was wrong in Problem Statement of 5th Problem?
Setter solution didn't ignore double counting.
For eg. xj[i] = 3;
then possible lengths of jumps are [2^0,2^1] union [2^1,2^2]
so,
{1,2} union {2,3,4} = {1,2,3,4}
but setter solution has taken it as {1,2,2,3,4}
Okay cool got it. Thanks!
I had solved first, second and fourth partial. For the first I had just checked if string length is greater than 3 and if s(I) == S(I+1) or S(I) ==S(I+2).
For. The second I had separately handled four corner cases and for rest cases just found out operation required to turn minimum of two number to zero and add 2 to it
For fourth partial brute force
Can anyone suggest approach for two summation and swap it harder?
This is the solution for Two Summation
First, in these types of problems, you should try to simplify as much as possible. Let's go through the solution.
You can take out $$$A[i] + B[j]$$$ from the max and the problem would reduce to finding sum of $$$A[i] + B[j]$$$ separately and sum of $$$max(0, A[j]+B[i] - A[i] - B[j])$$$
You can then calculate the first part by just observing that each number will appear in n pairs, so the sum would be $$$n \times (Sum(A[i]) + Sum(B[i]))$$$.
For the other part, see that it can be re-written as $$$max(0, (A[j]-B[j]) - (A[i]-B[i]))$$$
Make an array Diff, such that $$$Diff[i] = A[i] - B[i]$$$, so again rewriting, you need to find summation over all pairs of values in Diff, $$$max(0, Diff[i] - Diff[j])$$$.
Now how to do this in better than $$$O(N^2)$$$?
See that since you need to sum it over all pairs, the order does not matter.
So you can sort the elements in Diff array. Also, observe that only those pairs will contribute where $$$Diff[i] > Diff[j]$$$, others will be $$$0$$$.
So for each index i (say 0-based), the answer will increase by
$$$(Diff[i]-Diff[0]) + (Diff[i] - Diff[1]) + ... + (Diff[i] - Diff[i-1])$$$
=> $$$i \times Diff[i] - (Diff[0] + Diff[1] + ... Diff[i-1]) = i \times Diff[i] - (Sum(Diff[j])$$$ upto $$$i-1)$$$
Now you just iterate over all indices, keep a sum-upto variable and add the above to the answer.
Let's try to understand this by an example. $$$Diff = [2, 4, 5, 7]$$$.
So the pairs that will be counted are:
$$$4 - 2 => 4 - (2)$$$
$$$(5 - 2) + (5 - 4) => 2*5 - (2+4)$$$
$$$(7 - 2) + (7 - 4) + (7 - 5) => 3*7 - (2+4+5)$$$
All pairs are of the form $$$+Diff[i] - Diff[j]$$$.
Q: How many times, a certain index i, will be at '+' position?
A: $$$i$$$ times, as there are $$$i$$$ elements smaller than ith element (0-based).
Q: How many times, a certain index $$$i$$$, will be at '-' position?
A: $$$n-1-i$$$ times, as there are $$$n-1-i$$$ elements bigger than ith element (0-based).
Therefore, for each index $$$i$$$, add $$$i\times Diff[i] - (n-1-i)\times Diff[i] = Diff[i] * (2\times i - n + 1)$$$.
This should be O(nlogn) as you have sorted the diff array.
Yeah, you are right, what I meant was how to do in $$$O(N)$$$ after sorting.
I'll change that. Thanks!
This leetcode problem is based on the similar profile. Even though, I have solved this problem, I couldn't get the 4th one in the contest =(
If someone has got similar problems, please do share.
x
I appreciate your effort but it is kind of unreadable.
y
I did with prefix sums but my approach is different and works in nlogn :)
Were the points displayed after submission? They weren't displayed for me when my solutions got fully accepted
Yes the points were not shown when the solution got fully accepted but for partially correct solution points were shown
crappiest contest wasted 4 hours solved first three only to learn test cases for problem 2 changed and for problem 3 test cases were super weak and wrong . no learning
Can anyone help with the logic of the shipment packaging question?
Does anyone know when will they release standings?
After the second version which is to be held on 23rd Oct . Your best of two scores will be considered in final standings.
Source :- LinkedIn
I have received one mail (some days back) regarding another contest of Codeagon on 17th October. But since then, I haven't received any further notifications. Has anyone else got it?
When we can expect results of codeagon 2021 ?
It's better to have no expectation from them :XD
Looks like they were not too much interested this year.In first contest test cases went wrong for second problem.
Shortlisting emails are getting released. Check your mailbox.