HackerRank : Week of Code 34 – Once in a tram

By | July 17, 2017
Once in a tram: Hackerrank

Once in a tram : One day, Jack was going home by tram. When he got his ticket, he noticed that number on the ticket was not lucky. A lucky ticket is a six-digit number on the ticket in which sum of the first three digits is equal to the sum of the last three digits.

For example, number 165912 is lucky because sum of , and .

Since the number on the ticket wasn’t lucky, Jack needs your help to find the next lucky ticket number.

For example, if Jack’s ticket number is 165901, then the next lucky ticket number is 165903.

Given Jack’s current ticket number, find and print the next lucky ticket number.

Input Format

The first line contains an integer, , denoting the  number on the ticket.

Constraints

Output Format

For the given input find and print the next lucky ticket number.

Sample Input 0

555555

Sample Output 0

555564

Explanation 0

After  the first lucky number is , where the sum of first three digits  is equal to the sum of last three digits .

Solution

Brute force works here. Need to look for test scenarios. Need some logic to deduce.