+ 14

🏆 [M💙 Challenge] Substring Reversal

Monday Blue 💙 Challenge Series #1 Write a program to accept both { string } and { length } to perform reverse on each of the substrings of the given length. Here are the test cases of "123456789":- ☑ Length 1 output: "123456789" ☑ Length 2 output: " 214365879" ☑ Length 3 output: "321654987" Assumption: 1 ≤ length ≤ string's length Happy Coding!!! 😁💻

16th Oct 2017, 1:29 PM
Zephyr Koo
Zephyr Koo - avatar
20 Respuestas
+ 10
18th Sep 2017, 4:56 AM
noobcøder
noobcøder - avatar
+ 11
@ysraelcon Another creative use of regex! You reminds me about the comic strip by xkcd below and it seems almost anything can be solved by regex. 😂 By ysraelcon 👇👍 https://code.sololearn.com/WP35CG6WZ66D/?ref=app https://code.sololearn.com/WiBHxBs0BFmX/?ref=app
18th Sep 2017, 11:59 AM
Zephyr Koo
Zephyr Koo - avatar
+ 11
https://code.sololearn.com/cmf0LR6eXRiw/#cs My solution in C# :) .
19th Sep 2017, 12:22 AM
Vukan
Vukan - avatar
+ 8
heres mine... prints all possibility ## https://code.sololearn.com/cdLqa08Oh7d7/?ref=app
18th Sep 2017, 3:26 AM
sayan chandra
sayan chandra - avatar
+ 6
@Calvin Good job! We need a general approach to accept any length of substring with the constraint above by using one function only. I believe you can do it! 😄
18th Sep 2017, 11:33 AM
Zephyr Koo
Zephyr Koo - avatar
+ 6
Here's my own C# implementation! ✌ LINQ One-Liner〰 string.Concat( Enumerable.Range(0, input.Length) .GroupBy(i => i / length) .Select(g => string.concat( g.Select(i => input[i]) .Reverse()))) Yup it's a LINQ solution again~ Enjoy! ❤ https://code.sololearn.com/c3QVlZ739VTl/?ref=app
16th Oct 2017, 2:42 PM
Zephyr Koo
Zephyr Koo - avatar
+ 5
https://code.sololearn.com/WPA0zG5EI6i7/?ref=app
18th Sep 2017, 3:36 AM
Calviղ
Calviղ - avatar
+ 5
@Zephyr: Thanks for mark mine as best answer! 😊👍
16th Oct 2017, 5:08 PM
noobcøder
noobcøder - avatar
+ 5
@noobcøder You're welcome! 😄 Well the best answer was selected after every week, perhaps you're too busy to get notified about it. 😂 Glad that there are people still interested with the challenge since I BUMP it unintentionally by standardizing the tags across my post. Thank you everyone again! 👍
17th Oct 2017, 1:39 AM
Zephyr Koo
Zephyr Koo - avatar
+ 4
my one https://code.sololearn.com/WP35CG6WZ66D/?ref=app example: text: Sololearn nro: 3 output: loSelonra
18th Sep 2017, 6:18 AM
ysraelcon
ysraelcon - avatar
18th Sep 2017, 1:12 PM
Zizibee
+ 4
My second solution in python. A bit longer but much better to anderstand: https://code.sololearn.com/csd9zxe2cyt2/?ref=app
18th Sep 2017, 1:31 PM
Zizibee
18th Sep 2017, 4:56 PM
VcC
VcC - avatar
18th Sep 2017, 1:17 PM
Jhoniel Viloria
Jhoniel Viloria - avatar
+ 3
Here You go in Java. Checks for valid length input. https://code.sololearn.com/cpwnmPxC5VtV/?ref=app
29th Sep 2017, 10:14 PM
Vari93
Vari93 - avatar
+ 3
https://code.sololearn.com/cMEgzsZh8s8L/?ref=app
16th Oct 2017, 2:11 PM
Kartikey Sahu
Kartikey Sahu - avatar
+ 1
I will try
16th Oct 2017, 2:28 PM
Sayantan Sinharay
Sayantan Sinharay - avatar
16th Oct 2017, 6:52 PM
VcC
VcC - avatar
20th Oct 2017, 3:18 PM
ⵢⴷⵢⴷ
ⵢⴷⵢⴷ - avatar
- 1
HERES A NEW CHALLENGE CHECK IT AND TRY IF YOU WANT https://www.sololearn.com/discuss/793924/?ref=app
17th Oct 2017, 3:14 PM
sayan chandra
sayan chandra - avatar