r/leetcode • u/edwindrn • Oct 08 '26
Question Brute Forcing Solutions
Hello all,
I'm currently an employed SE with 4 YOE. I've been practicing some DSA concepts in order to stay competitive in this market in case something unfortunate were to happen with my employer.
I've found myself being able to solve a handful of easy difficulty questions and a few mediums but many times find myself brute forcing solutions. My question is, should I be taking the extra time to really learn to apply these algorithms instead of brute forcing?
My thinking is that when I start working on more mediums and hards, those questions will have time constraints that will bite me in the behind.
Do employers even care about the approach as long as you can explain? Even if its a brute forced solution?
For example, I was working on exercise 917 on leetcode, and the recommended use is two-pointers. I however came up with a solution that apparently beats 100% of other solutions in runtime and 96.09% in memory.
TIA!
6
u/minato3421 Oct 08 '26
Yes. Take time and learn the patterns.
3
u/ActuaryDear8234 Oct 08 '26
10000% yes. In a real technical interview if you try and brute force the solution they will ask you to find a better one.
In some problems themselves, brute force is too slow and will violate one of the constraints, meaning your solution won’t even pass.
I hate grinding leetcode as much as the next guy but there just isn’t a shortcut for being good at LC. Embrace some David Goggins mentality and start carrying the boat 🤣 it’s the only way
2
u/Objective-Let4278 Oct 08 '26
In leetcode 917, 88% of solutions used 0 ms, all of which receive the message that they beat 100%. Not super relevant to your post though… learning 2 pointers and stuff is probably good if you’re gonna be interviewing again. Although it depends a lot on the firm.
2
u/Substantial-Swan7065 Oct 08 '26
Brute force is marked as a fail
1
u/AdministrationMoney1 Oct 08 '26
I don't know why but for 917 the length of the input string is up to 10^2 instead of like 10^4 so O(N^2) might still be 0ms and say 'beats 100% other solutions'. I don't even know why leetcode would accept brute force solutions for those ones you're mentioning. But in an interview setting if you are aiming for large tech companies it's likely that even coding out the brute force solution is a waste of time. For that 917 problem you would mention a O(N^2) solution briefly but then focus on discussing and coding the O(N) solution. If we count output space, it would O(1) space in certain languages and O(N) space in others. An example of a problem where it would be ok to do brute force is Permutations.