TicTacToe Validator
Function Name: isValidTicTacToe
Description
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.
Requirements
- The function must take one parameter, a 3x3 two-dimensional array.
- The function should return a boolean: true if the board is valid, false otherwise.
- Each element of the array can be 'X', 'O', or an empty string to indicate an empty cell.
- Assume that the game ends as soon as a winning condition is met, i.e., players do not play any extra moves.
Examples
Given board = [['X', 'O', 'X'], ['O', 'X', 'O'], ['X', '', '']], isValidTicTacToe(board) should return true.Given board = [['X', 'O', 'X'], ['X', 'O', ''], ['O', '', 'O']], isValidTicTacToe(board) should return false as 'O' cannot have a winning line since 'X' starts first.
Links
Simple Change Counter
Sun Oct 20 2024
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.
LinkedList Cycle Detector
Tue Oct 22 2024
Write a function `hasCycle` in a language of your choice that takes a linked list as an input and returns a boolean indicating whether the linked list contains a cycle.A linked list is said to contain a cycle if any node is visited more than once while traversing the list.To solve this problem, you should detect if the linked list has a cycle without using extra space (e.g., an additional data structure like a hash table).Assume that the linked list is a singly linked list provided with the next pointer.Your function should be able to return false if the input is an empty list or a single-node list without a cycle, and true if a cycle is detected.