Lucky Palindrome / Social Circle
A String is called a palindrome if it can be read the same way in either direction For example, "malayalam" is a palindrome, but "tamil" is not
A "lucky palindrome" is a palindrome of prime length,
Now, you task is to find out the length (denoted by L) of the longest palindrome sub-sting (maximum-length contiguous substring of a given sting that is also a palindrome) and print "YES" if it is a prime number, otherwise print "NO"
Write a function
function solution(s);
that given an string S, returns "YES" / "NO" ) based on whether the input string's longest palindrome substring is a prime number.
For example, given a string
S = "122243323341"
the function should return "YES" (quotes only for clearity) because the longest palindrome substring in S is "4332334"
, the length is 7 and 7 is a prime number
The string only consists of english alphabets A-Z(uppercase or lowercase) and digits 0-9
A String is called a palindrome if it can be read the same way in either direction For example, "malayalam" is a palindrome, but "tamil" is not
There are S students in a class. Some of them are fiends, while some are not. Their friendship is transitive in nature. For example, if A is a direct friend of B and B is a direct friend of C, then A is an indirect friend of C.
A "social circle" is a group of students who are direct or indirect friends.
You are given a S*S matrix M (S is the number of students) representing the friend relationship between students in the class. if M[i][j] = 1, then the ith and jth students are direct friend with eachother, otherwise not.
Your task is to return the string, representing all the social circles separated by pipe(i) among all the students. Individual members within circle should be seprated by a comma(,)
Write a function
function solution(s);
that given a zero-indexed double-dimensional array A of dimensions S*S (in string format to be converted to a 2-dimensional array), returns a string representing pipe-separated (|) social circles of comma-separated friends.
The function should return "0,1|2" (qutoes for representation purpose only)
The 0th and 1st students are direct friends (M[0][1]) = 1 and subsequently M[1][0] = 1), so they are in a social circle.
The 2nd student is in her/his own social circle. So return 2.
For another example, given:
M = "[
[1,1,0],
[1,1,1],
[0,1,1]
]"
the function should return "0,1,2"
The 0th and 1st students are direct friends, the 1st and 2nd students are direct friends. Thus, the 0th and 2nd are indirect friends. All of them are ub tge sine sociak curckes si retyrb 1.
You can assume that:
- for every i within the range [0.. N - 1] M[i][i] = 1
In your solution, focus on correctness. The performance of your solution will not be the focus of the assessment
please add answers also.