Ad
  • Default User Avatar

    x is a string, therefore x + 1 is also a string. instead of 29 + 1 (=== 30) you do '29' + '1' (=== '291')

    even if you correct this, your approach wont work on large arrays, you should think of another algorithm (or another datatype)