Questions tagged [longest-prefix]
29 questions
0
votes
1 answer
SQL longest prefix String
I have a loop that executes a query N times through a DAO. In my case, I have an object with a property that has the value "123456789". In the first turn, it executes a query on a particular table to get all the records which have the column C1…

manash
- 6,985
- 12
- 65
- 125
0
votes
2 answers
Longest prefix that match more than 50% of items in an array
Suppose I have array of strings: ["apple", "ape", "application", "item"].
I need to find the longest common prefix that matches more than 50% of the strings in that array.
For example, we got "ap" being the prefix of 3 strings in a 4 elements array…

nekoroden
- 3
- 2
0
votes
1 answer
I need clarification of Java while loop conditional statement, when trying to find longest common prefix from an array of Strings
I'm working on a problem - Longest Common Prefix - using Java, for this problem I must return the longest common prefix when given an array of Strings, for example an array of ["ale", "Altamonte", "alligator"] would return the Longest Common Prefix…

Altoids weed
- 3
- 3
0
votes
2 answers
Is there a way to prevent index out of bounds error here?
I am new here. I'm trying a C# problem on Leetcode about Longest Common Prefix. I know this problem has been solved MANY times. I'm just having a hard time understanding why my code doesn't work under certain conditions. When the input…

Blake
- 1
0
votes
1 answer
Converting CIDR address from Hex to Binary in JS [Javascript]
I'm looking for a way to read a list of CIDR addresses and convert them into a binary strings.
The input is a file with rows of actions and addresses and destinations:
ADD 192.168.20.16/28 A
FIND 255.255.255.0
REMOVE 192.168.20.16/28 A
How can I…

ksilla
- 101
- 10
0
votes
2 answers
Longest Prefix That is Also a Substring in Second String
This code (adapted from a Prefix-Suffix code) is quite slow for larger corpora:
s1 = 'gafdggeg'
s2 = 'adagafrd'
Output: gaf
def pref_also_substr(s):
n = len(s)
for res in range(n, 0, -1):
prefix = s[0: res]
if (prefix in…

JohnGS
- 1
0
votes
2 answers
BGP: Longest prefix vs. shortest path
Assume that an autonomous system AS0 receives the following two announcements from its peers:
AS1: 42.0.0.0/8 with path length 10
AS2: 42.0.0.0/16 with path length 20
Now, where a packet with destination address 42.0.0.1 will be routed by AS0?
To…

nils1f5
- 1
- 1
0
votes
1 answer
How to invoke function for a given string array?
I try to solve the problem 14 on leetcode, which is to write a function to find the longest common prefix string amongst an array of strings.
Here is my code, the result I expect is "f" while the result I got is "".
Can someone help me out here?…

Xinyi Li
- 123
- 1
- 2
- 8
0
votes
1 answer
MySQL LEAST() with arbitrary number of parameters; longest match in a table
I would like to create a MySQL query to find the longest match (of a given ip address in quad-dotted format) that is present in a table of subnets.
Ultimately, I'd like to create a LEFT JOIN that will display every quad-dotted ip address in one…

Andrew Breunig
- 135
- 2
- 12
0
votes
0 answers
Longest word match in an array of strings
Assume a large set of arrays of individual words (not phrases), e.g.
{"One", "two", "three", "four"}
{"One", "two", "three"}
{"One", "two", "where", "are", "you"}
{"One", "other"}
{"Two", "three", "four"}
{"More", "more", "more"}
Given another…

PNS
- 19,295
- 32
- 96
- 143
0
votes
1 answer
Fastest way to find longest match on a 50K line CSV file in PHP
In a voice application I have to find the longest match of a prefix on an international phone number. I have a rates table that is 50K lines that is stored in CSV file that gets updated with new rates periodically (CSV column headers contain prefix,…

RolandFlyBoy
- 193
- 3
- 14
0
votes
2 answers
IPv4 longest prefix match using Postgres
Given an IP address 192.168.0.1, and a table with a column next_hop_subnet storing subnet IP addresses, do you see any problem with the following PostGRESQL logic, accuracy or performance-wise:
minDif := select min(abs(inet '192.168.0.1' - …

tartar
- 688
- 4
- 16
0
votes
1 answer
What is the best way to run a longest matching prefix against a table column?
I need to run a longest matching prefix against a column in a table, not just a single value. For a single value I use something like SELECT value, prefix as lmp FROM aTable WHERE SUBSTRING(value,1, LENGTH(prefix)) = prefix ORDER BY prefix DESC…

vfclists
- 19,193
- 21
- 73
- 92
-1
votes
2 answers
Longest Common Prefix
Write a function to find the longest common prefix string amongst an array of strings If there is no common prefix, return an empty string "".
Example: Input: strs = ["flower","flow","flight"]
Output: "fl"
I'm new in coding and try to solve this…

lulia
- 3
- 2