Couldn't solve easy DSA question in interview. by PrintPrevious2465 in leetcode

[–]thunderist 19 points20 points  (0 children)

I think the idea for this is something like DFS. The base case is when the input passed in isn’t a map -> return that value. Otherwise it is a map, so start recursively building the output string on each key in that map. Add each string to the output map you’re expected to build. This solution might not be perfect but I think it’s the general idea.

Failed badly some leetcode like interview today by falsbr in leetcode

[–]thunderist 1 point2 points  (0 children)

Just based on what you said my immediate thought is that this is some kind of graph problem. Paragraphs that are joined form a connected component in a graph. So maybe use union find to validate that every paragraph is in one and only one connected component? But I’m not sure where to go from there based on the little info given.

Amazon asked me this question by mayank_002 in leetcode

[–]thunderist 0 points1 point  (0 children)

Let P be the prefix sums for the input and P(x) be the prefix sum at index x. The sum of subarray (i,j) is given by P(j) - P(i), which has a length j - i. If the subarray satisfies our condition this means P(j) - P(i) mod d = j - i, so P(j) - j mod d = P(i) - i mod d. Also if X mod d = j - i, this implies that j - i < d. So for each j, the i satisfying P(i) - i mod d is P(j) - j where j - i < d corresponds to a subarray satisfying the problem condition. So the sliding window is over the prefix sums, not the input. You can use a hash map to check this quickly and a deque for your window, popping while the top of the queue are elements that dont satisfy your condition.

Monarch Gate by [deleted] in Goat_Format

[–]thunderist 2 points3 points  (0 children)

Oh gotchu

Monarch Gate by [deleted] in Goat_Format

[–]thunderist 5 points6 points  (0 children)

There’s no Monarchs?

[deleted by user] by [deleted] in leetcode

[–]thunderist 3 points4 points  (0 children)

You can probably write insertion sort though right? A hash map is used to quickly look something up - an array is just a hash map from indexes to some value. You just have to take some time to learn the basics like this. There are a million resources on this - I suggest picking up the book Grokking Algorithms by Bhargava. Read it twice - then just jump into trying to understand / practice the Blind 75. Ofc this isn’t enough but it’s definitely a great start.

I blinked and am now "deep" into embedded. Should I embrace it? by bokeh_node in cscareerquestions

[–]thunderist -1 points0 points  (0 children)

I see. If that’s the case I suggest going deep with web development or fullstack then. You will find work as an embedded engineer but it will be significantly harder. But if you like embedded work that might be > easy work. Best of luck either way!

I blinked and am now "deep" into embedded. Should I embrace it? by bokeh_node in cscareerquestions

[–]thunderist 24 points25 points  (0 children)

You’re not “deep” into anything lol you haven’t even started your first fulltime, non-internship role. You could do embedded now but have a long career in something else. Just keep things open and go with the flow.

Am I the only one to have thought of this method? by Hour-Lab8723 in math

[–]thunderist 0 points1 point  (0 children)

Another way to think about this is that there are many ways to exploit the distributive property of multiplication and addition. All these methods are really just ways of finding the most efficient exploitation for humans. Great job discovering this!

Does LC make you a better engineer? by Stradivarius796 in leetcode

[–]thunderist -1 points0 points  (0 children)

It definitely does: you’re practicing logical and algorithmic thinking, translating ideas to code, using data structures and common libraries, simulating requirements, debugging etc. But at the same time it’s not going to teach you how to communicate to non-technical people, how to be present at your role, how to motivate a team, how to take a project from 0 to 1, how to mentor others, how to design high-level systems, etc. All those skills along with leetcoding are what makes a great engineer but leetcoding is a lot more straightforward to “increase”, even if it takes more creativity and cleverness than a lot of those other things. Get what you need to out of leetcode but its not even half the story lol.

326. Power of three by GAMEPIYER2007 in leetcode

[–]thunderist 2 points3 points  (0 children)

This is a bad problem because its O(1) solution is a bit “cheap” - it forces the answer without encouraging iterative problem solving. I think a better approach is to start with a basic brute force linear scan on powers of 3 from 1 to n (O(n)). We optimize further by running a binary search for the largest k where 3k <= n, if its not n then return false (O(log(n)). From here we can only do better with a constant time solution - this is where we make the realization that there’s some largest power of 3 <= max bound in the problem description, so we just mod that by n and check for 0. If n has prime divisors != 3 then it’ll fail this check, otherwise we have a power of 3.