Skip to content

Latest commit

 

History

History
85 lines (64 loc) · 2.84 KB

range_of_integers_in_an_unsorted_string.md

File metadata and controls

85 lines (64 loc) · 2.84 KB

In this kata, your task is to write a function that returns the smallest and largest integers in an unsorted string. In this kata, a range is considered a finite sequence of consecutive integers.

Input

Your function will receive two arguments:
  • A string comprised of integers in an unknown range; think of this string as the result when a range of integers is shuffled around in random order then joined together into a string
  • An integer value representing the size of the range

Output

Your function should return the starting (minimum) and ending (maximum) numbers of the range in the form of an array/list comprised of two integers.

Test Example

input_string = '1568141291110137'

mystery_range(input_string, 10) # [6, 15]

# The 10 numbers in this string are:
# 15 6 8 14 12 9 11 10 13 7
# Therefore the range of numbers is from 6 to 15
let inputString = '1568141291110137';

mysteryRange(inputString, 10) // [6, 15]

// The 10 numbers in this string are:
// 15 6 8 14 12 9 11 10 13 7
// Therefore the range of numbers is from 6 to 15
inputString := "1568141291110137"
MysteryRange(inputString, 10) // [6 15]

// The 10 numbers in this string are:
// 15 6 8 14 12 9 11 10 13 7
// Therefore the range of numbers is from 6 to 15
# For Elixir, return a tuple
input_string = "1568141291110137"

KataSolution.mystery_range(input_string, 10) # {6, 15}

# The 10 numbers in this string are:
# 15 6 8 14 12 9 11 10 13 7
# Therefore the range of numbers is from 6 to 15
string input_string = "1568141291110137";
KataSolution.MysteryRange(input_string, 10); // [6, 15]

// The 10 numbers in this string are:
// 15 6 8 14 12 9 11 10 13 7
// Therefore the range of numbers is from 6 to 15
input_string = '1568141291110137'

mystery_range(input_string, 10) # [6, 15]

# The 10 numbers in this string are:
# 15 6 8 14 12 9 11 10 13 7
# Therefore the range of numbers is from 6 to 15

Technical Details

  • The maximum size of a range will be 100 integers
  • The starting number of a range will be: 0 < n < 100
  • Full Test Suite: 21 fixed tests, 100 random tests
  • Use Python 3+ for the Python translation
  • For JavaScript, require has been disabled and most built-in prototypes have been frozen (prototype methods can be added to Array and Function)
  • All test cases will be valid

If you enjoyed this kata, be sure to check out my other katas