#๐ Need Help Finding A Good Approach
23 messages ยท Page 1 of 1 (latest)
@hollow hornet
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
sample input/output
i just need help with the approach to solve this
if anyone respond pls ping me
one way to check divisibility by three is to see if the sum of all digits is divisible by three
so if the sum of digits isn't divisible by 3, you just have to find what digits can be deleted to make it so
for example in 2009, you can delete consecutive digits (2), (2, 0), and (2, 0, 0) => three ways
why is the first one output 4
in 1005, it's already divisible by three, so that counts as one way
then you can delete the first zero, the second zero, and both zeros together (since they're consecutive), so 4 ways in total
I see
but how do i do that tho? i can only delete 1 digits at a time with that thinking
the problems says we can delete the digits but has to be consecutive
I imagine the simplest way is to try every combination possible and check the outcome of all of them. The fun would be how to optimize that
i can also think of brute force approach like you but i do believe there would be a better apporach
(I haven't tested this, just some ideas)
first find what the remainder is
then iterate through the digits:
if you can find a digit that is that remainder OR gives that remainder when divided by 3, that's one way
if that digit is followed by a number of zeros, each of those counts as a way
else consider the next digit plus the previous one, is that equal to or gives the remainder, and so on
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.