Fall Semester 2024-25 - STS3007 - TH - AP2024252001241 - 2024-10-01 - Reference-Material-I
Fall Semester 2024-25 - STS3007 - TH - AP2024252001241 - 2024-10-01 - Reference-Material-I
Y FIRST
PALINDROMIC
STRING
TEST TIME ON MAJORITY ELEMENT
URL:https://forms.gle/SFDVg26roZ2rtzcy5
QR CODE:
Introduction
Example :
The problem involves finding the smallest palindromic string that can
be formed using the characters of a given string `s`, and the resulting
string should be lexicographically smallest among all possible
palindromic strings.
Interview questions
2.How does the proposed solution work?
The solution sorts the characters of the input string, and then iterates
through the sorted characters. It appends each character to both the
beginning and the end of the resulting palindromic string. This way, it
constructs a palindromic string in a way that maintains lexicographical
order.
Interview questions
The time complexity is dominated by the sorting step, which takes O(n
* log n) time, where n is the length of the input string. The subsequent
iteration through the sorted characters takes O(n) time. So, the overall
time complexity is O(n * log n).
Interview questions