Simple Change Counter
Function Name: calculateChange
Description
Create a function named 'calculateChange' that takes an amount of money (in cents) and returns the minimum number of coins that make up that amount. Assume that the available coins are quarters (25 cents), dimes (10 cents), nickels (5 cents), and pennies (1 cent). The function should return an object/dictionary with the denomination of the coin as the key and the amount of each coin as the value.
Requirements
- The function should have one parameter: an integer representing the amount in cents.
- The function must return an object/dictionary with the keys 'quarters', 'dimes', 'nickels', and 'pennies'.
- Optimize the function to minimize the total number of coins returned.
- Handle cases where the amount is zero or less than zero.
- Include error handling for non-integer inputs.
Examples
Example 1: calculateChange(99) should return { 'quarters': 3, 'dimes': 2, 'nickels': 0, 'pennies': 4 }.Example 2: calculateChange(31) should return { 'quarters': 1, 'dimes': 0, 'nickels': 1, 'pennies': 1 }.Example 3: calculateChange(-5) should return { 'quarters': 0, 'dimes': 0, 'nickels': 0, 'pennies': 0 }.Example 4: calculateChange('Hello') should throw an error or return a meaningful message indicating invalid input.
Unique Paths in Grid
Sat Oct 19 2024
Write a function `countUniquePaths` that calculates the number of unique paths from the top-left corner to the bottom-right corner of a MxN grid. However, there are some 'obstacles' represented by a 1 placed in some cells. The function should take two parameters: `m` and `n` representing the dimensions of the grid, and `obstacles` a 2D array where `obstacles[i][j] == 1` means there's an obstacle on the (i, j) cell.The robot can only move either down or right at any point in time. If it encounters an obstacle, it cannot move further in that direction. If it's at the edge of the grid, it can only move in the direction that doesn't take it out of bounds.
TicTacToe Validator
Mon Oct 21 2024
Write a function that takes a two-dimensional array (3x3) representing a completed Tic Tac Toe game and determines if the board is in a valid state. A Tic Tac Toe board is valid if:- There are either an equal number of 'X's and 'O's, or one more 'X' than 'O's (since 'X' always goes first).- There cannot be two winners (both 'X' and 'O' cannot have a winning line).- A winning line is considered as three 'X's or 'O's in a row, column, or diagonally.