Question: Find the sum of even fibonacci numbers upto a limit N. Input:100Output: 44 Fibonacci numbers are a miracle of Math and are defined as: Thus the Fibonacci series can be given as0, 1, 1, 2, 3, 5, 8, 13, 21… Let us try to understand the question. We need to find all the Fibonacci numbers till a limit ‘N’ and then sum only the even numbers in them.Example:N = 10 Fibonacci numbers: 0, 1, 1, 2, 3, 5, 8 Sum of even numbers: 2 + 8 = 10 N…
Hackerrank


Question: Given two strings, determine if they share a common substring. If they have a common substring, print YES else print NO. Input:studyalgorithmsalgosOutput: YES This is one of the easy problems but can get a little tricky, if we do not understand it completely. Let us try to understand the test caseString 1 = “studyalgorithms” String 2 = “algos”The substring “algo” is common between both the substrings and therefore the answer is “YES“. Let us try to take one more test case. String 1 = “hello” String 2 = “world”The…

Question: If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. Find the sum of all the multiples of 3 or 5 below ‘N’ Input: N = 100 Output: 2318 The most naive approach to solve this problem will be Iterate over each number till N If the number is divisible by 3 or 5, add it to the sum Print the sum This approach can work well to numbers…

Question: Given a string, identify the index of character to be removed to change the string into a palindrome. If the string cannot be converted to palindrome or is already a palindrome just return 1. Input: abckdeedcbaOutput: 3 (0 based indexing) To start off with the problem, we must first understand that there can be two possible ways to make the string a palindrome. If the given string is “bcbc”. If we remove the first ‘b’, the string becomes “cbc” which is a palindrome. If we remove the last ‘c’,…

Let us try to simplify the problem as much as we can. We are given with some of the terms. Weights: According to the problem each character in the English alphabet has been assigned a weight. ‘a’ has been given a weight of 1, ‘b’ has a weight of 2, and so on. The weight of ‘z’ is 26. All the letters are assumed to be lowercase for simplicity. Weight of a string: This is defined as the sum of all the characters in the string. Example if a string…

Question: Given a string, identify if it is a pangram. Input: The quick brown fox jumps over the lazy little dog.Output: pangram To start with the problem statement we must first understand what is a pangram. A pangram is a string that contains all the characters in the English alphabet atleast once. This means that the string ‘the quick brown fox jumps over the lazy little dog’ will cover each of the letter from ‘az’. So how to identify if a string is a pangram?You need to keep a check…

A string is said to be valid when it has only distinct characters and none of them repeat simultaneously. For example, if string ‘s two distinct characters are x and y, then valid examples could be xyxyx or yxyxy but not xxyy or xyyx. Question: Given a sample string, we need to determine what is the maximum length of valid string that can be made by deleting any of the characters. Input: beabeefeabOutput: 5 Let us try to understand the output for the sample test case.If we delete e and…

Question: Given a camelCase string, find the number of words in the string. Input: saveChangesInTheEditorOutput: 5 Camel case is a very popular style of naming variables and methods in most of the programming languages. Not only it helps to make the code readable but also ensures that the variable names are unique and easy to remember.A camel case follows the following rules:1. The first word will start with a lower case character2. The first letter of each subsequent word should be upper case. To name a variable for InputStreamReader we…