Ad
  • Custom User Avatar

    You misunderstood the problem.

    The "needle" string is given to you as the argument str. The "haystack" string is not given to you as an explicit value, but it is fixed, has a predetermined, well known form: it's a string created by concatenation of all narural numbers. It starts with "12345678910111213" and continues up to infinity, or, if you prefer, as long as you need to find in it all numbers given to you as inputs.

    As said above, the indexOf will not work well for this problem, because the haystack is very, very, very large. If you want to, you can try to create it with string.Join("", Enumerable.Range(1, Infinity)), which, obviously, will not work, because there is not enough memory to build such a large string (you can replace the Infinity with a sufficiently large numeric value, but it will be still too much to build such string).

    The whole trick to this difficult task is to not build the haystack, but to exploit its well known structure and find the answer without building the long string.

  • Custom User Avatar

    cause I created a string on my own

    Did you just create any string you wanted? Well then it's wrong. The string (part of it) is given to you, but you have to expand it yourself. It's numbers from 1 to infinity, joined together in a string. Note that using this method, you will eventually run out of memory.

  • Custom User Avatar
  • Custom User Avatar

    But it should be clear in the description that the input is not the percentage value. it can be missinterpreted.

    OK. i changed description to say percentages of the total...

  • Custom User Avatar

    You need to represent the percentage of each element. For example, if the 6 values are [0, 2, 1, 2, 2, 3], then the percentages would be [0%, 20%, 10%, 20%, 20%, 30%] respectively.