Ad
  • Custom User Avatar

    Also closing as this issue is a duplicate of this one

  • Custom User Avatar
  • Custom User Avatar

    Hey, an interesting scenario, but this should be treated the same way as any other. Let's say we have an array [-5, 10, 8, 10, 2, -3, 10]; as you can see there are 3 occurences of 10, but still the algorithm works the same way: the greatest is 10, so it goes in the middle, the next greatest is 10, so it goes on both sides, then 10 again on both sides, and after that the other numbers accordingly, resulting in [-5, -3, 2, 8, 10, 10, 10, 10, 10, 8, 2, -3, -5]. I added this to the tests for clarity nevertheless.

  • Custom User Avatar

    In the test cases where there are 1000 elements or more in the data array, the max number may not be unique. For example, if the max in the array is 1000, there can be multiple 1000s.

    This raises a question about how we should deal with the existence of multiple max numbers:
    Should we take them as just one element?
    Should we place the group of max numbers in the middle, and then arrange the rest of numbers in the mirroring fashion?

    Moreover, we may have an odd or even number of max numbers. Under the requirement of returning an array with an 'odd' number of elements in it, things can get more complicated.

    This possibility of having multiple max numbers and how it should be handled should be mentioned in the description, and the test cases may need to be reexamined as well.

  • Default User Avatar

    I agree. I think most people (including myself) approached the problem as if a number in the array had to be divisible by its index, but this doesn't work correctly for index zero as we cannot divide by zero. However, as you suggested, zero is a multiple of every number, including itself. I agree that if zero appears at the zeroth index it is a valid multiple and should probably be included.

  • Custom User Avatar

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