I am the Ocean. I’m Water. I’m most of this planet. I shaped it. Every stream, every cloud and every rain drop. It all comes back to me. One way or another, every living thing here needs me. I’m the source. I’m what they crawled out of. Human, they’re no different. I don’t owe them […]
Minimum string moves
We have two strings A and B which are permutations of the same set of characters. We need to change these strings to obtain two identical strings by performing the following operations: swap two consecutive characters of a string swap the first and the last characters of a string The operation can be […]
String Similarity
For two strings A and B, we define the similarity of the strings to be the length of the longest prefix common to both strings. For example, the similarity of strings “abc” and “abd” is 2, while the similarity of strings “aaa” and “aaab” is 3. Calculate the sum of similarities of a string S […]
Fibonacci
Complete the function fibonacci to return an array containing the first N Fibonacci numbers. fib(n) = n , n <= 1 fib(n) = fib(n-2) + fib(n-1), otherwise Constraints: 1 ≤ N ≤ 10 Sample Input 4 Sample Output 0 […]
Calculate Factorial
Write a program that will read an integer N from STDIN and compute the factorial of N. The input to your program will contain many lines. On each line there will be exactly one integer. Your program should print the factorial of each integer in a separate line. Your program should terminate when it reads a number […]
Maximum Difference in an Array
Return the maximum difference between any a[i] and a[j] where a[i] < a[j] and i < j The maximum difference for a pair of elements in some array a is defined as the largest difference between any a[i] and a[j] where i < j and a[i] < a[j]. The declaration for a function named maxDifference […]