Блог пользователя Nightmare05

Автор Nightmare05, история, 4 года назад, По-английски

Hi guys,

I gave the Newton's coding challenge held today and could solve only 4, I got 15+ WAs on 5th and couldn't solve the 6th problem. Can anyone please tell me the solution for the last problem and if possible tell me the error in my code for 5th problem?

Also feel free to use the comment section to discuss other solutions as well.

Please visit this link to see a screenshot of the problem statement of P5

My Code For P5

I would be really thankful if someone can point out, exactly what edge cases did I miss!

Cheers!!!

  • Проголосовать: нравится
  • -3
  • Проголосовать: не нравится

»
4 года назад, # |
  Проголосовать: нравится +13 Проголосовать: не нравится

Dude, please format your code, it's totally screwed up as of now

»
4 года назад, # |
Rev. 2   Проголосовать: нравится +1 Проголосовать: не нравится

How did you guys do 3rd one? I did it by tracing back the parent in each step by binary search. Is there an easy to implement solution or observation that simplifies the problem ?

PROBLEM STATEMENT
CODE
  • »
    »
    4 года назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    Yes, bro I have a faster solution without binary search, since the number of children follows a nice ratio, binary search wasn't really needed!

    My Solution for P3

    Hope it helps :)

  • »
    »
    4 года назад, # ^ |
    Rev. 3   Проголосовать: нравится 0 Проголосовать: не нравится
    Code

    Here's mine, I stored the number of nodes in each level and traced back the parent using that information.

»
4 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Can you share the SS of the problem statement? You can get it in my submissions section.

  • »
    »
    4 года назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    Bro, what site do you use to host the image?

    I uploaded it on imgbb, but it's not loading as an image as it should be...

    • »
      »
      »
      4 года назад, # ^ |
      Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

      Did you check this ?Upload the pic on this site and then once upload is complete scroll down to find the HTML embed code

      • »
        »
        »
        »
        4 года назад, # ^ |
          Проголосовать: нравится 0 Проголосовать: не нравится

        I just have to copy the url of the hosted image right?

        Anyways, I have already posted the link to the screenshot, I hope for now that would suffice

»
4 года назад, # |
  Проголосовать: нравится +1 Проголосовать: не нравится

Auto comment: topic has been updated by Nightmare05 (previous revision, new revision, compare).

»
4 года назад, # |
Rev. 3   Проголосовать: нравится +5 Проголосовать: не нравится

Last Problem

  1. For (k < n), add (k+1)th smallest element to all the elements to its left(in sorted array), so now all the elements have value greater than the (k+1)th element, so (k+1)th element will be our final answer.

  2. Otherwise choose two index i and i+1 such value of (A[i] + A[i+1]) is maximum, then perform (k-(n-1)) operations on this pair, let say this pair is (x, y). After performing k-(n-1) operations on it, add the maximum among them(after operations) to the rest of the (n-1) elements, let suppose (x > y) after (k-(n-1)) operations, then add x to rest of the (n-1) elements, so now x is smallest element after all the k operations, which is the maximum possible.