Advertisement
Guest User

Untitled

a guest
Aug 20th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. Beautiful numbers
  2.  
  3. A beautiful number is one divisible by 5, 6 and 8.
  4.  
  5. Given an array containing the number of times each digit can be used, find the largest beautiful number that can be formed and return it in RLE compressed version.
  6.  
  7. Rules:
  8. - The digit array contains 10 elements. The element at position i corresponds to the number of times i can be used as a digit in the newly formed number.
  9. - You do not have to use all available digits.
  10. - You are not allowed to use extra digits, meaning that the maximum number of occurrences of a digit in the formed number cannot exceed the number in the corresponding position in the digit array.
  11. - You are not allowed to use leading zeros.
  12. - RLE encoding replaces each sequence of a same character in a string with the length of a sequence and the character. For example, "111559995" will be encoded as "31253915".
  13. - If it is impossible to form such number from the given array, return "Impossible".
  14.  
  15. Example:
  16. digits = {3,1,0,0,0,0,0,0,1,0} (Meaning we can use the following numbers: 0,0,0,1,8)
  17. The largest beautiful number that can be formed is 81000.
  18. The RLE compressed version of "81000" is "181130".
  19.  
  20.  
  21. Input parameters:
  22. digits - An array containing the number of times each digit can be used
  23.  
  24. Constraints:
  25. digits will contain 10 elements
  26. each element will be between 0 and 10 000 000 (inclusive)
  27.  
  28. Return value:
  29. The largest beautiful number in RLE compressed format as a string or "Impossible" if it is not possible to form a beautiful number.
  30. Class Name:
  31. BeautifulNumbers
  32.  
  33. Method signature:
  34. public String findLargestBeautifulNumber(int[] digits)
  35.  
  36. Test Case 1:
  37. findLargestBeautifulNumber({1,1,0,1,0,1,0,1,0,1}) = "10"
  38.  
  39. Test Case 2:
  40. findLargestBeautifulNumber({10,1,0,0,0,0,0,0,1,0}) = "1811100"
  41.  
  42. Test Case 3:
  43. findLargestBeautifulNumber({0,0,17,0,18,18,14,0,13,8}) = "Impossible"
  44.  
  45. Test Case 4:
  46. findLargestBeautifulNumber({142,0,0,117,0,27,7,104,0,180}) = "180910477626511731420"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement