✅ Repeated Letters
Hi, I have a question, how do I do this in C#, I have no idea, I've tried many ways
35 Replies
what are some of the ways you've tried?
everything i saw on overflow, youtube
and this
dear lord what is that
i said i tried
so, first thing is you never need to actually care which letter it is, only if it's the same as the one before it
ok
Maybe you can do this
Sort each word alphabetically and search of there are 2 same letters one after another
@Caioon9 split the string first via
string.Split(' ')
then do nested loop on it
the outer loop is your splitted string and the two inner loops will be comparing each character
so the tree should look like this
we can do this with linq quite easily but bcos you're just started with the language lets just do it manuallyWHAT IS THIS
he's learning the language, saying that would not help him solve the question
true
it's a fun question, you should try to solve it
Do we have a DSA related channel?
no response, anyway here
Gg the most brute force wat
Way*
SlimStv#2835
REPL Result: Success
Console Output
Compile: 329.912ms | Execution: 60.766ms | React with ❌ to remove this embed.
lmao 😽
if you're confused with how it works, let me know
even if we wanna avoid linq and also brute force it I can't leave a triple nested loop here as the solution. It is not needed and should be avoided
instead of doing
for
for
for
try to solve doing only
for
for
sure, feel free to post your answer
Also to be clear, linq shouldn't be avoided if you already grasp the fundamentals.. in this case, it is clear that they're new to the language
I'd rather let him try to get it but if you ask for it. Since we wanna avoid using Linq i go based of your solution and just remove the most inner loop. Here is some pseudo code, I dont have an IDE installed
you can do it here
!eval
command
or go to https://dotnetfiddle.net/ and do it there and paste the link herelmao
i am
@BadaBingBadaBoom https://dotnetfiddle.net/rKMKWl here is how I implemented it without using Linq. Sorry for late response. I haven't tested it much but It should be working tho
I just switched ever and greatest around in the input and checked if that would change my output and it did
that's incorrect
it shouldn't care about the order
yes it should
it says it should give the first word having the most same letter in it
ever
isn't the most same letterthe first word with greatest number of repeated letterssince both greatest and ever only have 2 when we swap those in input that changes output its two e's in ever. greatest has two e's and two t's so both have two as their maximum of repeated letters. so we return the first word of those two thats how I understood the task and solved it and it works under those requirements ^^ but would be easy to adjust I'm pretty sure I got the task right and you missunderstood it. Read the text again, it counts two e's and two t's but never adds them up and counts them as 4 for greatest and if you were to write it with linq grouping on the character, ordering by their count then you would have the same behaviour
AABBCC
-> AABBCCDD
-> AABB
:: which one of those 3 is the 1st greatest with repeating letters?the first entry
all have two as their maximum but the first entry is the first word having the most (2) amount of repeated letters @BadaBingBadaBoom
the output has to be the first word with repeated letter
can you send me a link to that task? do they have tests on that website?
it's a closed test, I don't think there's any way to send it
but I will try
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.