I got through part one but got stumped on part 2 because I was passing the example but my answer was too high. After seeing your solution I see that while looking at the positions of the blanks I did not handle the case of the position of the blank being after the file position (the if start >= pos check in the while loop). For both cases I did not actually move the files, but rather calculated the checksums there by using the index it would be moved to. I modified the blank spaces the same way though - shrink them if len(file) < len(blank) or pop if len(file) == len(blank)
@oldmajor52402 күн бұрын
nice! I wrote a really dumb solution naively creating the entire string and simulating everything as said in the problem. to deal with the ids, I just used unicode characters😂😅
@BillyNix2 күн бұрын
I can't believe I forgot that the dense representation had the sizes of spaces and files. I was following the example representation. Glad to see you implemented what I realized after I had already submitted my answer.
@MrRys2 күн бұрын
nice solution, I saved the memory as pairs of id(blank id=-1) and size, and then just switched the ids and sizes in a loop
@Skromez2 күн бұрын
hey HyperNeutrino, thank you for sharing your solutions with detailed explanation, i'm sometimes struggling with problems like these, it's easier for me to actually try to modify input to the expected result to make sure i'm doing everything correct, but sometimes that just makes things worse, but your explanation is really helpful to approach the problem from other direction and just coming up with correct data structures, really appreciate it!
@bencered2 күн бұрын
Awesome stuff! This solution is a lot more efficient than mine... (Took about an hour to run)
@griffinbaker8602 күн бұрын
here's the gaussian solution for the last part for anyone curious: *SPOILER* print( sum(fid * size * (pos + pos + size - 1) // 2 for fid, (pos, size) in files.items()) )
@yajusgakhar69692 күн бұрын
My solution was (for part 1): Make an array of all the files, Start adding (val * index) If find a blank, add the (last element * index) As you add the values, pop them out of the list Essentially blank meant add from behind or the end of the list Still fixing my logic for part 2
@terryaney73Күн бұрын
You ever post your run times? Curious how much slower my typescript version runs compared to your python :)
@hyper-neutrinoКүн бұрын
i could consider benchmarking but i don't have a reliable and consistent setup for that but i could. also your solution is probably faster, JS/TS is significantly faster than python in my experience
@kedarshinde42162 күн бұрын
very unrelated but what font do you use in vscode it looks cool
For part 2, I think blanks = blanks[:i] is basically useless (doesn't really make it faster), but blanks.pop(i) makes it like 10x faster! nice, i wasn't expecting it