title-img


Linked Lists: Detect a Cycle

A linked list is said to contain a cycle if any node is visited more than once while traversing the list. For example, in the following graph there is a cycle formed when node 5 points back to node 3. Function Description Complete the function has_cycle in the editor below. It must return a boolean true if the graph contains a cycle, or false. has_cycle has the following parameter(s): head: a pointer to a Node object that points to the head of a linked list. Returns boolean: T

View Solution →

Recursion: Fibonacci Numbers

The Fibonacci Sequence The Fibonacci sequence appears in nature all around us, in the arrangement of seeds in a sunflower and the spiral of a nautilus for example. The Fibonacci sequence begins with fibonacci(0) = 0 and fibonnaci(1) = 1 as its first and second terms. After these first two elements, each subsequent element is equal to the sum of the previous two elements. Programmatically: fibonacci(0) = 0 fibonacci(1) = 1 fibonacci(n) = fibonacci( n - 1 ) + fibonacci( n - 2 )

View Solution →

Recursion: Davis' Staircase

Davis has a number of staircases in his house and he likes to climb each staircase 1, 2, or 3 steps at a time. Being a very precocious child, he wonders how many ways there are to reach the top of the staircase. Given the respective heights for each of the staircases in his house, find and print the number of ways he can climb each staircase, module 10^10 + 7 on a new line. Example n = 5 The staircase has 5 steps. Davis can step on the following sequences of steps: 1 1 1

View Solution →

Crossword Puzzle

A 10 x 10 Crossword grid is provided to you, along with a set of words (or names of places) which need to be filled into the grid. Cells are marked either + or -. Cells marked with a - are to be filled with the word list. The following shows an example crossword from the input crossword grid and the list of words to fit, Function Description Complete the crosswordPuzzle function in the editor below. It should return an array of strings, each representing a row of the finished puzzl

View Solution →

Recursive Digit Sum

We define super digit of an integer x using the following rules: Given an integer, we need to find the super digit of the integer. If x has only 1 digit, then its super digit is x. Otherwise, the super digit of x is equal to the super digit of the sum of the digits of x. For example, the super digit of9875 will be calculated as: super_digit(9875) 9+8+7+5 = 29 super_digit(29) 2 + 9 = 11 super_digit(11) 1 + 1 = 2 super_digit(2) = 2 Function Description Co

View Solution →