FAILING THE 6KYU CHALLENGES - Codewars Challenges #8

NeuralNine · Intermediate ·💻 AI-Assisted Coding ·2y ago

Key Takeaways

The video demonstrates solving Codewars challenges using Python, with a focus on the 6KYU challenge, and discusses various concepts such as pairwise difference, sorting, and iterating through a list, as well as algorithmic complexity and optimization.

Full Transcript

what is going on guys welcome back it's time again for a casual Code War session where I'm going to try to solve programming challenges without editing out any mistakes or any thought processes that I have so let us get right into [Music] it all right now for those of you who don't know what code Wars is it's a platform where you can do programming challenges you have the different difficulty levels here 8q being the easiest one and one Q being the hardest one and the idea of this format the purpose of this format is to show you my thought process so that you can see how someone else solves these problems if I succeed of course uh and I also want to include the mistakes the wrong approaches if there are any because I think it's important especially for beginner programmers to see that programming is not always straightforward it's a lot of trial and error it's a lot of Googling certain aspects of libraries or of functions uh or of algorithms now of course not Googling the solution this would be too easy but Googling certain aspects um looking up the documentation of python or something like this and also the purpose of this is entertainment so if you just want to watch and and watch me solve the problem the idea is I don't edit out any mistakes I show you the wrong approaches I show you when I fail I show you when I have to Google the Only Rule is I'm not allowed to Google the solution I'm not allowed to use chat GPT or anything I'm only allowed to use stuff like documentation or stack Overflow for basic uh things like how to sort a list in a certain way or how to flatten a list if I need that so little pieces of code are allowed to be copy pasted or at least to be looked up but in general I have to solve the problem myself I don't edit out anything but what I want to try for this video today is I want to edit out at least the silent sections of just thinking because sometimes to solve a problem I need to just shut up for 5 minutes and look at it and think about it and if I always have to comment about what I'm thinking exactly every second uh this will of course inhibit my my problem solving ability so I'm going to try to cut a little bit uh more to edit out a little bit more this time but not because I make mistakes but because I just want to edit out the boring sections where I don't do anything uh all right so the difficulty level I usually go for in these videos is six and five so I'm going to start with six as a warm-up here um and we're going to try to solve something that we haven't seen before obviously so let's look at this one difference of two the objective is to return all pairs of integers from a given array of integers to have a difference of two the result array should be sorted in ascending order of values assume there are no duplicate integers in the array the order of the integers in the input array should not matter so okay so we get one and three because they have a difference of two two and four and if we have 1 3 3 5 4 6 okay I think this should be quite easy so let's go ahead and solve this in Python two different so we get a list and we get a list of numbers so if I go and open up a or actually let's do that at the desktop let's say um experiment. py okay I actually have this file already or let's go and edit anyway um so the idea is I get some input of numbers the order can be whatever so something like this I mean we have no duplicates so something like this maybe and the goal is to get all the um pairs of numbers that have a difference of two so actually I think now my first thought here is if I go from smallest to highest shouldn't I get all the numbers by just checking if the next number has a difference of two so I would just go and say sort the list then I would get a list like this and then all I have to do is I have to iterate I have to start with one and I have to ask looking at the next number so looking at two is there a difference that is two no okay so I go to two is the difference between two and five two no go to Five is the difference between five and seven too yes so save it 57 is the difference between seven and 8 to no is the difference between 8 and 10 to yes save it and then 10 and 14 no I think that is straightforward and it should probably work so what I'm going to do now is I'm going to increase this here and we're going to just say four um I think we need to do that with the index because if I do a for each loop we're not going to get the next element so I'm going to say 4 I in range length list and then I'm going to say for or I'm going to say um result is an empty list then I'm going to say for I in range length list if list I um if list I +1 minus list I is equal to if that is equal to two exactly then I'm going to say result append list I actually yes a list list I and list I + one and that's actually it right so I just have to return in the end result the only thing is I think I have to go minus one here I'm not sure about that but I think so so let's see if that works for the test no okay so okay because we need to have a tuple not a list but also because I get an empty list for what exactly uh Mt should equal 13 so why do I not get that oh okay got it uh because I didn't think about the following thing if I have a three here of course I have to also check for one and three okay so you can already see I missed something uh okay so how can we do that basically we have to go um now I don't know if that's the most efficient solution but you have to just look at a number and and see I mean what's what's less efficient uh if I go for each number and I go until I find a number or how would I do that maybe I could do something like um let's do it like this for I in range length list 4 J in range starting at i+ one until length list I guess and we can just say if um yeah if list J minus list I equals 2 result append um list I list J L if list J minus list I oh I also forgot something else because the problem is I didn't sort the list I need to sort the list first otherwise it doesn't make sense um so if that is larger than two then of course we can break out of this Loop and I need to sort the list so I need to say LST is equal to sorted LST now this is not the most efficient way to do this but I think it should work unless I forgot something okay it works but I'm not sure if that is the optimal solution probably not because this if we think about it in terms of algorithmic complexity sorting is done in I think um o of n log n um yeah so and log in and then you have I mean what is this isn't this pseudo linear not sure what is pseudo [Applause] linear I think that was super linear um but yeah this takes some time and then this iterates over the whole list so we have o ofn it's already linear uh or actually to linear and then linear and in here we have I mean what's the worst case you have to go all the way until the end is that actually true because you can go Max of two steps right if you go more than two steps this should be o of two right or am I stupid right now because you shouldn't be able to go beyond two steps I mean it's it's not super complex right it's not extremely inefficient but I'm thinking is there a more efficient way to do that um I mean another way to do that I'm just going to do it down here as as a comment is to say for each element for element in list check if this element plus two in list and if yes then add it but then this checking operator is again I mean that would be quadratic wouldn't it because I'm looking up I think that would be quadratic quadratic runtime complexity I think that's not as inefficient so we're just going going to submit that so attempt and there you go let's see what the other Solutions are okay this is interesting we have a set of a then what does he do here I mean he does the okay it's it's small in terms of code I'm not sure if that's not quadratic because 4X in a iterates over the whole set meaning you have a linear runtime complexity and for each of these he does an in which again has to iterate over the set to check if it's in so I think that is um concise code but I'm not sure if that's not less efficient than my solution I'm not not sure about that um yeah everything that has a membership in a four is probably I'm I'm not sure if I'm I'm talking nonsense right now but I would assume it's quadratic this is also quadratic you iterate overd array two times this is uh I don't think that's as efficient yeah so I think the solution is quite good uh let's go for another one let's go for um again a 6 q1 I'm just going to open a couple of them now the important thing is they shouldn't be too can I maybe sort them by not newest but by or actually let's go for newest I don't want to do anything that's too um comprehensive in the description because I don't want to spend too much time reading the description here in the video allocating hotel rooms this seems okay allocate customers to hotel rooms based on their arrival and departure days each customer wants their own room so two customers can stay in the same room only if the departure day of the first customers earlier than the Arrival Day of the second customer okay the number of rooms used should be minimized a list or array of end customers um is the input each customer is represented by a tuple Arrival Day departure day okay I mean this is basically a scheduling somewhat of a scheduling problem uh clearly customers wanted to cannot get okay but the room doesn't matter so or do they have any okay so they don't have a preference for a specific room they just have to be in separate rooms I think we can do that let's see uh let's use my local uh editor again so the idea is we have a list of we have a list of tupal and the tupol represent you know starting arriving day one leaving day five um arriving day three leaving day six arriving day one leaving day two arriving day five leaving day uh day seven then maybe yeah what do we have maybe staying just one day whatever um now the important thing is to just separate them so that they don't overlap so I would say that we want to have um I mean can we do it like this we start by saying let's do something like while list not or while not list empty so or maybe we can say why length of list is larger than zero we're going to do the following we're going to say that room is going to be one the first room is going to be one and then we're going to say okay we're going to add the first customer to room one so let's say we have our solution it's going to be an mty list and we're going to say okay uh first customer so for for customer in list we're going to say at the customer or how do we do that how do we model that um now for the first one I want to assign obviously just the room number one so that's not too difficult the question is how do I decide let's say I have a one already in here and let's say I have I mean I cannot just delete it right because then I have nothing let's do it in a different way let's say I have a dictionary solution dictionary where I have the room numbers as keys and the list of uh so let's say one the list of customers s uh values here so so let's say I already removed that so I say if the list is empty just add him add him to the list if the list is not empty so for example for three and six what do I have to do I have to say if solution dictionary room if the length of this is zero we just say solution dictionary [Music] room um or actually we don't even have no we're going to do it another way we're going to say if if room in solution dictionary. keys we're going to do something else we're going to say solution dictionary uh room is going to be equal to uh it's going to be equal to the customer in a list all right and if there already is a a customer like right now what I have to do is I have to save I mean this is now not very efficient but let's do it let's say for uh now I cannot use customer again for C in and then solution dictionary room we need to see if they overlap so we need to say if and now my arrival date has to be after their departure date or can it be on the same day okay no earlier so it has to be a difference and also my depart okay so basically I have to check if the C if c one or let's say if customer Arrival Day Zero comes before c departure day or if C arrival day comes before customer departure day then I have to to increase room by one so let me just make this a little bit larger here and I want to break the loop I want to break this Loop here so I'm here again does this make sense no actually uh if I break out of this Loop I'm in this one again so I go to the next customer but I'm not done with this one so I don't want to go to the next customer I don't think that's correct we need to restart the loop actually so basically we need to repeat the process until I have gone through all the rooms how do I do that um I start with one then I say I have a new customer then I say I think that's a problem I think if room and solution keys should be inside another loop so we can say done equals false while not done now these are a lot of nested Loops probably we have to do some optimization here but basically the idea is to say here we have done equals true and here now we say okay if yeah we need to break here otherwi wise we can say solution dict room append customer and we can say done equals true I think this should work because now what we're doing is yeah I mean this should work I guess it's probably not very efficient but what we need to do in the end of course is we are done and we need to say [Music] solution oh now we have another problem but this is not really a um solution problem it's more like how do we translate this now into into the proper output format because the output format is just the the order and we don't keep track of it so now a Brute Force way to do that is to just add to each of them an index like this uh one and then and so on um we can do that just to see if it works so we would have to say something like for element in list now let's call this list actually for element in list we need to say or actually for element for I element in enumerate list we want to say no this is kind of stupid um I mean no we don't have to do anything we can just can do it like this we can say solution is equal to empty list and then we just have to say solution append room I think this should work or am I mistaken I think it should work let's just copy and paste this into here now we need to indent this we need to say that list is actually it's an empty dictionary and here we don't have list we have customers and I think I don't use list oh I do customers there you go uh and in the end I just want to return solution so basically I have return solution 1 2 34 right yeah shouldn't this work let's try I mean maybe it's very inefficient that could be a problem with a timeout that could be a real problem problem though so maybe it works but it works in a very inefficient way yeah timeout okay we cannot do it as inefficiently uh let's see now obviously this is I mean we have one two three four Loops nested this is definitely too too complex now let's just see if this actually works at least locally here list equals 15 let's just print in the end solution let's print solution dictionary oh boy this is already very slow for just four instances or maybe the problem is not maybe actually it's not about the inefficiency maybe it's not not even terminating ah I know why because we're not removing the elements from the list um so maybe it's not that inefficient maybe it's about popping list. remove um list. remove the customer that would be it right wouldn't that be the solution yeah I think I mean does this make sense yeah actually none of them can be in the same room right uh let's me let me just change this a little bit let's change this to to six and eight okay but actually this should work right so six and eight should fit into one and five why doesn't it why does it choose to add it to a new room so the room oh I'm probably not resetting the room number right yeah if I'm yeah okay that's also an issue still a problem what's the problem um okay so we get the customer we try to fit him into into a new room now we see we start at room one and we try to see if 68 can fit into room one so room one is in the solution we try to see let's say C is our 68 and customers our 15 now customer zero is one that is less [Music] than oh this is not what I'm checking for what I want to be checking for I want to actually do the opposite or am I wrong am I stupid [Music] um customer one is before customer no wait need to do it like this no still still a problem I'm brute forcing this right now let me think about this again so 15 and 68 if one now when would they be incompatible either if six is actually smaller than five that would be incompatible if if c0 is greater than than this so actually customer one is five and it's greater than this no it's not but this is greater than this okay um that's actually not the correct check because okay so we need to say if this is the case and so this can actually be greater than this as long as this is also greater than this so customer zero is smaller than C1 or this thing does this make any sense what do you mean X is not en list how can it not be in the list if customer if anyone at the second position is larger than the other one at second at the first position and at their first position they're smaller is this actually what I'm checking for I mean what I'm actually trying to do is I'm trying to say they shouldn't overlap so the last one let's maybe put this a different way customer one has to come before customer zero or customer I mean customer one has to come before C 0 or c0 has to come or C C1 has to come before customer zero and if that's not the case then we have a problem is that correct there you go now we have it now we have it or do we no this doesn't work no doesn't work because three and six let me just think so why does he think that this is an okay solution let me just copy this and uh put it as a comment here so this is obviously okay now I have a list 1 two 44 to this now I consider adding 36 or it's probably done the other way around so I probably have 3 six and one two and I'm considering adding 4 four what does the check do it says oh okay got it we need to do it at the end of the loop because we need to go through all the [Applause] elements uh what did I do here [Music] um I think I'm making this more complicated than it has to be um okay for customer in solution dictionary room I'm trying to see if that customer has a problem if there's a problem with any customer in that room I need to increase the room number and I have to break out of the loop and then I want to restart actually [Music] M I think the order is messed up I have a room if if I don't have the room at all I create a new one if I do have a customer that conflicts so let's use the the example again I have one two so I say four four doesn't conflict with one two because of that I do not get into this and I go to the next one I go to 36 okay when I go to 36 I see that there is a conflict so I increase the room number by one and break out of the loop but when I break out of the loop I I do this this is not intelligent I shouldn't do that oh I think this is one of these magical moments where we need to use a for else I think this could work boom that's one of the magical moments where we can actually use four El's because the idea of four El's for those of you who don't know is uh you only get into this Branch if you don't break out of the loop yeah this makes sense okay let's go so let's copy this and try to put it here let's try to indent this let's replace LST with um customers and this should not be probably this should be a dictionary otherwise I think it's a set I'm not sure and in the end we want [Music] to come on 1 two 3 4 return solution okay I don't think this will work but let's see number of rooms EX seats number of customers how is this possible what's the what's the input I get here I already get this for the first result how can that be actually now I copied the wrong thing uh 122 444 one two 22 44 no 24 sorry it's not true I get 112 but 112 is not correct right actually my solution is correct but the order is messed up because that should actually be considering I mean it should be one two one which I think is valid one 12 one okay so I'm probably experiencing a problem with the with the order here where do I add to the solution I add to the solution well actually shouldn't that be I mean does it even represent my solution no not really I mean let's just print what's happening when I say uh a pen solution print [Music] appending customer and then room let's do that here as well okay so why is this appended why is this appended before I do anything with the other one so why is this one appended before this one for customer in list okay why is this one handled first I don't get it let me just see can I delete this there you go uh why is my [Music] customer I mean what is that's the list and he goes to this one how and why is this some am I stupid right now or is this some python behavior that I don't understand this is my list and I then tell him four elements in this list and he picks this one why here I get the list in the correct order why is this happening interesting for customer inlist and he handles the second one first I don't understand let's see for each python wrong order okay this is some something else this is this is not what I'm looking for I think it's probably some obvious mistake that I'm not seeing right now for customer in list list is a certain list now let me just comment this out so we have less stuff to worry about I'm just interested in the list and why the customer is picked in a different order I have this list uhuh this looks different now I have the list for customer in list I start with one two so I print one two done equals false while not done we don't have anything yet so I go here and I say room one is customer okay and I append to the solution room one for the first element then I remove this customer from the list which is probably why I jump to the next one do I even need to do that is this Loop even necessary I think so I mean what happens if I remove it or actually I don't want to remove it because no let me let me think about this we start with this Loop room equals one print list I got this print statement twice so it does execute a second time the problem is I think with the iteration maybe if I don't remove and I don't have the while loop this could work just fine no unexpected indent okay this is syntax related okay I need to solution though um there you go okay if it works I'm going to explain it in a second but the idea is remove this shift this to the left get rid of this statement was this everything I changed yeah okay now it works okay so the difference is that the problem was that I was iterating over the list while removing elements from the list so maybe I can show this here in a Python 3 shell if I have my list with the values 1 2 3 4 5 and then I say four element in my list let me just zoom in a little bit Four Element in my list print element and my list remove element then I get this 135 and not 1 2 3 4 5 because the problem is I say for element uh it iterates over the list but while it's iterating over the list I'm removing Elements which leads to problems all right so that is now a solution that works let me see if I can optimize it in any quick way here because I don't want to spend too much time on this I think I want to do another one um so I think I'm going to just quickly see if I find some quick optimization here we're basically saying we have an empty solution we have an anti solution dictionary now we need the dictionary to keep track of this comparison we need to also iterate over all of them to make sure I mean we don't probably have we probably don't have to but I don't want to do some some calculations now to figure out if I fit in in between some some specific section of the dictionary I mean we could probably instead of keeping track of all the individual um customers we could probably Define like a a range or we could Define ranges that are occupied but I think I'm going to just leave it like this and we're going to see if there is some much more intelligent Solution by someone else so I'm going to attempt and Hope hope that this doesn't take too long come on holy what is this random tests testing number of customers 787 rooms needed 414 number of allocated rooms is larger than necessary okay come on why is that okay I think we're not going to do another one I have to do this one and get it right using more rooms than necessary means that I'm rejecting without having to reject and I'm only rejecting actually here if I'm only rejecting in this case and this case is too strict which means that there should be cases in which I should allow something that I'm not allowing here let me just get rid of all the stuff here what could be such a case it seems to happen only with large numbers so why is that the case [Music] customer is let's say one90 C is and what's the condition now customer one has to be less than customer less than c0 so it has to be less than whatever this is 91 for example 200 or customer zero has to be larger than so it would be something like this 91 and 200 and C would be in one and 90 these are the only two cases I accept are there other cases could there be a case where neither of the two is the case so where c0 is greater no C 0 is less than customer one so let's say customer let's say customer is just 10 and 20 now c0 is less than 20 let's say five and customer zero now it doesn't make sense does it I'm not sure I mean isn't this by definition I mean maybe let's consider multiple instances um let's say I have a oh I think let's say I have the following list already I have one five then I have 6 10 then I have 11 50 then I have 55 uh 100 something like this and then I want to add a new element let's say I want to add 52 54 what would happen I would go and say okay looking at 15 and 52 54 I mean this should work right because customer one five is less than this so it works or does it yeah I mean we don't do anything so we jump to the next one 610 Works 1150 works and then I get to 55 100 and it also works so when do I reject a possible solution I'm not I'm not sure I understand because when I do test it passes all the tests but when I do attempt it somehow doesn't work with the random examples nonoverlapping tests random all overlapping tests random tests so where we do have some overlaps this is more difficult than I thought for a 6q challenge or maybe I'm just stupid but we have a solution dictionary with all the rooms I would like to have such an example I I would like to see the example that doesn't work uh but I don't want to print everything now so what is the I mean these are just a sample tests I would like to see the random tests can I see the input or anything number of customers rooms needed there's probably some intelligent algorithmic solution to this that is super simple I don't understand why I use more rooms because in order to use more rooms than necessary I have to reject I have to reject um I have to reject rooms that I wouldn't have to reject so in order to use more rooms than necessary I have to say okay you don't fit into this room even though you would fit into this room because the only reason why I add a new room is that true am I maybe increasing the room number too early that could be another that could be another problem no I think I I get into this if there is an overlap then I increase the room by one I break out of the loop since I'm breaking out I'm not getting into this boom repeat if room in yeah I mean I don't know the problem is I don't have an example I cannot even troubleshoot this because I don't know uh where this would fail because all the all the examples that I have here they work so it works for at least small numbers I guess so what could happen when we scale it up what would happen when I have oh I I have an idea or I'm not sure if I have an idea but let's say I have something like 50 no actually yeah let's say this is 53 and let's say I have here something like 54 54 would just cause some issues customer one is less than this this is not true but customer zero is larger than this so it shouldn't reject it what if I try to add something like this 53 it should work how would I not get the optimal number of rooms here because the only thing I'm doing is I'm looking at a solution I'm I'm looking at a candidate and I'm saying in a given room we start with room one I want to see do you fit into this room for this I see does this room already exist if it exists I want to see what are all the customers in the room if there's a conflict we go to the next room we break that is as simple as it gets so why what does not work the condition for something to be compatible is that they don't overlap and overlap means that one has to start before the other one ends one has to start so um or to be compatible one has to start after the other one ends or the other one has to start before the one ends what are examples of compatibility one and two is compatible with with uh or let's go with two and three is compatible with 1 one two and three is compatible with 44 two and three is also compatible with um with anything like four and [Music] 10 two and three is also compatible with anything like yeah if if if we go below let's say we can do something like zero and uh one as well is there anything any other chance any other possibility to be compatible with 23 because the same day is not allowed as as far as I saw you're not allowed to have the same day so if it's on the same day it's not allowed and does this condition reject any of these let's say this is customer this is C customer one is below C1 no okay a c0 okay but this is below this yeah so either this has to be below this or this has to be below this this has to be below this or this has to be below this this has to be below this or this has to be below this and it's always the case so I guess that this is not the problem if that is not the problem the problem must be something else the problem must be that I'm increasing the room too early too often something like this does it say somewhere how many more rooms I use is this some slight difference or is this a huge difference okay it doesn't really tell me how many rooms I use maybe I use just one more room it did work here though so oh here as well so it does work occasionally but often times it doesn't which confuses me even more when I reject I increase the room by one and I break and I'll repeat the process and now I have room two okay guys um I don't know I don't want to give up on this I think instead of just giving up and looking at the solution I'm going to break one of the rules I'm going to say that um I'm going to use GPT to see if I can get some answer from it so let me just open this on my second screen here I'm going to see if I can get some some magical solution I have this code to solve um the problem of placing customers in hotel rooms without overlap it does work most of the time but for some reason I have an issue with large randomized instances I I use more rooms than necessary why could that be I mean this is just I mean this is just efficiency stuff right so this doesn't really produce problems now let me just see uh I'm just going to copy paste this to see if that uh solves the problem so then we can analyze it but often times it doesn't so I don't want to spend time looking at code that doesn't solve the problem uh let's just copy paste this actually let's do it come on let's just do it like this and we're going to replace list by customers so first of does this still work it does work here now when I attempt no okay it it produces the same problem okay so let's just return to what it was before it's kind of embarrassing to be honest I'm not sure if I'm really that stupid right now or if it's not not that easy um let me just rephrase this I am now I don't see what I'm typing I am not talking about inefficiencies did I spell this correctly inefficiencies I am talking about not using the optimal number of runs oh this makes sense okay this is true okay oh now I get it I'm using a greedy approach I'm just checking does it fit into a room I'm not checking what's the optimal order okay okay so this is okay I'm not going to do this now but I understand now what the problem is the problem is not that my check is wrong per se it's that my algorithm is a greedy algorithm trying to to just see okay does it fit into this room no does it fit into this room no does it fit into this room yes so put it in there instead of asking asking does it fit into any other room and what's overall the best solution so my Approach Works per se so it finds a solution and probably it's not the worst solution as you saw often times it finds the optimal solution but this is the the stuff that I usually show you in these algorithmic problems um yeah I'm not I'm just not going for the optimal algorithm I'm not what I would be interested in is um is this an NP complete problem okay it's an m i mean if if he's correct I'm not sure if chat GPD is correct right now but if this is an NP complete problem you basically have to bruteforce it for the optimal solution or not let me just just try again to to ask him if it's if it's MP complete let me just open up a new instance uh oh what kind of algorithmic problem is this interval scheduling problem interval scheduling problem NP part NP complete when some groups contain three or more intervals okay so this shouldn't be NP NP complete actually okay but I think I can say that I somewhat failed this I mean I got a solution that works it's not the optimal one so let's just skip this and see uh now actually I wanted to see the solution uh unlock Solutions there you go so yeah there you go this is unfiltered unedited I failed this and this would have been a nice easy solution uh what is rest and depth length customers result I guess for I a and sorted enumerate customers sorting them by their end date so by their um departure date okay so it's just it just creates yeah I mean this is this is just a different order this is also done here with a heap it's just a completely different algorithm I went for the greedy solution where I just put everything together and often times this results in the um so I I basically fit every single customer into the first possible room which oftentimes leads to a good solution but not always and yeah I mean it's actually I I think this is quite hard for a 6q challenge now maybe maybe I'm just too incompetent to solve it but also the solutions here I think you either know about this you know the algorithmic problem the interval scheduling problem and you apply the solution to it in this case if you if you just know it or if you've thought about this already then it's quite easy but if you didn't do that then coming up with a solution yourself is a little bit hard for 6q I guess so yeah I can say that I failed that I'm not going to do another one so I think that's it for today just two challeng Alles I think it was still interesting uh we had to apply for else I think the solution does work it comes up with a valid solution it doesn't come up with the optimal solution so we can say we solved it to some degree but we didn't solve the the cata itself yeah so that's it for today's video I hope you enjoyed it and hope you learned something if so let me know by hitting a like button and leaving a comment in the comment section down below and of course don't forget to subscribe to this Channel and hit the notification Bell to not miss a single future video for free other than that thank you much for watching see you in the next video and bye by

Original Description

Today we do some Codewars challenges again. And I fail the 6KYU challenge. ◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾ 📚 Programming Books & Merch 📚 🐍 The Python Bible Book: https://www.neuralnine.com/books/ 💻 The Algorithm Bible Book: https://www.neuralnine.com/books/ 👕 Programming Merch: https://www.neuralnine.com/shop 💼 Services 💼 💻 Freelancing & Tutoring: https://www.neuralnine.com/services 🌐 Social Media & Contact 🌐 📱 Website: https://www.neuralnine.com/ 📷 Instagram: https://www.instagram.com/neuralnine 🐦 Twitter: https://twitter.com/neuralnine 🤵 LinkedIn: https://www.linkedin.com/company/neuralnine/ 📁 GitHub: https://github.com/NeuralNine 🎙 Discord: https://discord.gg/JU4xr8U3dm
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from NeuralNine · NeuralNine · 0 of 60

← Previous Next →
1 Visualizing Stock Data With Candlestick Charts in Python
Visualizing Stock Data With Candlestick Charts in Python
NeuralNine
2 Python Beginner Tutorial #1 - Installation and First Program
Python Beginner Tutorial #1 - Installation and First Program
NeuralNine
3 Python Beginner Tutorial #2 - Variables and Data Types
Python Beginner Tutorial #2 - Variables and Data Types
NeuralNine
4 Python Beginner Tutorial #3 - Operators and User Input
Python Beginner Tutorial #3 - Operators and User Input
NeuralNine
5 Python Beginner Tutorial #4 - If Statements and Conditions
Python Beginner Tutorial #4 - If Statements and Conditions
NeuralNine
6 Python Beginner Tutorial #5 - Loops
Python Beginner Tutorial #5 - Loops
NeuralNine
7 Python Beginner Tutorial #6 - Sequences and Collections
Python Beginner Tutorial #6 - Sequences and Collections
NeuralNine
8 Python Beginner Tutorial #7 - Functions
Python Beginner Tutorial #7 - Functions
NeuralNine
9 Python Beginner Tutorial #8 - Exception Handling
Python Beginner Tutorial #8 - Exception Handling
NeuralNine
10 Python Beginner Tutorial #9 - File Operations
Python Beginner Tutorial #9 - File Operations
NeuralNine
11 Python Beginner Tutorial #10 - String Functions
Python Beginner Tutorial #10 - String Functions
NeuralNine
12 Python Intermediate Tutorial #1 - Classes and Objects
Python Intermediate Tutorial #1 - Classes and Objects
NeuralNine
13 Python Intermediate Tutorial #2 - Inheritance
Python Intermediate Tutorial #2 - Inheritance
NeuralNine
14 Python Intermediate Tutorial #3 - Multithreading
Python Intermediate Tutorial #3 - Multithreading
NeuralNine
15 Python Intermediate Tutorial #4 - Synchronizing Threads
Python Intermediate Tutorial #4 - Synchronizing Threads
NeuralNine
16 Python Intermediate Tutorial #5 - Events and Daemon Threads
Python Intermediate Tutorial #5 - Events and Daemon Threads
NeuralNine
17 Python Intermediate Tutorial #6 - Queues
Python Intermediate Tutorial #6 - Queues
NeuralNine
18 Python Intermediate Tutorial #7 - Sockets and Network Programming
Python Intermediate Tutorial #7 - Sockets and Network Programming
NeuralNine
19 Python Intermediate Tutorial #8 - Database Programming
Python Intermediate Tutorial #8 - Database Programming
NeuralNine
20 Python Intermediate Tutorial #9 - Recursion
Python Intermediate Tutorial #9 - Recursion
NeuralNine
21 Python Intermediate Tutorial #10 - XML Processing
Python Intermediate Tutorial #10 - XML Processing
NeuralNine
22 Python Intermediate Tutorial #11 - Logging
Python Intermediate Tutorial #11 - Logging
NeuralNine
23 Python Data Science Tutorial #1 - Anaconda and PyCharm Setup
Python Data Science Tutorial #1 - Anaconda and PyCharm Setup
NeuralNine
24 Python Data Science Tutorial #2 - NumPy Arrays
Python Data Science Tutorial #2 - NumPy Arrays
NeuralNine
25 Python Data Science Tutorial #3 - Numpy Functions
Python Data Science Tutorial #3 - Numpy Functions
NeuralNine
26 Python Data Science Tutorial #4 - Plotting Functions With Matplotlib
Python Data Science Tutorial #4 - Plotting Functions With Matplotlib
NeuralNine
27 Python Data Science Tutorial #5 - Subplots and Multiple Windows
Python Data Science Tutorial #5 - Subplots and Multiple Windows
NeuralNine
28 Python Data Science Tutorial #6 - Matplotlib Styling
Python Data Science Tutorial #6 - Matplotlib Styling
NeuralNine
29 Python Data Science Tutorial #7 - Bar Charts with Matplotlib
Python Data Science Tutorial #7 - Bar Charts with Matplotlib
NeuralNine
30 Python Data Science Tutorial #8 - Pie Charts with Matplotlib
Python Data Science Tutorial #8 - Pie Charts with Matplotlib
NeuralNine
31 Python Data Science Tutorial #9 - Plotting Histograms with Matplotlib
Python Data Science Tutorial #9 - Plotting Histograms with Matplotlib
NeuralNine
32 Python Data Science Tutorial #10 - Scatter Plots with Matplotlib
Python Data Science Tutorial #10 - Scatter Plots with Matplotlib
NeuralNine
33 Python Data Science Tutorial #11 - 3D Plotting with Matplotlib
Python Data Science Tutorial #11 - 3D Plotting with Matplotlib
NeuralNine
34 Python Data Science Tutorial #12 - Pandas Series
Python Data Science Tutorial #12 - Pandas Series
NeuralNine
35 Python Data Science Tutorial #13 - Pandas Data Frames
Python Data Science Tutorial #13 - Pandas Data Frames
NeuralNine
36 Python Data Science Tutorial #14 - Pandas Statistics
Python Data Science Tutorial #14 - Pandas Statistics
NeuralNine
37 Python Data Science Tutorial #15 - Pandas Sorting and Functions
Python Data Science Tutorial #15 - Pandas Sorting and Functions
NeuralNine
38 Python Data Science Tutorial #16 - Pandas Merging Data Frames
Python Data Science Tutorial #16 - Pandas Merging Data Frames
NeuralNine
39 Python Data Science Tutorial #17 - Pandas Queries
Python Data Science Tutorial #17 - Pandas Queries
NeuralNine
40 Python Machine Learning Tutorial #1 - What is Machine Learning?
Python Machine Learning Tutorial #1 - What is Machine Learning?
NeuralNine
41 Python Machine Learning Tutorial #2 - Linear Regression
Python Machine Learning Tutorial #2 - Linear Regression
NeuralNine
42 Python Machine Learning Tutorial #3 - K-Nearest Neighbors Classification
Python Machine Learning Tutorial #3 - K-Nearest Neighbors Classification
NeuralNine
43 Python Machine Learning #4 - Support Vector Machines
Python Machine Learning #4 - Support Vector Machines
NeuralNine
44 Python Machine Learning Tutorial #5 - Decision Trees and Random Forest Classification
Python Machine Learning Tutorial #5 - Decision Trees and Random Forest Classification
NeuralNine
45 Python Machine Learning Tutorial #6 - K-Means Clustering
Python Machine Learning Tutorial #6 - K-Means Clustering
NeuralNine
46 Python Machine Learning Tutorial #7 - Neural Networks
Python Machine Learning Tutorial #7 - Neural Networks
NeuralNine
47 Python Machine Learning Tutorial #8 - Handwritten Digit Recognition with Tensorflow
Python Machine Learning Tutorial #8 - Handwritten Digit Recognition with Tensorflow
NeuralNine
48 Generating Poetic Texts with Recurrent Neural Networks in Python
Generating Poetic Texts with Recurrent Neural Networks in Python
NeuralNine
49 Stock Portfolio Visualization with Matplotlib in Python
Stock Portfolio Visualization with Matplotlib in Python
NeuralNine
50 Analyzing Coronavirus with Python (COVID-19)
Analyzing Coronavirus with Python (COVID-19)
NeuralNine
51 Making Text Images Readable Again with Python and OpenCV
Making Text Images Readable Again with Python and OpenCV
NeuralNine
52 Neural Networks Simply Explained (Theory)
Neural Networks Simply Explained (Theory)
NeuralNine
53 Motion Filtering with OpenCV in Python
Motion Filtering with OpenCV in Python
NeuralNine
54 Top 5 Programming Languages To Learn in 2020
Top 5 Programming Languages To Learn in 2020
NeuralNine
55 Simple TCP Chat Room in Python
Simple TCP Chat Room in Python
NeuralNine
56 Image Classification with Neural Networks in Python
Image Classification with Neural Networks in Python
NeuralNine
57 Edge Detection with OpenCV in Python
Edge Detection with OpenCV in Python
NeuralNine
58 S&P 500 Web Scraping with Python
S&P 500 Web Scraping with Python
NeuralNine
59 Simple Sentiment Text Analysis in Python
Simple Sentiment Text Analysis in Python
NeuralNine
60 Introduction - Algorithms & Data Structures #1
Introduction - Algorithms & Data Structures #1
NeuralNine

This video teaches how to solve Codewars challenges using Python, with a focus on the 6KYU challenge, and discusses various concepts such as pairwise difference, sorting, and iterating through a list, as well as algorithmic complexity and optimization. The speaker provides a step-by-step solution to the challenge and discusses the importance of optimization and efficient coding. The video is suitable for intermediate learners who want to improve their coding skills and learn how to solve algorit

Key Takeaways
  1. Sort the list of integers
  2. Iterate through the list to find pairs with a difference of two
  3. Use a dictionary to store room numbers and their corresponding customers
  4. Check if a customer fits into a room without considering the optimal order
  5. Increase the room number if there is an overlap
  6. Break out of the loop if a room is found
💡 The greedy algorithm approach may not always result in the optimal solution, and a more optimal approach may be needed to solve the challenge.

Related Reads

📰
Stop Expecting “One-Shot” Miracles: The Real Way to Work with Coding Agents
Learn to work effectively with coding agents by understanding their limitations and potential, and why a one-shot approach is not the best way to utilize them
Medium · AI
📰
Introducing Carrick
Learn about Carrick, a context layer for polyrepo TypeScript teams that enables AI coding agents to search and validate code across services
Dev.to AI
📰
Why I Switched from Ponytail to Guardsman for AI Coding
Learn how Guardsman improves AI coding by teaching agents to write accountable code, a crucial step beyond just writing less code
Dev.to · Antoinette C. Lennox
📰
How to Learn With AI Without Letting It Do the Thinking for You
Learn to leverage AI as a tool without losing critical thinking skills by setting boundaries and using it to augment your learning process
Medium · AI
Up next
Microsoft 365 Copilot ULTIMATE Guide: Excel, Word, Outlook & More!
Maksims Sics
Watch →