Lights Out Puzzle
Function Name: isSolvableLightsOut
Description
In the game 'Lights Out', there is a grid of lights that are either on (1) or off (0). When you toggle a light at position (i, j), it also toggles the lights vertically and horizontally adjacent to it. The task is to write a function that takes a 5x5 grid of the lights as an input and determines if the game is solvable. A game is considered solvable if there exists a sequence of moves that turns all the lights off.
Requirements
- The function must accept a single argument, which is a 5x5 two-dimensional array representing the lights grid.
- Each light is represented by a 1 (on) or 0 (off).
- The function should return a Boolean value: true if the game is solvable, otherwise false.
- You do not have to provide the sequence of moves, just determine if a solution exists.
- Constraints: Do not use any external libraries or plugins.
- Assume the function will only be used for a 5x5 grid.
Examples
Example 1: isSolvableLightsOut([[0, 1, 0, 1, 0], [1, 1, 1, 0, 0], [0, 0, 1, 0, 1], [1, 0, 0, 1, 0], [0, 1, 0, 1, 0]]) -> Returns trueExample 2: isSolvableLightsOut([[1, 1, 1, 1, 1], [0, 0, 0, 0, 0], [1, 0, 1, 0, 1], [0, 0, 0, 0, 0], [1, 1, 1, 1, 1]]) -> Returns false
Links
Binary Tree Right Side View
Mon Dec 09 2024
Given the root of a binary tree, imagine yourself standing on the right side of the tree, return the values of the nodes you can see ordered from top to bottom.The binary tree's TreeNode is defined as: struct TreeNode { int val; TreeNode *left; TreeNode *right; TreeNode(int x) : val(x), left(NULL), right(NULL) {} };The function should traverse the tree level by level and only take the farthest right node's value at each level.The tree may contain duplicate values.
Sum of Multiples
Wed Dec 11 2024
In this challenge, you are required to implement a function that calculates the sum of all multiples of a set of numbers up to a certain limit. For example, if the set is [3, 5] and the limit is 10, the function should return the sum of the numbers that are multiples of either 3 or 5 below the limit: 3, 5, 6, and 9, which adds up to 23.