You are given a string with some repeating characters and some unique characters. Find the first unique character and return its index. Example 1:Input: studyAlgorithmsOutput: 2 Example 2:Input: iLoveToCodeOutput: 0 Problem Statement: I want to simplify the problem statement first before we begin to solve it. An input string consists of some uppercase and lowercase characters which may or may not be repeated. Out of all the unique characters, you need to return the characters that occurs first in the string. In the first example studyAlgorithms, s, and t are…
Preprocessing


Question: Given an array A, find the sum of maximum sum of two nonoverlapping subarrays, with lengths L and M.In other words, return the largest V for which V = (A[i] + A[i+1] …. A[i+L1]) + (A[j] + A[j+1] …. A[j+M1])Input: A = {3, 8, 1, 3, 2, 1, 8, 9, 0}; L = 3, M = 2Output: 29 The problem statement is quite clear. We need to find 2 contiguous subarrays from an array Add the elements of both these arrays The sum should be the maximum possible sum…

Question: Given an integer N, find the prime numbers in that range from 1 to N. Input: N = 25Output: 2, 3, 5, 7, 11, 13, 17, 19, 23 We have several ways of finding prime numbers. Some of the methods are discussed in the these posts. Method 1 Method 2 Method 3 In this post we will find the first N prime numbers using the Sieve of Eratosthenes. This technique is helpful in scenarios when we have to give immediate results and we need to query the prime numbers…

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…