ProgrammingHardInfosys · Cognizant
For the string s = "forgeeksskeegfor", the procedure below expands around each centre to find the length of the longest palindromic substring. What is printed?
For the string s = "forgeeksskeegfor", the procedure below expands around each centre to find the length of the longest palindromic substring. What is printed?
best = 1
for each centre c (between or on characters)
expand while the left and right characters match
best = max(best, length of the largest palindrome found)
end for
Print best- A. 1
- B. 9
- C. 10
- D. 8
Correct answer: C. 10
The palindrome geeksskeeg has length 10, found by expanding around the double-letter centre ss. Centres on single characters only give 1, subtracting one from the answer gives 9, and the length of the outer part gives 8.
Practise more Pseudocode and Code Tracing questionsPseudocode and Code Tracing: notes and key points
More Pseudocode and Code Tracing questions
- Count the palindromic substrings (substrings of length 1 or more that read the same forwards and backwards, counted by position) of the…
- Run-length encoding replaces each run of equal characters by the character followed by its run length. The procedure below encodes s =…
- A Caesar cipher shifts each lowercase letter forward by 3 places, wrapping from z back to a. The procedure below encodes the word "xyz"…
- The number of distinct arrangements (permutations of the letters, with identical letters not counted twice) of the string "AABBC" is…
- The string "Programming Language" is taken in lowercase and the procedure below counts its vowels (a, e, i, o, u). What is printed? count…
- For the bracket string "(()(()))", the procedure below tracks the nesting depth and prints the maximum depth reached. What is printed?…