Tic Tac Toe Validator
Function Name: isValidTicTacToe
Description
Write a function to validate a Tic Tac Toe game state. The game is played on a 3x3 grid. The function should determine if the given game state is a possible state that could be reached within the rules of Tic Tac Toe. The board is presented as a single array with 9 elements, representing rows from top to bottom, where 'X', 'O', or an empty string '' are the possible values for each cell.
The function should return true if the board configuration is valid, and false otherwise. A valid Tic Tac Toe board has either 'X' or 'O' as the winner, or the game is ongoing or is a draw, but it cannot contain both 'X' and 'O' as winners. Additionally, the number of 'X's must be equal to or one more than the number of 'O's.
Requirements
- The function's signature should be: bool isValidTicTacToe(string[] board).
- The input array has exactly 9 strings, each representing a cell in the Tic Tac Toe board.
- The input can only consist of 'X', 'O', or '' for each cell.
- The function should return a boolean value.
- Do not use any external libraries or modules.
- You should not make any assumptions about the order of moves or who started the game.
Examples
Given the board ['X', 'O', 'X', 'X', 'O', 'O', '', '', 'X'], the function should return true because it's a possible game state.Given the board ['X', 'O', 'X', 'X', 'O', 'O', 'O', 'X', 'X'], the function should return false because there cannot be 5 'X's and 4 'O's in a valid game.
Links
Colorful Number
Sat Sep 28 2024
A 'colorful' number is one where the product of every digit of a contiguous subset of its digits is different. For instance, the number 263 is a colorful number because (2, 6, 3, 2*6, 6*3, 2*6*3) are all different.Write a function `isColorful` that determines if a given number is colorful or not.The function should take an integer as a parameter and return a boolean indicating whether the number is colorful.
Stock Spanner
Mon Sep 30 2024
Write a function to calculate the span of stock’s price on a given list of days. The span of the stock’s price today is defined as the maximum number of consecutive days (starting from today and going backward) for which the price of the stock was less than or equal to today's price.The function should take an array of integers representing the stock prices and return an array of integers representing the span of each stock price.