darkshadows's blog

By darkshadows, history, 4 years ago, In English

Hello again,

Google's Kick Start 2020 season is here! Kick Start hosts online rounds throughout the year, giving participants the opportunity to test and grow their coding abilities while getting a sample of the programming skills needed for a technical career at Google. Top candidates might be invited for interviews.

We have some exciting updates for 2020:

  • We’re removing Hidden Verdict Test Sets. All submissions will receive instant feedback.
  • You'll see a fourth problem added to each round.

I invite you to solve some fun and interesting problems on Mar 22 2020, 04:00 UTC.

Dashboard can be accessed here during the contest. Problem analyses will be published after the contest.

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

| Write comment?
»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Bump; few hours to go.

»
4 years ago, # |
  Vote: I like it +3 Vote: I do not like it

What does it mean when it says Sample Failed: WA?

Does it mean I got WA on the sample provided?

»
4 years ago, # |
  Vote: I like it +74 Vote: I do not like it

Problems this time are way easier than previous ones. This round is like 1000 — 1200 — 1600 — 1800 compare to the last one I tried 1200 — 1800 — 2200

  • »
    »
    4 years ago, # ^ |
      Vote: I like it -43 Vote: I do not like it

    How many people scored 100/100?

  • »
    »
    4 years ago, # ^ |
      Vote: I like it -18 Vote: I do not like it

    I feel the third is hardest, I use dp and get TLE for test 2

    • »
      »
      »
      4 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      in 3rd, u need beinary search. check whether we can make x as our answer. we can make x as our answer only when sum of all (a[i+1] — a[i]) / x , for i = 1 , n — 1 is <= k.

    • »
      »
      »
      4 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      It can also be done by simple greedy, just pick the largest gap, decrease the gap, repeat for k times. O(klogn).

      • »
        »
        »
        »
        4 years ago, # ^ |
          Vote: I like it +3 Vote: I do not like it

        Hey!

        I'm not sure that this always works, for example, given a case where the optimal solution involves splitting up some difficulty gap twice (one input gap into thirds), but this solution would first split it into halves and split one half into two quarters.

        Here's a case:

        N = 2
        K = 2
        M = [1, 19]
        

        Here, the optimal solution would be to use two splits between 1 and 19, making [1, 7, 13, 19] so the answer is 6. However repeatedly picking the largest gap and splitting it into half, would give you:

        [1, 19] => split into [1, 10, 19] for the first step,

        Now the largest gap is [1, 10] (or [10, 19]), which you could split into [1, 5, 10]. This approach gives 9 as the answer (because [10, 19] still hasn't been split), but 6 is possible, as we showed above.

        Thanks!

        • »
          »
          »
          »
          »
          4 years ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          No, I meant equally distribute the gap, like fo the first time you visit this gap {1,19} divide it in two parts (thus {1,10,19}) now when you visit the same gap again split it into 3 parts(thus {1,7,13,19}), and so on k times. I implemented it like @Spheniscine 's comment down below.

  • »
    »
    4 years ago, # ^ |
      Vote: I like it +18 Vote: I do not like it

    2nd was def tougher than 1200

»
4 years ago, # |
  Vote: I like it +63 Vote: I do not like it

Speedforces

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Why priorityqueue based greedy solution giving WA on large test case of problem 3?

  • »
    »
    4 years ago, # ^ |
      Vote: I like it +5 Vote: I do not like it

    If you are just taking biggest gap and dividing it into two, that won't work. Consider the case:

    1
    2 2
    1 10
    

    The optimal solution is 1 4 7 10 with a penalty of 3, but the divide-by-two solution would produce something like 1 5 7 10 with a penalty of 4.

    • »
      »
      »
      4 years ago, # ^ |
        Vote: I like it +9 Vote: I do not like it

      I too wrote the solution using priority queue and got 3 WA. Later used binary search.

      • »
        »
        »
        »
        4 years ago, # ^ |
          Vote: I like it +10 Vote: I do not like it

        I actually used priority queue, but rather than storing only the gap, I store both the initial gap and the number of insertions, and greedily add insertions to the entries with the biggest current gap, i.e. $$$\left\lceil \dfrac {gap_0} {insertions + 1} \right\rceil $$$

        • »
          »
          »
          »
          »
          4 years ago, # ^ |
            Vote: I like it +3 Vote: I do not like it

          yeah i did the same ,Having original value is important

        • »
          »
          »
          »
          »
          4 years ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          Wow, that's smart way.

        • »
          »
          »
          »
          »
          4 years ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          Can you kindly post your solution?

        • »
          »
          »
          »
          »
          4 years ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          Is there a mathematical formula/concept behind that expression? I fail to see why that works.

          • »
            »
            »
            »
            »
            »
            4 years ago, # ^ |
            Rev. 3   Vote: I like it 0 Vote: I do not like it

            Each entry represents the gap between a pair of consecutive numbers in the input (so $$$gap_0 = M_{i+1} - M_{i}$$$ for the $$$i$$$th entry). $$$insertions$$$ are the number of new exercises you plan to put within that gap.

            So say you plan to put $$$3$$$ insertions between $$$2$$$ and $$$11$$$. It can be seen that it's optimal to space them out as evenly as possible (e.g. 2 4 6 8 11), and the largest gap remaining in that segment is $$$\left\lceil \dfrac {11-2} {3 + 1} \right\rceil = 3$$$.

    • »
      »
      »
      4 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Ahh, Thanks.

  • »
    »
    4 years ago, # ^ |
    Rev. 2   Vote: I like it 0 Vote: I do not like it

    I solved it using the priority queue.

    My code.

»
4 years ago, # |
  Vote: I like it +77 Vote: I do not like it

Got rly lucky and got first :) Screencast: https://youtu.be/uGrBHohIgQY

  • »
    »
    4 years ago, # ^ |
      Vote: I like it +5 Vote: I do not like it

    u r legend.

  • »
    »
    4 years ago, # ^ |
      Vote: I like it +28 Vote: I do not like it

    How to get lucky as often as you and win everything?

  • »
    »
    4 years ago, # ^ |
      Vote: I like it +23 Vote: I do not like it

    seems like the thinking phrase was missing

  • »
    »
    4 years ago, # ^ |
      Vote: I like it +13 Vote: I do not like it

    The only reason why I was able to solve the 4th question was that I had seen this video from your Youtube channel in which you applied dfs on the trie. It's a simple and easy concept but still was very helpful. Thanks!

»
4 years ago, # |
Rev. 2   Vote: I like it +167 Vote: I do not like it

The "Case #x: y" is the most bullshit thing I have ever seen in my life.

»
4 years ago, # |
  Vote: I like it +18 Vote: I do not like it

11000 people gave this contest. Never ever in the history of kickstart. what make sudden rise.

  • »
    »
    4 years ago, # ^ |
      Vote: I like it +3 Vote: I do not like it

    2100 something people participated in last year November 2019. Such a huge increase in participation.

    • »
      »
      »
      4 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Because here in India we are observing Janta curfew an unofficial type of lock down. So all interested Indians participated. even in other parts of the world every one of them are in their home

    • »
      »
      »
      4 years ago, # ^ |
      Rev. 2   Vote: I like it -9 Vote: I do not like it

      Corona Effect

  • »
    »
    4 years ago, # ^ |
      Vote: I like it +69 Vote: I do not like it

    Maybe because everyone is at home.

    • »
      »
      »
      4 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      how much u solved? how to solve D.

      • »
        »
        »
        »
        4 years ago, # ^ |
          Vote: I like it +1 Vote: I do not like it

        There is an analysis section, you can check editorial there too. By the way D can be solved using trie, Rolling Hash, or even with segment trees.

        • »
          »
          »
          »
          »
          4 years ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          ok.

          • »
            »
            »
            »
            »
            »
            4 years ago, # ^ |
              Vote: I like it 0 Vote: I do not like it

            I solved it using Trie, felt most intuitive to me.

            • »
              »
              »
              »
              »
              »
              »
              4 years ago, # ^ |
                Vote: I like it 0 Vote: I do not like it

              yes, i see.

              • »
                »
                »
                »
                »
                »
                »
                »
                4 years ago, # ^ |
                  Vote: I like it 0 Vote: I do not like it

                Since we need some information about prefixes and not any arbitrary range, using Trie is best and a lot easier.

            • »
              »
              »
              »
              »
              »
              »
              4 years ago, # ^ |
                Vote: I like it 0 Vote: I do not like it

              Any ideas why this brute force is even passing the larger test cases as well. I mean why am I getting both test cases passed without trie etc.

              Spoiler
        • »
          »
          »
          »
          »
          4 years ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          How to solve D using segment trees?

  • »
    »
    4 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Corona

  • »
    »
    4 years ago, # ^ |
      Vote: I like it +10 Vote: I do not like it

    Besides Corona Effect, I think there's an another reason. The first problem in this Kickstart problem set was ridiculously easy so almost everyone attempted it. Otherwise, many candidates who can't come up with a remotely working solution for the first problem, simply leave the contest, without a single submission.

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

How to solve Plates (second problem) ?

  • »
    »
    4 years ago, # ^ |
      Vote: I like it +3 Vote: I do not like it

    go for knapsack type dp, pick j th plate from ith stack or leave it.

    • »
      »
      »
      4 years ago, # ^ |
      Rev. 3   Vote: I like it +3 Vote: I do not like it

      can u provide your solution please??

      • »
        »
        »
        »
        4 years ago, # ^ |
          Vote: I like it 0 Vote: I do not like it
        Spoiler
  • »
    »
    4 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Using dp.

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

I really feel stupid not noticing the 4th problem and wasted 50 minutes rejoicing. Anyone else along with me?

  • »
    »
    4 years ago, # ^ |
      Vote: I like it +8 Vote: I do not like it

    How is that even possible?

    • »
      »
      »
      4 years ago, # ^ |
        Vote: I like it +9 Vote: I do not like it

      My page size was such that it did not fit the 4th one. And I did not notice there is an option for other problems. Yeah I feel silly.

»
4 years ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

I used trie to solve the 4th problem. I personally felt that it's a feasible solution with good efficiency, though unfortunately I got WA in larger test. Is there anyone willing to take a quick look at here for me? I hope I could debug by myself, but I have no idea how to proceed since google is unwilling to release the test set even after the contest (sighed). Would be really appreciated if anyone can help :D

»
4 years ago, # |
  Vote: I like it -6 Vote: I do not like it

How much pwople going to round B?

»
4 years ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

what is wrong with my greedy approach for C

for every session to be added pick that consecutive (a,b) whose difference is maximum and add a seesion at (a+b)/2+(a+b)%2. and i did it using priority queue 1st test case passed but got WA on other.

Please help.

  • »
    »
    4 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Testcase for which your code fails is

    1

    3 2

    1 2 10

    The answer is 3 (insert 5 and 7) ,but you would get 4

»
4 years ago, # |
  Vote: I like it -6 Vote: I do not like it

How to solve problem D using trie ?

  • »
    »
    4 years ago, # ^ |
    Rev. 2   Vote: I like it +1 Vote: I do not like it
    First insert each string in the trie ,then traverse the trie starting from the head node and count the frequency of each prefix in the trie.
    
    The answer would be the sum of frequency/k for all the prefixes.
    

    Code

    • »
      »
      »
      4 years ago, # ^ |
      Rev. 3   Vote: I like it 0 Vote: I do not like it

      Will it be the sum of frequency/k or sum of valid frequency(atleast k strings possesssing that prefix). Also, when adding the frequencies, ain't we adding up the undesired frequencies too?

      for eg — rain, rainbow, rainy, rat, ra, with k=3 so r->5, ra->5, rai->3, rain->3, ra->2, rat->1, rainb->1, rainy->1...and others.

      According to me, we should add (len. of "rain")*(freq. of "rain")/k into our final answer and subtract the this frequency from previous prefixes, ie — (freq. of "rai") -= freq. of "rain" and propagate this difference to the previous prefixes.

    • »
      »
      »
      4 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      BTW, why did you use map and pushing the prefix count and later doing ans+=map[depth][i]/k instead of directly doing ans+=freq/k in the traverse() function?

      • »
        »
        »
        »
        4 years ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        Yes you are right it can be written that way as well.

        PS- This code is what I wrote during the contest so it may not be as neat as it should be.

        • »
          »
          »
          »
          »
          4 years ago, # ^ |
          Rev. 2   Vote: I like it 0 Vote: I do not like it

          I did it both ways(yours and my way) but still getting WA. I'm doing traverse thing in the fun() function.Can you check a bit this code?

»
4 years ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

Although, I did the 3rd question(Workout) using binary search, How to do it using priority_queue?

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

In problem D why does sorting and then grouping them into size of k and then finding longest common prefix for each group is not working . I wasted my 2 hours on this . Anybody help ?

  • »
    »
    4 years ago, # ^ |
      Vote: I like it +4 Vote: I do not like it

    Consider this test case

    Bundle Size = 2
    AB AC AC AD
    

    By your logic, you will group (AB, AC) and (AC, AD) with sum 2. While the correct answer is 3 by grouping (AB, AD) and (AC, AC).

    • »
      »
      »
      4 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Thank You so much for the test case .

    • »
      »
      »
      4 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      I tried every cyclic shift after sorting. Is there a counter test for that too? Or my implementation was incorrect ( I got WA xD ) ?

      • »
        »
        »
        »
        4 years ago, # ^ |
          Vote: I like it +19 Vote: I do not like it

        Consider this

        Bundle Size = 2
        AB AC AC AD AE AE
        

        In any of your cyclic shifts, you will either have (AB AC) (AC AD) (AE AE) or (AC AC) (AD AE) (AE AB) with sum 4. While the correct answer is 5 by grouping (AB AD) (AC AC) (AE AE).

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Hi everyone,

For problem 4, I implemented using Trie and passed the small test but somehow I got MLE for the large test, I spent hours trying to find out. Thank you in advance.

My code:(https://ideone.com/s8IpR6)

  • »
    »
    4 years ago, # ^ |
      Vote: I like it +4 Vote: I do not like it

    You need to free the dynamically allocated memory using delete after each test case.

    • »
      »
      »
      4 years ago, # ^ |
      Rev. 3   Vote: I like it 0 Vote: I do not like it

      Writing destructor also didn't worked for his code. There may be possibly infinite recusion or loop allocating memory indefinitely.

      • »
        »
        »
        »
        4 years ago, # ^ |
          Vote: I like it +4 Vote: I do not like it

        You're right. The actual issue was in the function print1(), which was $$$\mathcal{O}(n^2)$$$ in time and memory because it passed the string as parameter. It now ACs even without freeing memory. https://ideone.com/4U0qVM

        • »
          »
          »
          »
          »
          4 years ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          Why exactly does this work? Can you explain the intuition behind the approach?

        • »
          »
          »
          »
          »
          4 years ago, # ^ |
            Vote: I like it +1 Vote: I do not like it

          Thank you so much.

»
4 years ago, # |
Rev. 2   Vote: I like it -19 Vote: I do not like it

KickStart 2020, Round A. The limit for N of 10^5 in test set 2 which they specified in problem 1 ("Allocation") is incorrect. I am pretty sure they have a test case in test set 2 with more than 10000 houses.

Why? I was getting RE on test set 2 and I spent about 1 hour trying to find "the bug" in my program, and then finally as a last resort I decided to just extend the size of my arrays to 10^6. And the same code which I already had and which was giving me the RE, it suddenly worked fine (just with the array size changed).

Did anyone else notice this issue in test set 2?

»
4 years ago, # |
  Vote: I like it +1 Vote: I do not like it

The ranklist was filled with people who never solved more than 2-3 Problem, but guess what,today they solved a friggin trie problem...On a totally unrelated note someone sent me a picture of people discussing on whatsapp groups, but let's just ignore it :)

  • »
    »
    4 years ago, # ^ |
      Vote: I like it +3 Vote: I do not like it

    Yes, i agree. but how u know they r the same people who never solve > 3 problems. I understand there is a lot of cheating and many knows from where they r from. but what they will gain, they will get crushed if they called for interview. so chill :_)

    • »
      »
      »
      4 years ago, # ^ |
        Vote: I like it +3 Vote: I do not like it

      They will get crushed no doubt, but someone might not get a call because of these people, considering google does not call everyone.

      • »
        »
        »
        »
        4 years ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        Yes.. u r right. Google should take it seriously.

        darkshadows please convey it to google. It happened on large scale today.

        • »
          »
          »
          »
          »
          4 years ago, # ^ |
            Vote: I like it +24 Vote: I do not like it

          Google only contacts the top <100 based on previous competitions, so I doubt you can cheat your way to that high because if you need to ask for sol you probably can't code fast enough and you'd have to copy paste from someone in the top 100, and the people that high in ranking do not want to cheat. So if you're worried about cheaters taking your interview, you nor them is probably getting an interview.

          • »
            »
            »
            »
            »
            »
            4 years ago, # ^ |
              Vote: I like it +18 Vote: I do not like it

            Are you sure about the <100 thing? I had a 2 digit rank last year but wasn't invited. I know a guy who had a 500+ rank but was invited for the interview :-/

            • »
              »
              »
              »
              »
              »
              »
              4 years ago, # ^ |
                Vote: I like it +2 Vote: I do not like it

              No this is not true. My fried had around 370 rank in one ks round. He received call and cracked google too. One with 542 rank also got call. So this is not true.

              • »
                »
                »
                »
                »
                »
                »
                »
                4 years ago, # ^ |
                  Vote: I like it 0 Vote: I do not like it

                Are you sure that they didn't applied on Google's Career Page and received call?

            • »
              »
              »
              »
              »
              »
              »
              4 years ago, # ^ |
                Vote: I like it 0 Vote: I do not like it

              Maybe they were contacted regardless of performance on kick start. Like referral or just standard application.

          • »
            »
            »
            »
            »
            »
            4 years ago, # ^ |
              Vote: I like it 0 Vote: I do not like it

            Take 4 people who cooperate and parallelize work by first solving harder problems as a team (if necessary) and then coding on 4 machines in parallel and submitting everything under the same account.

            This way you can get result in top-X with zero people who have top-X skill level involved.

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

B was a really beautiful problem