आसान 0 हल किए गए 0% स्वीकृति

Reverse a String

Return the characters of a string in reverse order.

आप क्या सीखेंगे

  • Walk through a string backwards
  • Build a new string from characters
  • Use slicing or two pointers

समस्या

अनुवाद दिखाएँ

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

उदाहरण

उदाहरण 1
इनपुट:
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".

उदाहरण 2
इनपुट:
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 के लिए अनुकूलित की गई है। ऊपर दिए गए स्टेटमेंट और सीमाओं का पालन करें।

दूसरों से सीखें

समुदाय समाधान

अभी तक कोई प्रकाशित समाधान नहीं। पहला साझा करने के लिए इस चुनौती को हल करें।