Unique Paths Calculator
Function Name: countUniquePaths
Description
Create a function that calculates the number of unique paths from the top-left corner to the bottom-right corner of a m x n grid. The only movements allowed are to move right or down at any given point. The function will take two parameters: the number of rows (m) and the number of columns (n). It should return the number of unique paths possible.
Constraints:
1. You may not use any third-party libraries.
2. Optimize the function for time complexity.
3. Extra challenge: Use only O(n) extra space for the solution, where n is the number of columns.
Requirements
- The function must be named 'countUniquePaths'.
- The function must accept two integer parameters, 'm' and 'n'.
- The function must return an integer representing the number of unique paths.
- The function must handle grids of at least size 1x1 up to 100x100.
Examples
Example 1:countUniquePaths(2, 2) should return 2. (Two paths: right -> down or down -> right)Example 2:countUniquePaths(3, 3) should return 6. (Right -> Right -> Down -> Down, Right -> Down -> Right -> Down, Right -> Down -> Down -> Right, Down -> Right -> Right -> Down, Down -> Right -> Down -> Right, Down -> Down -> Right -> Right)
Links
Anagram Detector
Thu Sep 19 2024
Write a function that checks whether two given strings are anagrams of each other. An anagram is a word or phrase that is made by rearranging the letters of another word or phrase. For example, 'heart' and 'earth' are anagrams.
Circular Queue Implementation
Sat Sep 21 2024
Implement a Circular Queue data structure using an array. The circular queue should support the following operations: enqueue, dequeue, peek, and isEmpty.The enqueue operation should add an item to the back of the queue if there is space. If the queue is full, it should return 'Queue Full'.The dequeue operation should remove an item from the front of the queue and return it. If the queue is empty, it should return 'Queue Empty'.The peek operation should return the item at the front of the queue without removing it. If the queue is empty, it should return 'Queue Empty'.The isEmpty operation should check if the queue is empty and return a boolean value.