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

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

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
  • Проголосовать: не нравится

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

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

»
5 лет назад, скрыть # |
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
  • »
    »
    5 лет назад, скрыть # ^ |
     
    Проголосовать: нравится 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 :)

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

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

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

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

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

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

»
5 лет назад, скрыть # |
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.