Ad
  • Default User Avatar

    Try to write down the till's contents after each transation.

    Take the series of customers with bills of [25, 50, 25, 100]:

    Step 1:
    Bills in till after the transation: 1x 25
    (customer paid his ticket and did not need change)

    Step 2:
    Bills in till: 1x 50
    (customer brought the 50 and received the 25 bill as remainder)

    Step 3:
    Bills in till: 1x 50, 1x 25
    (the customer paid his 25, needed no change, so the bill goes in the till)

    Step 4:
    Bills in till: none
    (customer came with a bill of 100, the clerk is able to use the 50+25 bills to hand him the change)

    Apply the same for [25, 25, 50, 100], till contents per step are:

    1. 25
    2. 25, 25
    3. 25, 50 (the 50 bill was received now, one 25 bill was given as rest)
    4. none (both bills used as rest)
  • Default User Avatar

    You can use the equality operator (==) with the null keyword. So, if (a == null) { do things differently }

  • Default User Avatar

    @Mariam:

    After careful consideration, I am fully sure I need to check for the abs() value when sorting, to handle negative numbers in the array. That is not the issue. Thank you for your contribution :)

    However, after re-re-checking my logic, I have found a pesky off-by-one error, so I will consider my issue as moot. It wasn't test case 8's fault.

    Instead, I have discovered that none of the examples even hint that the arrays might have different sizes, they are the same size in all examples. Another thing to consider....

    @Hobovsky:

    I have. It would have been more useful if you had directly quoted the parts you thought were relevant for me. In any case, thank you, I guess.

  • Default User Avatar

    Testcase 8 is strange. The last pair is definitely NOT a root and square pair, the root of 36481 is 191, not 195.

    I am printing arrays a and b in ascending order of their abs(values).

    Log:
    0 0
    1 1
    -14 196
    19 361
    144 20736
    161 25921
    195 36481 <-- ????

    expected: but was:

  • Default User Avatar

    11 squared is 121, do the math