scope_'s blog

By scope_, history, 3 years ago, In English

Problem

  • Vote: I like it
  • -21
  • Vote: I do not like it

| Write comment?
»
3 years ago, # |
  Vote: I like it +5 Vote: I do not like it

hmmm... i think if you could give us the link to the problems judge, it would've been a lot easier... :)

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

An efficient way of solving this problem(instead of O(n)). Can you provide the link to the ques so that i can verify my ans?

My Code

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

    Sorry, this problem appears in the OA of ByteDance So, I don't have a link. But Could you PLz Explain your Approach Thanks.

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

      Instead of allocating memory for each second i.e O(n) we can directly make a jump of i seconds. we choose that value of i after which the maxm(m1,m2) changes.

      we will remove i' units i.e sum of n natural numbers upto i — (already removed units upto prev. seconds).

      i is calculated using quadratic equation i*(i+1)/2=difference reqd.