You are provided with an array of integers. We need to find the subarray with the maximum sum such that all the elements are contiguous. Example:Input: [2, 5, 6, 2, 3, 1, 5, 6]Output: 7Explanation: The subarray with maximum sum is [6, 2, 3, 1, 5] Problem Statement: You are provided with an array of integers. These elements could be all positive, all negative or a combination of both. A subarray is a smaller array formed using the elements of the original array. The condition for this problem is that…
Dynamic Programming


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…

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 string, find the next lexicographic permutation. Input: abcOutput: acb First of all let us try to understand what do you mean by next lexicographic string. To get a hold of the concept try to remember an English dictionary and how words are arranged in it. We start with the letter ‘a’, write all the words and then move to letter ‘b’ all the way to letter ‘z’. This is called as a lexicographic order.This is possible when we have all the letters in English alphabet available to…

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 discussed the basic approaches to find the first N prime numbers in these posts Find the first N prime numbers (Method 1) Find the first N prime numbers (Method 2) It is advised that you go through the above posts to get a basic understanding of the approach that we have used to determine the prime numbers. Now lets analyze…