Nim Game is a mathematical game of strategy in which two players take turns removing (or "nimming") objects from distinct heaps or piles. On each turn, a player must remove at least one object,…
Given a total of N regular hexagon , find out how many rows of pyramid we can build. Note that every k-th row must have exactly k hexagon. Sample Input:…
In number theory, a perfect number is a positive integer that is equal to the sum of its positive divisors, excluding the number itself. For instance, 6 has divisors 1, 2 and 3 (excluding itself), and…
Given a list of integers including positive and negative ones, find out the maximum sum from any slice of this list. Sample Input: [3,-2,2,-3,4,-1,2,1,-5,4,-2,2] Sample Output: 6 From the above…
Fibonacci numbers, commonly denoted Fn, form a sequence, called the Fibonacci sequence, such that each number is the sum of the two preceding ones, starting from 0 and 1. That is, and The…
Given a decimal number and a base N (which is between 2 and 35), convert the decimal number to the base-N number. For base more than 9, use uppercase letter…
Given a 32 bit integer, reverse all the 0/1 bits so that the first bit becomes the last one, the second bit becomes the one before the last one...etc. Sample…
Given a pattern and a list of words, check whether the words match the pattern. Sample Input: pattern = "ABBA"words = "hello kitty kitty hello" Sample Output: True In the…