Hello Everyone!
I would like to invite you to participate in HackerEarth's June Easy '20. It will be held on Saturday, June 06 at 12:00 — CDT.
I (nikesh04), vivaan_gupta, Finding_Infinity, spar5h, and Kritagya Agarwal are the setters of this round, and Arpa is the tester of the problems.
You will be given 6 algorithmic questions to solve in 3 hours. Partial scoring will be used (you get points for passing each test case). Although the contest is targeted towards beginners, we hope that everyone finds the tasks interesting. The contest is rated for all and the prizes will be awarded to the top 3 beginners (i.e. programmers with a rating of 1600 or less before the challenge starts):
First place: $75 Amazon gift card.
Second place: $50 Amazon gift card.
Third place: $25 Amazon gift card.
Good luck to everyone, and I hope you like the contest!
contest is not loading 502 gateway error:(
Hint for last problem ?probably greedy with taking mid does not work
Please share approach for "Arrays and Sum" , I solved 4 questions and this one partial .
I do not know how but subset-sum did the work for me. According to the constraints I should have got partial points.
Can u please share your code ... and it will be more helpful if anyone share most optimized approach for this question
My in contest soln was similar just that it used bitsets for a /32 constant factor.
I assumed it to be O(N*1000/32). After reading your comments I realized it was O(N*1000*1000/32).
just do knapsack, and if u can make the sum looking more than 1 time than there is another subset that can make this sum. corner case is zero (ignore it).
What's your complexity N3 ?
o(n^2)
Please share your code .
You can store the number of ways to get a sum of x by in dp[x]. Thus, if the number of ways is greater than 1, then there exists a subset with equal sum. One implementation detail to take care of is to ignore 0 valued elements and set dp[0] to 1 initially as sum of empty set is 0.
Can someone share the intuition for the F problem? Problem Link
I was able to arrive at an O(N^2) solution using dp.
How to solve it efficiently ?
A brief writeup of my O(N*logM) soln.
Notice that one will be at a[i-1] when we want to go to a[i].
This gives N^2 DP.
There are 2 transitions for each state (a[i-1],y) to (a[i-1],a[i]) or (a[i],y).
Lets calculate a[i],j 0<=j<=M from a[i-1],k 0<=K<=M.
Ignore the first transition.
For 2nd transition update (a[i],a[i-1]) with min(abs(y-a[i])+dp[a[i]][y]) — abs(a[i]-a[i-1]) for 0<=y<=M.
Difference if we opt for 2nd instead of first.
Can be done in O(logM) using segment trees.
At last add abs(a[i]-a[i-1]) for 0<=i<=N in minimum(a[n],y).
Won't there be a state for number of days we have successfully passed?
Solve like sweep algorithm.
Keep O(M) states when we reach ith index and then convert them into O(M) i+1 th. Notice that only one of them changes.
Can you share the code,as they're not visible yet.
Sure. link