Ad
  • Custom User Avatar
    • 20 sees only 30, and therefore can be the lowest value (1)
    • 30 sees 20 and 40, and must be higher than 20 (1), and is therefore (2)
    • 40 sees 30 and 30, and must be higher than both, but we do not yet know what the value of the 30 at index 3 is

    It's not that the second 30 takes precedence exactly, it's that the team that scored 40 must be higher than both of its neighbours - and the second 30 can be deduced to have a value of 3... but as you've discovered, not by taking into account only the information on its left hand side.

    How might we figure that out?

  • Default User Avatar

    However, i am missing the point on this testcase

    [20, 30, 40, 30, 20, 10]), 13

    13 would result from this
    [1 2 4 3 2 1]

    is tht right?
    if that is so, then 20 has no visibility, so it will get a 1
    30 can see 20, so it will be 1+1 = 2
    40 can see 30 on its left and 30 on its right
    However it seems that the 30 on its right takes precedence.... why? is there still something i am
    not seeing?
    Thanks again and regards
    Marco

  • Default User Avatar

    your explanation is v clear. by adjacent i inferred only the team before..not the team before and the one after.my bad.rhanks for following up

  • Custom User Avatar

    As said in description:

    A team can know the bonus amount of its adjacent team, if the
    score of the adjacent team is lower than itself.

    This means the first team (team who scored 30) will know the bonus amount of the second team (team who scored 20), the second team will know the amount of bonus from the third team (team who scored 10). Also said in description that:

    If a team finds that its bonus is no higher than the adjacent team whose
    score is lower than itself, the team will not be satisfied

    First we know that the third team knew none of the other teams' score, therefore they get the lowest of 1 bonus. Secondly, the second team knew the score of third team (which means second team have a higher amount of score), therefore they needed a bonus amount higher than 1, which is 2. We can also use the same logic to get the amount of bonus for the first team, they needed a bonus higher than 2, which is 3. Then we add all the bonuses together to get:

    1+2+3=6k, so the answer is 6 for minimum bonus. Sorry if my explaination isn't clear enough :)

  • Default User Avatar

    HI guys
    sorry, for this testcase [30, 20, 10] why should the minimum bonus be 6?
    the first team does not know, so it gets 1k, the second team does not know, so it gets 1k
    and the third team does not know, so it should get 1k.
    Where does the 6 come from ? nobody in this sequence will know the amout of the adjacent?
    Kind regarsd
    marco

  • Default User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Default User Avatar

    sorry guys i dont undestand. I am given a query function,but i dont know N at all. where do i get N from?
    Kind regards
    Marco

  • Default User Avatar

    Hi all
    uhm i am seeking some hints here as my code runs out of time
    So i take it i'd need to use an efficient algo to find the prime factors, and once i have the prime factors i can then generate divisors out of prime factors,.
    Sort of two loops,where the first one is 'expensive' and the second one should be a 'small one'
    Giving my code is runnign out of time i am guessing my prime factorization code is deficient...
    is there a formula somewhere to find prime factors?
    Kind regars
    Marco

  • Default User Avatar

    Great! thanks! i think i figured it out on paper by just observing relationship between runs of the algo for 1..10 and it looks like another well known series .
    I cant believe this is pure coincidence.. would you mind sending me some useful links on this
    to my private email mmistroni@gmail.com ?
    Many thanks for putting me on the right track!
    moderator feel free to ban this comment if it gives the solution away
    kind regards

  • Custom User Avatar

    You're on the right track thinking about recursive algorithms and your deductions so far are almost correct. If permutations(5) is made up of (5-1) == 4 branches as you say, each having 11 leaves, how might we derive that number 11? You say it's permutation(n-1) - <something> but permutations(5-1) == permutations(4) == 9 as you say, which is smaller than 11... so something is being added, not subtracted.

  • Default User Avatar

    Hi all
    am a little bit rusty on math and i need a starting point
    Have kicked off a brute force algo, can see that for
    n=4 we have 9 possible permutations, 3 starting with 2, 3 starting with 3 and 3 starting with 4
    n=5 we have 44 possibilties, 11 starting with 2, 11 starting with 3, 11 starting with 4, and 11 starting with 5
    so the number of permutations are always the same for 1 < i <=n, which seems to be
    permutation(n-1) - "something which i can figure out"

    Could anyone give me a trace without exposing to much?
    Kind regars
    Marco

  • Custom User Avatar

    I believe this is the 2kyu kata for anyone interested https://www.codewars.com/kata/evaluate-mathematical-expression/

  • Custom User Avatar

    Duplicate of a 2 kyu kata, except without parentheses. I can literally copy-paste my JS or Python solution from the 2 kyu one and paste here and it will immediately pass.

  • Default User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Default User Avatar

    Many thanks, understood!
    kind regards

  • Loading more items...