String Permutations
Function Name: generatePermutations
Description
Write a function that takes a single string parameter and returns all possible permutations of the characters in the string.
The string will contain only unique characters and will not be empty.
The permutations can be returned in any order.
If the string is a single character, the function should return an array containing just that character.
Requirements
- The function 'generatePermutations' must accept a single parameter: a string.
- The function must return an array of strings containing all the permutations of the input string.
- All characters in the input string are unique.
- The function must handle strings of different lengths, including single-character strings.
- The function must not use any libraries or built-in permutation functions.
Examples
If the input string is 'ab', the function might return ['ab', 'ba'].If the input string is 'a', the function should return ['a'].If the input string is 'abc', the function might return ['abc', 'acb', 'bac', 'bca', 'cab', 'cba'].
Links
Matrix Spiral Copy
Thu Oct 10 2024
Write a function that takes a 2D array (matrix) as its parameter and returns a list of its elements in a spiral order.You should start from the top-left corner of the matrix, proceed to the right, and continue spiraling into the center of the matrix.The spiral order should proceed with the pattern: right -> down -> left -> up, repeating until all elements have been visited.
K-nearest Points to Origin
Sat Oct 12 2024
Write a function that finds the 'k' nearest points to the origin (0, 0) in a 2D plane. The points are provided as a list of tuples (x, y), representing the cartesian coordinates of the points. You should return a list of 'k' tuples that are closest to the origin, sorted by their Euclidean distance from the origin. In case of a tie in distances, sort the points by their x-coordinates, and if those are the same, by their y-coordinates.