Nightmare05's blog

By Nightmare05, history, 3 years ago, In English

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!!!

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

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

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

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

    Oh oops, sorry, my bad, wait a second, I will format it, using the spoiler feature for the first time

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

    Done bro, I hope it's readable now :)

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

    Agreed, use the "Block" option.

    ~~~~~
    // your code here
    ~~~~~
    

    Oh, you already updated.

    Can you describe the problem? I can't seem to open the problems

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

      Yeah bro, already did that, please refresh it once :)

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

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
  • »
    »
    3 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    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 :)

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

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

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

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

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

    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...

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

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

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

        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

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

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

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

    I think you mistakenly uploaded same image in both the links

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

      Oh yea sorry, just noticed, I am sorry, didn't have any submission on P6, so can't view it... Anyways updated :)

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

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.

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

    Can you please share the screenshot of the problem statement ?

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

    Wait oops, were we allowed to reorder the array? T_T

    I think I missed this, thanks a lot for the solution bro

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

      No, we aren't allowed to reorder the array, i have sorted the array only in the case where k < n.