In this post, we will solve the Separate the Numbers HackerRank Solution. This problem (Separate the Numbers) is a part of the HackerRank Problem Solving series.
A numeric string, s , is beautiful if it can be split into a sequence of two or more positive integers, a, a, …, a[n] , satisfying the following conditions:
- a[i] – a[i-1] = 1 for any 1<i<=n (i.e., each element in the sequence is 1 more than the previous element).
- No a[i] contains a leading zero. For example, we can split into the sequence , but it is not beautiful because and have leading zeroes.
- The contents of the sequence cannot be rearranged. For example, we can split into the sequence , but it is not beautiful because it breaks our first constraint (i.e., ).
The diagram below depicts some beautiful strings:
Perform queries where each query consists of some integer string . For each query, print whether or not the string is beautiful on a new line. If it is beautiful, print
YES x, where is the first number of the increasing sequence. If there are multiple such values of , choose the smallest. Otherwise, print
Complete the separateNumbers function in the editor below.
separateNumbers has the following parameter:
- s: an integer value represented as a string
– string: Print a string as described above. Return nothing.
The first line contains an integer , the number of strings to evaluate.
Each of the next lines contains an integer string to query.