Advertisement
satishfrontenddev5

Untitled

Feb 19th, 2024
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Problem Statement
  2.  
  3. You are given a green and blue image, image.
  4.  
  5. Character j of element i (both e-based indices) of image represents the pixel in row i, column j. 'X' characters represent green pixels and '.
  6.  
  7. characters represent blue pixels. crops, which contains a series of rectangular crop operations that are performed on the image. Cropping is an operation that trims an image so that only the specified area of the original image remains.
  8.  
  9. Each element of crops is formatted as "rl cl r2 c2" (quotes for clarity only), where the upper left corner of the area to crop is at row r1, column cl, and the lower right corner is at row r2, column c2. The coordinates are inclusive.
  10.  
  11. The crop operations are performed in the order that they appear in crops, and each one is performed on the most recent version of the image.
  12.  
  13. The constraints will guarantee that all crop operations will be within the boundaries of the image.
  14.  
  15. Return the final cropped image as a string[] in the same format as the original image string[].
  16.  
  17. Constraints
  18.  
  19. • Image will contain between 1 and 50 elements, inclusive.
  20.  
  21. • Each element of image will contain between 1 and 50 characters, inclusive.
  22.  
  23. • Each element of image will contain exactly the same number of characters.
  24.  
  25. • Each element of image will contain only '.' and uppercase 'X' characters. • Crops will contain between 1 and 10 elements, inclusive.
  26.  
  27. Each element of crops will be formatted as described in the problem statement and no integers within crops will contain
  28.  
  29. extra leading zeros. • Within each element of crops, r2 will be greater than or equal to r1 and c2 will be greater than or equal to c1.
  30.  
  31. • Crops will contain no operations that exceed the boundaries of the image at any time in the cropping process.
  32.  
  33. Examples
  34.  
  35. • input:
  36.  
  37. • 4
  38.  
  39. ["......"],
  40.  
  41. ".....X....",
  42.  
  43. "....."]
  44.  
  45. 2 (crops length)
  46.  
  47. ["1 0 2 8", "0 0 1 1"] Returns: ["X.", ".." ]
  48.  
  49. Explanation
  50.  
  51. The first crop effectively removes the top and bottom rows of the image and results
  52.  
  53. in:
  54.  
  55. The second crop is then performed
  56.  
  57. relative to the new image:
  58.  
  59. . X.
  60.  
  61.  
  62.  
  63.  
  64. Output:-
  65.  
  66.  
  67. function printhello(image, crops) {
  68.    for (const crop of crops) {
  69.        const [r1, c1, r2, c2] = crop.split(" ").map(Number);
  70.        for (let i = r1; i <= r2; i++) {
  71.            image[i] = image[i].substring(0, c1) + image[i].substring(c2 + 1);
  72.        }
  73.    }
  74.    return image;
  75. }
  76.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement