ErolKZ

Untitled

Apr 6th, 2022
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.49 KB | None | 0 0
  1. Task 1:
  2.  
  3. Write an efficient program to return the duplicate characters from given String, for example, if given String is "C++" then your program should print "+" Similarly, if the input is "Java and JavaScript" then your program should print "J", "a" and "v". User Input is not case sensitive z = Z.
  4.  
  5. Extra not-mandatory subtask:
  6.  
  7. Also print the count of occurrences next to the duplicate characters:
  8.  
  9. Input -> Java and JavaScript
  10.  
  11. Output -> “j” occurs 2 times,
  12. “a” occurs 5 times,
  13. “v” occurs 2 times
  14.  
  15. Task 2:
  16.  
  17. Given two non-empty arrays of integers, write a function that determines whatever the second array is a subsequence of the first one.
  18.  
  19. A subsequence of an array is a set of numbers that aren`t necessarily adjacent in the array, but that are in the same order as they appear in the array.
  20.  
  21. For example:
  22.  
  23. the numbers [1,3,4] form a subsequence of the array [1, 2, 3, 4], and so do the numbers [2, 4].
  24.  
  25. Note that a single number is an array and the array itself are both valid subsequences of the array.
  26.  
  27. Sample Input:
  28.  
  29. Array to check -> 5,1,22,25,6,-1,8,10
  30. Sequence to check if is subsequence of the array -> 1,6,-1,10
  31.  
  32. Sample output:
  33.  
  34. True
  35.  
  36. Extra not-mandatory subtask:
  37.  
  38. Modify the method so that it accepts one modifier that changes the logic (adjacent). If this modifier is given by the user a subsequence is valid only when its numbers are contained in the array, in the same order and are adjacent.
  39.  
  40. Sample Input:
  41.  
  42. Array to check -> 5,1,22,25,6,-1,8,10
  43. Sequence to check if is subsequence of the array -> 1,6,-1,10,adjacent
  44.  
  45. Sample output:
  46.  
  47. False
  48.  
  49.  
  50.  
  51. Task 3:
  52.  
  53. Purple vs Brown is a game played on a 2D grid that in theory can be infinite (in our case we will assume that x <= y < 1 000).
  54.  
  55. Each cell on this grid can be either Purple (represented by 1) or Brown (represented by 0) The game always receives an initial state of the grid which we will call “Generation Zero”. After that, a set of 4 rules are applied across the grid and those rules form the next generation.
  56.  
  57. Rules that create the next generation:
  58.  
  59. 1. Each Brown cell surrounded by exactly 3 or exactly 6 Purple cells will also become Purple in the next generation.
  60.  
  61. 2. A Brown cell will stay Brown in the next generation if it has either 0, 1, 2, 4, 5, 7 or 8 Purple neighbors.
  62.  
  63. 3. Each Purple cell surrounded by 0, 1, 4, 5, 7 or 8 Purple neighbors will become Brown in the next generation.
  64.  
  65. 4. A Purple cell will stay Purple in the next generation if it has either 2, 3 or 6 Purple neighbors.
  66.  
  67.  
  68.  
  69. Important facts:
  70. - Each cell can be surrounded by up to 8 cells 4 on the sides and 4 on the corners. Exceptions are the corners and the side of the grid.
  71. - All the 4 rules apply at the same time for the whole grid for the next generation to be formed.
  72.  
  73.  
  74.  
  75. Your Task:
  76. Create a program that accepts:
  77. - The size of our grid - X, Y (X being the width and Y being the height)
  78. - Then the next Y lines should contain strings (each string is long X characters) created by O`s and 1`s which will represent the “Generation Zero” state and help us build the grid
  79. - The last arguments to the program should be coordinates (X1 and Y1) and the number N.
  80.  
  81.  
  82.  
  83. (X1 and Y1) will be coordinates of a cell in the grid We would like to calculate in how many generations from Generation Zero until generation N this cell was Purple. (The calculation should include generation Zero and generation N)
  84.  
  85.  
  86.  
  87. Print your result in the console.
  88.  
  89.  
  90.  
  91. Example 1: 3x3 grid, in the initial state, the second row is all 1s. how many times will the cell (1. 0) (top center) become Purple in 10 turns?
  92.  
  93.  
  94.  
  95. 3,3
  96.  
  97. 000
  98.  
  99. 111
  100.  
  101. 000
  102.  
  103. 1,0,10
  104.  
  105. expected result: 5
  106.  
  107.  
  108.  
  109. Example 2: 4x4 grid. Input:
  110.  
  111.  
  112.  
  113. 4,4
  114.  
  115. 1001
  116.  
  117. 1111
  118.  
  119. 0100
  120.  
  121. 1010
  122.  
  123. 2,2,15
  124.  
  125. expected result: 14
  126.  
  127.  
  128.  
  129. Notes:
  130.  
  131. Try using the four fundamental OOP principles while solving the tasks, where appropriate.
  132.  
  133. No frameworks needed, use plain JAVA / C# or any other OOP capable language, without external libraries.
  134.  
  135. Use only the console for Input and output.
  136.  
  137. Implement validations of the user input.
  138.  
  139. Format the code to your preferences to improve readability.
  140.  
  141. Put comments in the code to improve readability.
  142.  
  143. Use appropriate and descriptive names when naming variables and functions.
  144.  
  145. Try avoiding code lines longer than 125 characters.
  146.  
  147. Use GitHub or BitBucket for VCS.
  148.  
  149. Start small and iterate to improve your code.
Advertisement
Add Comment
Please, Sign In to add comment