Algorithms {Longest Palindromic Substring}

Today we will talk about “Longest Palindromic Substring” problem. I’ve developed solution about year ago but a few days remembered it and thought about it. So, full problem description: Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longest palindromic substring. Ok, good, on the face of it, we can use some simple naive algorithm with O^2 complexity…

"Algorithms {Longest Palindromic Substring}"

Algorithm {Binary Tree Maximum Path Sum}

I’ve just solved one more problem from leetcode and going to share that solution. So, solved problem calls Binary Tree Maximum Path Sum. Problem description: Given a binary tree, find the maximum path sum. The path may start and end at any node in the tree. For example: Given the below binary tree, 1 / \ 2 3 Return 6. OK, stop and think …. What do we have ???  The main point is binary tree. We can…

"Algorithm {Binary Tree Maximum Path Sum}"

Evaluate Reverse Polish Notation Algorithm

I’ve solved a few tasks from http://leetcode.com/ and going to publish my solutions, So, first task is Evaluate Reverse Polish Notation The task description is : Evaluate the value of an arithmetic expression in Reverse Polish Notation. Valid operators are +, –, *, /. Each operand may be an integer or another expression. Some examples:   [“2”, “1”, “+”, “3”, “*”] -> ((2 + 1) * 3) -> 9   [“4”, “13”, “5”, “/”, “+”] -> (4 + (13 / 5)) ->…

"Evaluate Reverse Polish Notation Algorithm"

Algorithm {The maximum-subarray problem}

I’ve just opened Introduction to Algorithms on Divide-and-Conquer chapter, and found interesting item – The maximum-subarray problem. In book you can find implementation with complexity O(NlogN) with good explanation, but in Exercises part there is good task: Use the following ideas to develop a nonrecursive, linear-time algorithm for the maximum-subarray problem. Start at the left end of the array, and progress toward the right, keeping track of the maximum subarray seen so far. Knowing a…

"Algorithm {The maximum-subarray problem}"

Algorithm {Single Number}

We are working on next task from leetcode. So, next task will be …. , {Single Number} 🙂. Task: Given an array of integers, every element appears twice except for one. Find that single one. Note: Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory? Stop and think … What we have, input array of integers and we should find one NOT DUPLICATE number. So, it’s easy … Go to the…

"Algorithm {Single Number}"