Skip to main content

Posts

Showing posts with the label Algorithms

Arrays

DP :Rat maze, Minimum cost path

Robot walked from the upper left to the lower right, can only go down and to the right, the number of each grid is height, If the next cell height is higher than the current, we must pay the difference cost, otherwise no cost, Find the minimum cost to reach the lower right corner, Follow up 1, print the minimum cost path;  November 25, 2017 in United States | Facebook SDE1 Problem 2 --> Given a non-empty string s, you may delete at most k characters. Judge whether you can make it a palindrome. Remove a character from a string to make it a palindrome Given a string, we need to check whether it is possible to make this string a palindrome after removing exactly one character from this. Examples: Input : str = “abcba” Output : Yes we can remove character ‘c’ to make string palindrome Input : str = “abcbea” Output : Yes we can remove character ‘e’ to make string palindrome Input : str = “abecbea” It is not possible to make...

Arrays: subarray problems

Problem : How many subsets of a given array sum to zero? October 18, 2017 in United States |  Flag   Facebook   SDE1 Largest sum subarray with at-least k numbers Given an array, find the subarray (containing at least k numbers) which has the largest sum. Examples: Input : arr[] = {-4, -2, 1, -3} k = 2 Output : -1 The sub array is {-2, 1} Input : arr[] = {1, 1, 1, 1, 1, 1} k = 2 Output : 6 The sub array is {1, 1, 1, 1, 1, 1} Asked in : Facebook Problem  Problem 2 Maximum element from each subarray of size k Problem : Find maximum (or minimum) sum of a subarray of size k Given an array of integers and a number k, find maximum sum of a subarray of size k. Examples : Input : arr[] = {100, 200, 300, 400} k = 2 Output : 700 Input : arr[] = {1, 4, 2, 10, 23, 3, 1, 0, 20} k = 4 Output : 39 We get maximum...