Matrix Spiral Copy
Function Name: spiralCopy
Description
Write a function that takes a 2D array (matrix) as input and returns a list of its elements in a spiral order. Start at the top-left corner of the input 2D array, go right and traverse the boundaries of the matrix in a clockwise spiral order, collecting elements until every element has been visited.
Requirements
- The function should take a single parameter: a 2D array of integers
- The matrix can be of any size, including empty and rectangular shapes
- You must collect elements in a clockwise spiral order: right, down, left, then up, and repeat
- Once an element is collected, it cannot be collected again
- Return a list of integers in the order that they were collected
- Do not mutate the original matrix
- Implement the spiral traversal without using any libraries that can perform the operation automatically
- The function should handle edge cases, such as single row, single column, and empty matrix inputs
Examples
Given matrix: [[1, 2, 3], [4, 5, 6], [7, 8, 9]], the function should return [1, 2, 3, 6, 9, 8, 7, 4, 5].Given matrix: [[1], [2], [3]], the function should return [1, 2, 3].Given matrix: [[1, 2, 3, 4, 5]], the function should return [1, 2, 3, 4, 5].
Links
Anagram Detector
Sun Sep 01 2024
An anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once. For example, the word 'listen' is an anagram of 'silent'.Your task is to write a function 'areAnagrams' that takes two strings as parameters and returns a Boolean value. The function should determine whether the two strings are anagrams of each other, considering letter case and ignoring whitespace and punctuation.
Merge Intervals
Tue Sep 03 2024
Write a function that merges overlapping intervals. The function should take an array of intervals, where each interval is represented as an array of two integers, and merge all overlapping intervals. The input array of intervals is not necessarily ordered in any way. The function should return an array of the merged intervals sorted in ascending order by the start of the intervals.