समस्या
Replace every space in text with a dash -, and convert all letters to lowercase.
Implement slugify_spaces(text).
Input
text: The text to convert.
Output
Return the converted text.
सीमाएँ
0 ≤ length of text ≤ 10,000
उदाहरण
इनपुट:
text = "Hello World"
अपेक्षित आउटपुट:
expected = "hello-world"
इनपुट:
std::string text = "Hello World";
अपेक्षित आउटपुट:
std::string expected = "hello-world";
इनपुट:
string text = "Hello World";
अपेक्षित आउटपुट:
string expected = "hello-world";
व्याख्या
The space becomes a dash and letters are lowercased: "hello-world".
इनपुट:
text = "Learn To Code"
अपेक्षित आउटपुट:
expected = "learn--to-code"
इनपुट:
std::string text = "Learn To Code";
अपेक्षित आउटपुट:
std::string expected = "learn--to-code";
इनपुट:
string text = "Learn To Code";
अपेक्षित आउटपुट:
string expected = "learn--to-code";
व्याख्या
Each space becomes its own dash: "learn--to-code".
कैसे हल करें
पहले खुद कोशिश करें, फिर एक-एक करके संकेत खोलें।
संकेत 1
Transform the whole string by applying both lowercase conversion and space replacement.
संकेत 2
A single pass can build the result while handling each character.
संकेत 3
Be careful not to change non-letter characters except spaces.
अपेक्षित जटिलता
O(n) time, O(n) extra space
संदर्भ
यह चुनौती CodeUtility के लिए अनुकूलित की गई है। ऊपर दिए गए स्टेटमेंट और सीमाओं का पालन करें।