Fibonacci Nth Number
Function Name: fibonacciNth
Description
The Fibonacci sequence is a series of numbers where the next number is found by adding up the two numbers before it. The sequence starts with 0 followed by 1, and each subsequent number is the sum of the previous two.
Your task is to write a function named 'fibonacciNth' that calculates the nth number in the Fibonacci sequence.
- The function should be efficient and should handle large values of 'n'.
- You may not use any libraries or built-in functions that directly compute the Fibonacci sequence. Implement the calculation from scratch using your understanding of the sequence.
Requirements
- The function 'fibonacciNth' takes one argument:
- 1. 'n' (integer): The position in the Fibonacci sequence for which to find the corresponding number. The first position in the sequence is 0.
- Consider edge cases where 'n' could be a very small or very large number.
- Optimize the solution to achieve a runtime better than the naive recursive approach (which has exponential time complexity).
Examples
// Example 1: Find the 5th Fibonacci numberfibonacciNth(5); // Should return 5// Example 2: Find the first Fibonacci numberfibonacciNth(0); // Should return 0// Example 3: Find the 10th Fibonacci numberfibonacciNth(10); // Should return 55
Links
Tree Level Sums
Tue Sep 17 2024
Write a function that calculates the sum of values at each level of a binary tree.The function should take the root of the binary tree as an input parameter.The binary tree nodes have an integer value, along with left and right child pointers.The function should return an array, where each element represents the sum of the values at the corresponding level of the tree.Level order traversal of the tree would help to collect the sums in breadth-first manner.
Anagram Detector
Thu Sep 19 2024
Write a function that checks whether two given strings are anagrams of each other. An anagram is a word or phrase that is made by rearranging the letters of another word or phrase. For example, 'heart' and 'earth' are anagrams.