## Mass update all cells in a column with a substring of it’s original value

I need to trim the last seven characters off of all the cells in a column.

This query returns the results that I need

SELECT test_date, SUBSTRING(test_date FROM 1 FOR CHAR_LENGTH(test_date) - 7) as test from results; 

I now need to take the computed result from the substring and replace the original values.

Here’s what the data looks like, if it helps. ## Longest palindrome substring in logarithmic runtime complexity

In a palindrome of size N, the amount of candidates for the longest palindrome is N^2. Therefore, the information theoretic lower bound (IBT) should be lg(N^2), which is equivalent to a runtime complexity of lg(N).

By IBT I mean that if we use a comparison based algorithm and you think about a decision tree to apply it, the leafs of that tree will be all of the possibilities (N^2 leafs), therefore the height of that tree is lg(N^2). However, I was not able to find any algorithm that is able to solve this question in this runtime complexity; the best I have found is Manacher’s algorithm that solves the question in linear time.

Posted on Categories proxies

## Longest Even Length Palindromic Substring (with unique adjacent characters except for the center 2 letters)

You are given a string S containing lowercase English characters. You need to find the length of the largest subsequence of S that satisfies the following pattern: X1,X2,X3…Xn,Xn,…X3,X2,X1 where Xi is some character of S. The only constraint is that no adjacent character should be the same except Xn, that is Xi != X(i+1) for all 1<=i< n.

Input: The string: S

Output: The integer: 2n

Constraint: 1<=|S|<=10^3

Sample input 1: “acdbdea”

Sample output 1: 4

Explanation: “adda” is the longest subsequence following the given pattern.

Sample input 2: “abbacdeedc”

Sample output 2: 6

Explanation: “cdeedc” is the longest subsequence following the given pattern.

Sample input 3: “taker”

Sample output 3: 0

Explanation: No subsequence follows the given pattern.

This question was asked in a coding interview and I didn’t know how to solve it. I understood how to find longest palindromic sub sequence but don’t know how to implement the unique adjacent character part. Please help. pseudo code is fine

Posted on Categories proxies

## Practical applications of the palindromic substring problem?

The longest palindromic substring problem is certainly an interesting intellectual exercise, and seems to be popular in coding interviews in industry. As an interesting puzzle, its popularity for interviews is not too hard to understand–it’s not too hard to find an $$O(N^2)$$ solution, and if someone manages to come up with a linear time solution, they’re probably either a genius or at least well-read, which is arguably as valuable.

Given the apparent frivolity of the problem, however, it seems like a surprising amount of effort has gone in to analyzing it. There are at least three published linear-time solutions (by Manacher, Jeuring, and Gusfield). But, is it actually useful for anything? Are there other problems in which finding a palindromic substring is a necessary step? And in the absence of a direct application, did any of the known solutions to this problem reveal new techniques that have been applicable elsewhere?

Posted on Categories proxies

## Apache, Redirect is not working for substring

Issue

In apache, how can I redirect to homepage in case if you will go to exact string, but everything behind this string should be displayed normally, no redirect.

Example.

http://example.com/STRING -> go to homepage http://example.com/STRING_PAGE -> go to http://example.com/STRING_PAGE 

I tried

Redirect 301 /STRING http://example.com/ 

But in this case page is redirected to homepage too, for example in case of http://example.com/STRING_PAGE.

Thanks.

## Given a list of strings, find every pair $(x,y)$ where $x$ is a substring of $y$. Possible to do better than $O(n^2)$?

Consider the following algorithmic problem: Given a list of strings $$L = [s_1, s_2, \dots, s_n]$$, we want to know all pairs $$(x,y)$$ where $$x$$ is a substring of $$y$$. A trivial algorithm would be this:

foreach x in L:    foreach y in L:       if x is substring of y:          OUTPUT x,y 

However, this takes $$O(n^2)$$ $$x$$ substring of $$y$$ operations – I am curious to know whether there is a faster algorithm?

Posted on Categories proxies

## How to Tokenize a String and Save Each Substring Separately (Independent Names for Each Substring)

I am given two files one with the name of person and the location that they are from (Evan Lloyd|Brownsville) and one with the name and salary (Evan Lloyd|58697) (the line number that you find the employee on in the first file is not necessarily the line number that find the employee on in the second). The user inputs a location (whole or part). For example if they input “ville” or “Ville” it should include all of the employees in Brownsville, Clarksville, Greenville, etc. I am supposed to join the the name and salary and return them if they are in the city searched for i.e. “ville” or “Ville.” I am attempting to use a vector for both of the files vector(name, address) and vector(name, salary) and later return a vector of a string and tuple (address, (name, salary)) as my output. I don’t know how to tokenize the string for example “Evan Lloyd|Brownsville” into the substrings “Evan Lloyd” and “Brownsville” separately (without the |) and save them separately so that I can push both strings into my vector(name, address). How would I tokenize the strings that way or should I try something else entirely?

Posted on Categories proxies

## How many operations of flipping all brackets on a substring of a string of brackets are needed to make the string ‘correct’?

I call a string of brackets ‘correct’ if every opening bracket has a corresponding closing bracket somewhere after it and every closing bracket has a corresponding opening bracket somewhere before it. For example

(())()((()()))

is a correct string and

)()()(

is an incorrect string.

An operation consists of taking a contiguous subsequence of the input string and ‘flipping’ every bracket in that subsequence.

Given an arbitrary string of brackets (of even length), the task is to find the smallest number of such operations needed to change it to a ‘correct’ string of brackets.

Another way to look at this problem is to have a string of +1s and -1s, and to try to find the smallest number of operations (of multiplying every number on an interval by -1) needed to make every prefix of this string nonnegative and every suffix nonpositive.

Posted on Categories proxies

## Build a DFA that accepts strings over {0,1,2} that are divided by 3 and doesn’t include the substring 012

Ive tried to draw it but im not finding the right way. Ive also read it “How to prove a language is regular?” and here – https://math.stackexchange.com/questions/1556655/build-a-dfa-that-accepts-strings-over-0-1-2-that-are-divided-by-3-and-do , but still in the same situation. hope someone can help or give a lead.

Thats what ive got so far: Posted on Categories proxies

## Finding an substring in an infinite sequence

I’m trying to find a substring in an infinite sequence of numbers (Similar to Substring in a infinite sequence of numbers) and am a little stuck on improving my algorithm. I know there is already an answer given in the question I linked above, but I want to try and improve my brute force algorithm.

Given a sequence $$S = \{12345678910…n-1n | S \in \mathbb{Z}:\}$$, the algorithm tries to compute the first index of a pattern $$P$$ in the string. For instance, $$\mathrm{find}(P = 456) == 3$$ as the sequence $$456$$ is located at index $$3$$. I have a very simple algorithm that generates a sequence till the substring is found, and then goes through the sequence to return the index of the substring. This algorithm is very slow for for large $$N$$ and I want to improve it:

def find_position(string):      # Build a window of size len(string) and init from 1 -> m     windowSize = len(string)     window = [str(i) for i in range(1, windowSize + 1)]     result = ''.join(window)      # Loop till match     while string not in result:          # Remove front and add back         window.append(str(int(window[-1]) + 1))          # Join window and match         result = ''.join(window)      return result.index(string) 

This algorithm is like a very basic Rabin-Karp without any hashing but just regular string matching. I am not too sure if adding a rolling hash would speed up this algorithm in any way because the slow aspect of the algorithm is generating and appending to the sequence and then checking if the string is contained in the window.

Any ideas on how to improve this algorithm?

Posted on Categories proxies