When presented with a problem how do you solve it? Sometimes it’s difficult to come up with an efficent solution on the spot, what’s best is to drum up the most direct solution you can find - brute force and work backwards from there. You may have to think outside the box of what the question is really asking - what are the input values? what is the expected output?
The answer you may percieve may not necessairly mean do it; built it - it may just want to determine a count but you’re going through X,Y and Z to return something simple. With these questions it’s sometimes best to take a step back and take a breather, as the more you fixate on your solution the more clouded your mind gets. It’s sometimes best to take a step back look at the actual problem or even ask the provider of the problem, what they are truely looking for.
These problems are daunting, i’m not going to sit here and say this is easy I still struggle with this. Sometimes you don’t know when to step back or when to say this isn’t working let me try something else or look at something else. It’s a learning process for sure but i’m making my way there.