समस्या
Reverse text so the last character comes first.
Implement reverse_string(text).
Input
text: The text to reverse.
Output
Return the reversed text.
सीमाएँ
0 ≤ length ≤ 10,000
उदाहरण
इनपुट:
text = "hello"
अपेक्षित आउटपुट:
expected = "olleh"
इनपुट:
std::string text = "hello";
अपेक्षित आउटपुट:
std::string expected = "olleh";
इनपुट:
string text = "hello";
अपेक्षित आउटपुट:
string expected = "olleh";
व्याख्या
h-e-l-l-o read backwards is "olleh".
इनपुट:
text = "a"
अपेक्षित आउटपुट:
expected = "a"
इनपुट:
std::string text = "a";
अपेक्षित आउटपुट:
std::string expected = "a";
इनपुट:
string text = "a";
अपेक्षित आउटपुट:
string expected = "a";
व्याख्या
A single character reversed is itself.
कैसे हल करें
पहले खुद कोशिश करें, फिर एक-एक करके संकेत खोलें।
संकेत 1
The answer is the characters in opposite order.
संकेत 2
A two-pointer approach or a backward traversal both work well.
संकेत 3
Be sure the empty string stays empty after reversal.
अपेक्षित जटिलता
O(n) time, O(n) extra space
संदर्भ
यह चुनौती CodeUtility के लिए अनुकूलित की गई है। ऊपर दिए गए स्टेटमेंट और सीमाओं का पालन करें।