Problem Statement
When John and Brus were high school students, they liked to investigate integer sequences. Once, John wrote down a sequence containing only positive integers. Brus wanted to change the sequence so it contained only "lucky" numbers. Brus considered a number lucky only if it was evenly divisible by 4 or 7 (or both). (Note that 0 is a lucky number by this definition.) For each number x in John's sequence, Brus did the following. If x was lucky, he did not change it. Otherwise, he replaced x with a lucky number y (not necessarily positive) such that the absolute value of the difference between x and y was minimal. If there were two such values for y, he chose the smaller one.
You are given an int[] sequence containing John's original sequence. Return the sequence after Brus made all his changes.
Definition
- Class:
- TheSequencesLevelOne
- Method:
- find
- Parameters:
- int[]
- Returns:
- int[]
- Method signature:
- int[] find(int[] sequence)
- (be sure your method is public)
Constraints
- sequence will contain between 1 and 50 elements, inclusive.
- Each element of sequence will be between 1 and 1,000,000,000, inclusive.
Examples
{1, 2, 3, 4, 5, 6, 7}Returns: {0, 0, 4, 4, 4, 7, 7 }{1000000000, 999999995}Returns: {1000000000, 999999994 }When replacing 999999995, Brus has two choices: 999999996, which is divisible by 4, and 999999994, which is divisible by 7. Brus will choose 999999994 because it is smaller.{4, 7, 7, 4}Returns: {4, 7, 7, 4 }Here Brus will not change any number.{44, 47, 77, 74, 474, 444, 747, 7777777}Returns: {44, 48, 77, 72, 472, 444, 748, 7777777 }