Ad
  • Custom User Avatar

    Of course you don't NEED to iterate through. It's a really quick solution to a really quick problem, that's why it's good. The Intstream solution takes 1.3s if the input is 1 billion, but since the tests were way smaller, that ain't a problem. If coding a real project, then of course everyone should think twice if their solution is really the most efficient or not. Here it's not necessary.

  • Custom User Avatar

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

  • Custom User Avatar

    Because the array itself can't be multiplied or added. You want to use the values inside the array to build another array to return.

  • Custom User Avatar

    why are you modifying the input array? it doesn't say we want to change the data of the input, just return an array based on the data from the input.

  • Custom User Avatar

    Your solution is probably too inefficient. They probably have a cap on the callstack higher than your computer since it's doing the computing on their servers, and with recursion, inefficient solutions means stacking operations. To fix this, try using an iterative solution or figuring out what the O(1) solution is.

  • Custom User Avatar

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

  • Custom User Avatar

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

  • Custom User Avatar

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