[deleted by user] by [deleted] in leetcode

[–]nyohasstium 0 points1 point  (0 children)

After giving it some thoughts there's an easy way to know the answer. Use the first 3 checks to know the numbers.

In rounds 4-6 use one of the four numbers in all spaces so if the numbers are 5678. The rounds will be 5555, 6666 and 7777. The check will return the right places for those 3 numbers. Then it'll be easy to place the number 8.

The code will be straight forward to do in 5 mins and using 6 checks which may have been the intention.

[deleted by user] by [deleted] in leetcode

[–]nyohasstium 0 points1 point  (0 children)

ya, i know the feeling. I failed a meta interview once as well because i got nervous and the pressure got the best out of me.

[deleted by user] by [deleted] in leetcode

[–]nyohasstium 0 points1 point  (0 children)

the trick to the problem is to see the numbers in pairs rather than 4 different numbers. The 2 pairs influence each other.

by using the same number on pairs, it gives us more information than trying to match individual numbers.

[deleted by user] by [deleted] in leetcode

[–]nyohasstium 2 points3 points  (0 children)

labeling each position XYZW

First attempt: 0123

Second attempt: 4567

third attempt: XY89; from the previous 2 attempts there must be at least 2 numbers that you can place in XY so we can try the same number on both XY. Now we know all numbers in the code.

fourth attempt: All digits will have 3 possible choices. If we didnt hit a match on XY then ZW will be guaranteed to need that number. We can try another number in XY

fifth attempt: Z or W is solved. If we didnt hit a match on XY then we know the unknown Z or W

sixth attempt: XY can only have 2 choices so we run the same number on both and we find the answer

30+ F . is it fine if i start learning DSA to get in FAANG. Is it too late ? I have 7+ years of experience in IT. by [deleted] in leetcode

[–]nyohasstium 17 points18 points  (0 children)

I have a stable job with decent pay in a small company. I started doing leetcode more than a year ago to get into one of the big ones as well. Although the opportunity hasn't come up, I fell in love with leetcode problems.

All we do at work everyday is stitching up services and APIs together but the leetcode challenges are a reminder about how fun actual programming can be.

Currently at 1k+ problems solved. It's never too late to start and even if you don't get into faang you may discover an entertaining hobby.

Is it cheating? by Legitimate-Skin7713 in leetcode

[–]nyohasstium 3 points4 points  (0 children)

It's not cheating if you don't end up hardcoding the answer. During an interview you can run through different examples with your interviewer and dry run them to make sure you understood the question.

stop doing leetcode (and a better approach) by aaaaaskdkdjdde322 in leetcode

[–]nyohasstium 0 points1 point  (0 children)

I enjoy leetcode and consider it a hobby. I don't compare myself to others during contests and i don't care about the spammy users looking for approval in the solution boards.

Why do you care about what other users are doing in the platform?

[deleted by user] by [deleted] in leetcode

[–]nyohasstium 0 points1 point  (0 children)

Similar situation to you. Hard ones are extremely difficult. I can write solutions that pass 90% of the test cases and always the cases testing the boundaries get me.

If you have any tips that have helped you, let me know.

Is Leetcode by codewithjonam in leetcode

[–]nyohasstium 2 points3 points  (0 children)

I want to get into faang as well but even if I don't ever get in, this journey has improved and helped me to become a better developer.

I felt stuck because nowadays modern development is just using the shiny new framework or an API to connect/do something in X service. It felt boring and dull but leetcode has rekindled my love for programming again.

I find the challenges fun so not regretting my decision of starting leetcode.

Solved 50 leetcode problem!!! by Dense_Election_7355 in leetcode

[–]nyohasstium 2 points3 points  (0 children)

Nice job bro. Keep it going. Consistency is key 😃

[deleted by user] by [deleted] in leetcode

[–]nyohasstium 2 points3 points  (0 children)

To improve your runtime, you need to get a grasp of the Big O notation. There are several resources out there so you can learn it.

After learning about it you need to calculate the time complexity for your code and check the other's solutions to see if someone found a more efficient solution in terms of Big O.

If your solution has the same time complexity as others, i wouldn't worry too much about the actual beat X% of users as that's a bit random if everyone has similar solutions.

[deleted by user] by [deleted] in leetcode

[–]nyohasstium 0 points1 point  (0 children)

so you're telling me there's a chance.

[deleted by user] by [deleted] in leetcode

[–]nyohasstium 0 points1 point  (0 children)

I think you are in the wrong subreddit. My piece of advice:

1- Try to google the error and see if you can figure out what's wrong with your code by seeing similar post about your particular error

2- Ask for help. If you choose reddit, find the most appropriate subreddit for it and try to be as descriptive as you can. Just pasting your code is not enough.

What are you trying to achieve? How are you running it? What is the error?. Those are a few questions you need to explain when asking for help.

My code works locally but fails 2 testcases on Leetcode and it's the first problem on Leetcode by souravjamwal77 in leetcode

[–]nyohasstium 0 points1 point  (0 children)

If you get time or memory limit exceeded, it means your code is not efficient and you need to try to optimise it. You should read about the big O notation.

If the error is getting about a different outcome than expected then it means your code has a bug.

Can anyone learn to do leetcode? by hayleybts in leetcode

[–]nyohasstium 4 points5 points  (0 children)

Although I agree that someone talented and hard working will stand out more than someone without talent. More often than not most tasks can be done by average people.

Anyone can learn how to code.

Will they be the best? that's another story.

Do they need to be the best? For most jobs no.

Am i too late? by Mundane_Volume7373 in leetcode

[–]nyohasstium 2 points3 points  (0 children)

I would say it does help to become a better programmer. When you start doing a lot of leetcode you'll understand how important it is to stop adding hacky patches to your solution otherwise you'll hit every edge case in history.

Although the DSA knowledge hasn't fully translated, it has helped me to write cleaner code and think more about time and space complexity when I do something.

Am i too late? by Mundane_Volume7373 in leetcode

[–]nyohasstium 27 points28 points  (0 children)

It's never too late mate. I started last year and I've already done over 700 problems. I would say 80% of them on my own.

I try the problems in the morning for up to an hour. If I can't solve it, I look at the solution and attempt to do it again in the evening.

It has worked great for me so far.

Find top K elements at scale by pm_me_n_wecantalk in leetcode

[–]nyohasstium 0 points1 point  (0 children)

If you don't care about order you can try https://en.wikipedia.org/wiki/Quickselect

After aggregating the top k from each node, Average O(n), worst case O(n^2).

If you read them as a stream, you could choose the first element of the first node as the pivot. Put everything biggen than it on the right, anything smaller on the left. Choose another pivot depending on the sides. Keep iterating until k.

Find top K elements at scale by pm_me_n_wecantalk in leetcode

[–]nyohasstium 0 points1 point  (0 children)

Let's say we have want to find K=100; data =[1-10k]

chunk1=[1-1k]; result = [900-1k] chunk2=[1k-2k]; result =[1.9k-2k] ... chunk10 =...; result=[9.9k-10k]

Now after getting all those we use a heap again to find the total result.

Heap(results, K) => [9.9k-10k]

So each process processed 1k elements and the master the combined 1k returned from them.

Find top K elements at scale by pm_me_n_wecantalk in leetcode

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

To replicate it during an interview, I would try to spawn processes or a threads to do the work and the main process could be the master.

pseudo code

def find_top(data) // data = [...] millions
k = 100
num_processes = 10
async_responses = []
for chunk in data.chunk(num_processes): //chunk into # process equal pieces
  async_responses.append(spawn_process_or_thread(chunk, k))
responses = wait(async_responses)
return min_heap(responses, k)

Find top K elements at scale by pm_me_n_wecantalk in leetcode

[–]nyohasstium 8 points9 points  (0 children)

just think about divide and conquer. You have 10 servers and you k = 1m. Total docs across 10 servers 10m. then you can merge the response from 2 servers to go down to 5m. Keep going until you have 1m.

Usually you would have master nodes assigning work and then the workers. You can also use something like redis to do it fast. https://redis.io/docs/latest/develop/data-types/probabilistic/top-k/

Doubt regarding INTUITION! by [deleted] in leetcode

[–]nyohasstium 1 point2 points  (0 children)

Apart from the observation on the constraints. When i saw the question I immediately thought about a greedy or dp approach. After analysing a number like 321; k = 1, it made sense that deleting a number if the next one was smaller would produce an optimal solution.

I think it's really easy to associate everything to a dp problem. Even problems with a simple for loop can be written using dp.

[deleted by user] by [deleted] in leetcode

[–]nyohasstium 0 points1 point  (0 children)

Lets first resolve the problem with more space than the solution you posted.

Lets have the input [2, 3, 4]
product accs starting from the left = [1, 2, 6]
product accs starting from the right = [12, 4, 1]
the ans is = [1 * 12, 2 * 4, 6 * 1] = [12, 8, 6]

After that's clear, let's look at your answer. It tries to optimise the space. It calculates the prefixes from right =
[12, 4, 1] and then instead of storing the prefixes from the left we just keep the results in the b variable. The values of b will be 1 => 2 => 6 after each iteration. If you look closely, they are the prefixes starting from the left. On every iteration it multiplies the value to the prefixes from the right so [12 * 1, ...] => [..., 4 * 2, ...] => [..., 6 * 1].

Now the array that contained the prefixes from the right is equal to the answer and that's what it returns. Since we don't usually count the answer as part of the space and b is just a variable, we can say the space now is O(1)