Guest User

Untitled

a guest
Apr 24th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. Problem Statement for DNAString
  2. Problem Statement
  3. A string of length L is called periodic with period p if the i-th character is equal to the (i+p)-th character for all i between 0 and L-p-1, inclusive. For example, the strings "CATCATC", "CATCAT", "ACTAC" and "ACT" are all periodic with period 3.
  4.  
  5.  
  6.  
  7. You are given a String[] dna. Concatenate the elements of dna and return the minimum number of replacements needed to make the resulting string periodic with period less than or equal to maxPeriod. Each replacement consists of changing a single character from one letter to any other letter.
  8.  
  9. Definition
  10.  
  11. Class: DNAString
  12. Method: minChanges
  13. Parameters: int, String[]
  14. Returns: int
  15. Method signature: int minChanges(int maxPeriod, String[] dna)
  16. (be sure your method is public)
  17.  
  18.  
  19. Constraints
  20. - dna will contain between 1 and 50 elements, inclusive.
  21. - Each element of dna will contain between 1 and 50 characters, inclusive.
  22. - Each character in dna will be 'A','C','G' or 'T'.
  23. - maxPeriod will be between 1 and n, inclusive, where n is the number of characters in the concatenated string.
  24.  
  25. Examples
  26. 0)
  27.  
  28.  
  29. 3
  30.  
  31. {"ATAGATA"}
  32.  
  33. Returns: 1
  34.  
  35. Here, we only need one replacement to make the string periodic with period 2. Replace the 'G' with a 'T': "ATATATA".
  36. 1)
  37.  
  38.  
  39. 2
  40.  
  41. {"ACGTGCA"}
  42.  
  43. Returns: 3
  44.  
  45. With 3 replacements we get the string ACACACA with period 2.
  46. 2)
  47.  
  48.  
  49. 13
  50.  
  51. {"ACGCTGACAGATA"}
  52.  
  53. Returns: 0
  54.  
  55. Here there is no need to change anything since our string already has period 13.
  56. 3)
  57.  
  58.  
  59. 1
  60.  
  61. {"AAAATTTCCG"}
  62.  
  63. Returns: 6
  64.  
  65. The best way to do this is to replace all non-'A' characters with 'A's.
  66. 4)
  67.  
  68.  
  69. 12
  70.  
  71. {"ACGTATAGCATGACA","ACAGATATTATG","ACAGATGTAGCAGTA","ACCA","GAC"}
  72.  
  73. Returns: 20
Add Comment
Please, Sign In to add comment