We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- Algorithms
- Strings
- String Similarity
- Discussions
String Similarity
String Similarity
Sort by
recency
|
179 Discussions
|
Please Login in order to post a comment
!/bin/python3
import math import os import random import re import sys
def stringSimilarity(s): n = len(s) z = [0] * n z[0] = n l, r = 0, 0
if name == 'main': fptr = open(os.environ['OUTPUT_PATH'], 'w')
import java.util.Scanner;
public class StringSimilarity { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int t = scanner.nextInt(); // Number of test cases
Read the number of test cases and input strings. For each string, compute its Z array using the Z algorithm. Sum up the values in the Z array to get the similarity. Output the similarity for each string. Repeat for each test case.
}
//Java solution using recursion function(fails for the test case 11 and 12 yet i got 85.04):
public static int stringSimilarity(String s){
JavaScript solution
i got time limit exceed in 2 test cases, how should i modify this code?
using namespace std; long long stringSimilarity(const string& s) { int n = s.length(); vector z(n, 0); z[0] = n; int l = 0, r = 0;
}
int main() { int t; cin >> t; while (t--) { string s; cin >> s; cout << stringSimilarity(s) << endl; } return 0; }