I swear sometimes the hardest thing about CTF is thinking you're solving it "wrong" or "too easily" so you spend ages looking for the correct way, only to watch videos on youtube of people just basically doing it the same way you did 😂😂
Extremely helpful! But I have a question regarding the very first __init__ function and the “self” that keep repeating across the code. Would be very helpful if you can explain this point 2:30
Sure thing. In Python, when we define a method, or function that will belong to an object, the first parameter is always a self reference. Technically, we can call the self reference whatever we want, but the standard is just "self". That way, we can refer to the object itself and grab properties or other methods from it to be used within the method being defined. We can also use it to set properties on the object, which is what we see a lot during the __init__ method. Let me know if this explanation is clarifying. I know class definition and the idea of objects can be confusing (it's all so abstract!). Thanks for watching!
This one was weird for me. Every video I saw has done it the same way you did. It wouldnt let me login with anything at all. Always came back 404. But if I put in the URL with /flag it just gives me the flag. Either way. Thanks!
Have a look on this approach too function queensAttack(n: number, k: number, r_q: number, c_q: number, obstacles: number[][]): number { const os = new Set(obstacles.map(([a,b]) => `${a}_${b}`)); function st(rowOp: number,colOp: number): number { let steps=-1; let row = r_q; let col = c_q; while(!(row < 1 || col < 1 || row > n || col > n)) { if(os.has(`${row}_${col}`)) break; row += rowOp; col += colOp; steps++; } return steps; } return ( st(+1,-1) + st(+1,0) + st(+1,+1) + st(0,+1) + st(-1,+1) + st(-1,0) + st(-1,-1) + st(0,-1) ) }
This is a much nicer approach. Using the set lookup is efficient and reworking the logic for each direction as parameters is very elegant. Well done and thanks for watching!
kinda weird that you know what a hexadecimal number is, but you don't know the most common representation of it? PS: Do you have short term memory? (I am not trying to be mean) Cause like, you instantly forgot what a function you just analysed does...
Hey, thanks for watching! I don't really work with hexadecimal numbers too often, so it took a bit to remember how they work. I'm not sure what you mean about forgetting a function. Which function do you mean? I fully admit I'm not the best programmer - after years on the job, I'm still learning 😀
@@arjix8738 Oh, haha, yes! Good catch. I was thinking about the first step of the function, but completely forgot about the second step indexing the list😅
Very Simple Solution: # Write your code here for i in a: if (i.isupper() and i not in b): return "NO" for j in b: if j not in a.upper(): return "NO" return "YES"
for input of GAAATAAA the hackerrank solution says correct answer is 5 but minimum value can be 4 as we can replace 4 A's out of 6 with G T C . AM i right this way?
The key limitation is that we can only replace a CONTIGUOUS substring. So you are correct about replacing the four A's in your example of "GAAATAAA", but in order to get those A's we have to include the one T - even if we are not changing it. Let me know if that makes sense, and thanks for watching!
Oh, do you mean a link to the code? I put it in the description, but here it is again: gist.github.com/Shaddyjr/88d3babf082fe869bc550a42ee56f6e0 I hope that helps!
let b = [] let c = 0 for (let i=0; i<a.length; i++) { for (let j =i+1; j<a.length; j++) { if (a[i]==a[j]) { //console.log(i,j) b [i] = j-i c = 1 } } } let min = b[0] for (let i=0; i<b.length; i++) { if (min>b[i]) { min = b[i] } } if(c==0) { min = -1 } return min my code
Great explainer! I was stumped on this one for a couple of days. I was able to get all tests to pass except #8 which failed due to time complexity. Going through your solution I like how you declared useful variable names instead of trying to keep track of what q[i] -1 is supposed to represent. Thanks for helping me understand how to solve more efficiently.
Same as Joshua I did a lot of Math.min and foor loops in a first solution, but i was suspecting that i made a lot of inecesary stuff haha Thanks for the content
I think you missed the point but still got the flag haha. actually you can't login to "Joe", but since you used a lowercases "j" to "joe" you still logged in. The manipulation you did work with every user/password
I did not come to this, or rather, I just thought that it was impossible (although it turned out I did not try). but I managed to outweigh the balance to a positive value by selling a large number of products with a minus sign (such as -123456789 flags). thanks for the solution!
Definitely an interesting solution, nice one! I wonder why you couldn't just sort the original list straight-up for the same time complexity? Surely just `return sorted(unsorted)` would do the trick? Another question I thought about here was the true time complexity of sorting the strings: because they're stored in string format, and we can't (maybe in python we actually can, but nvm that for a moment) convert them directly to an integer, which has O(1) comparison using a CPU instruction, surely when comparing two strings when sorting, we in fact need to compare every character separately...? The only thing I can't tell is whether this introduces another factor into thr time complexity or not, because it definitely seems like more work, but is it technically constant because the inputs are no more than 2*10^5 in number?
Hey, thanks for watching! I didn't go into detail about sorting the list of numeric strings as it is, but doing so reveals 2 big problems. The first problem is that programming languages have an upper limit on how big an integer can be (as well as be reliable & "safe"). In python the max unsigned integer is 18,446,744,073,709,551,615 (as a string this would be 20 characters long) - meaning any number larger than this cannot be held in memory. In JavaScript, the max safe integer is 9,007,199,254,740,991 (as a string this would be 16 characters long). This is why we cannot handle these numeric strings as integers, they're just too big having a length of way more than 16 or 20 characters. So, we have to sort them as strings, which reveals the 2nd problem. Strings are sorted lexicographically, which is similar to how words are sorted in a dictionary. "A" goes before "Axe", which both go before "Be" - the same way numeric strings would be sorted as "1" goes before "183", which both go before "23". The sorting we need still has to use lexicographical sorting, but in such a way that it results in typical integer sorting. Hence the added complexity for the solution. In the video, I do make an error regarding the time complexity. I should have used a proper variable to denote the length of the string, it's not constant as I implied. Each string gets compared and is sorted for each string, so the total time complexity is more like O(k*nlogn) Let me know if that doesn't make sense.
I think this is a very good explanation but if you want to become more popular slides need to be improved. The algorithm part can be improved a lot with some more air and a few colors. Top channels has pretty visuals (sometimes messy) but it helps create your style. I believe, this aproach, like "debugging", is very appreciated by juniors like me, but often is a like hard to follow. Thanks for the video.
Good question! I really should have labeled them when I made this video 😞 The Y-label should read "Count of players" and the X-label should read "Player position when game ends".
i can't believe you have this few views, great video quality :) just one small question, im not very well versed in neural networks (i've listened to a lot of explanations but never written one myself) but should the validation set really be sequential? i was thinking there might be some correlation for the first few numbers that doesnt hold in the long run and that it should probably be randomly selected. thanks for answers!
This is a great question! In short, the validation set does NOT need to be sequential and is often randomized, like you suggest. In my example, I was keeping things simple for the sake of explaining. However, a train_test_split is appropriate and practical for the reason you mentioned. The only consideration is that we need to be consistent in how we handle the split to ensure the test input (X_test) and expected output (y_test) remain aligned. The scikit-learn package offers a helpful function for this called `train_test_split` (scikit-learn.org/stable/modules/generated/sklearn.model_selection.train_test_split.html). This essentially takes the total input (X) and expected output (y) and randomly selects indices returning the training input and expected training output (X_train & y_train) as well as the testing input and output (X_test & y_test). Thanks for watching!
Thank you. I see that this approach is solving it. What I don‘t quite get is this: Why can‘t I just compare the rowsums with the colsums? imho rowsum(i)==colsum(i) - otherwise impossible. (I tried that, but doesn‘t work for all tests.)
I totally get where you're coming from. It wasn't clear when I was first doing this either. Let's look at an example that I hope is clarifying: 5 1 3 1 5 2 2 3 5 Each row is a container. - The first row/container has 9 balls in it, which means it can only ever hold 9 balls (given the swap mechanic). Let's call this container A. - The second row/container has 8 balls in it (container B). - The third row/container has 10 balls in it (container C). Each column is a unique color - There are 8 balls belonging to the first column/color. Let's call this color Red. - There are 9 balls belonging to the second column/color (color Blue). - There are 10 balls belonging to the third column/color (color Yellow). We have one container that can fit each color: - Container A can hold color Blue - Container B can hold color Red - Container C can hold color Yellow However, if we just compare the row and column sum by their original index we'd have a problem, since there is no order enforced on which containers or colors are listed first. - row 0 (container A) holds 9 balls, but column 0 (color Red) only has 8 balls in total. - row 1 (container B) holds 8 balls, but column 1 (color Blue) only has 9 balls in total. - row 2 (container C) holds 10 balls and column 2 (color Yellow) has 10 balls in total, so this happens to work out. If we sort the counts for rows and columns then we can line them up by their new sorted index. - sorted row list 0 holds 8 balls (this corresponds to container B), which can hold sorted column list 0 (color Red). - sorted row list 1 holds 9 balls (this corresponds to container A), which can hold sorted column list 1 (color Blue). - sorted row list 2 holds 10 balls (this corresponds to container C), which can hold sorted column list 2 (color Yellow). I hope this helps. Thanks for watching!