5 kyu

Max & Min Numbers Concatenation with Constraints

Description:

You are given:

  • an array of integers, arr , all of them positive.

  • an integer k, 2 <= k <= 4 , (amount of digits)

  • an integer s, 6 <= s <= 24 , sum value of k contiguous digits.

You have to search the maximum or minimum number obtained as a result of concatenating the numbers of the array in all possible orders but discarding the numbers having an amount of k contiguous digits which sum is higher than s.

Let's see an example:

arr = [18, 35, 76]
k = 2
s = 9
concat_max_min(arr, k, s) == [18, 3518]
# the concatened numbers that fulfill the constraint that the sum of its every 2 contiguous digits is not higher than 9 are: 18, 35, 3518 (concatened numbers)

arr = [18, 35, 76]
k = 2
s = 14
concat_max_min(arr, k, s) == [18, 763518]
# Because the concatened numbers that fulfill the constrains are:
18, 35, 76, 1835, 3518, 3576, 7618, 7635, 183576, 357618, 761835, 763518

The function will discard the numbers that their amount of digits is less than k.

arr = [18, 35, 76]
k = 3
s = 18
concat_max_min(arr, k, s) == [1835, 763518]
# all the numbers that have less than 3 digits will be discarded, now the numbers are: 1835, 3518, 3576, 7618, 7635, 183576, 357618, 761835, 763518

If s decreases, will decrease the selected concatened numbers:

arr = [18, 35, 76]
k = 3
s = 15
concat_max_min(arr, k, s) == [3518, 7618]
# the selected concatened numbers are only: 3518 and 7618

If there is only one number the function should output it:

arr = [18, 35, 76]
k = 2
s = 8
concat_max_min(arr, k, s) == [35, 35]

If there is no a single number that fulfills the conditions, the function will return an empty list:

arr = [18, 35, 76]
k = 2
s = 7
concat_max_min(arr, k, s) == []

Enjoy it!!

Fundamentals
Data Structures
Algorithms
Mathematics
Logic
Strings

Stats:

CreatedApr 20, 2016
PublishedApr 25, 2016
Warriors Trained239
Total Skips56
Total Code Submissions252
Total Times Completed42
Python Completions42
Total Stars7
% of votes with a positive feedback rating89% of 14
Total "Very Satisfied" Votes12
Total "Somewhat Satisfied" Votes1
Total "Not Satisfied" Votes1
Total Rank Assessments11
Average Assessed Rank
5 kyu
Highest Assessed Rank
4 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • raulbc777 Avatar
  • Voile Avatar
  • dfhwze Avatar
  • saudiGuy Avatar
Ad