William Y. Feng
William Y. Feng
  • 167
  • 289 043
Leetcode Weekly Contest 407
In this video, I do Leetcode Weekly Contest 407 and explain all four problems & solutions.
Erratum: ended up with rank 600-something, not 400-something. 🤷
LINKS 🔗
Contest: leetcode.com/contest/weekly-contest-407
Leetcode playlist: ua-cam.com/play/PLsqh-jhhTL2-1J8o1_yWdjzmSIdWZ2swb.html
CHAPTERS 📚
00:00 Intro
00:27 Timelapse
00:37 Problem 1
03:18 Problem 2
05:46 Problem 3
09:07 Problem 4
20:10 Outtro
Music: Covert Affair and Lobby Time by Kevin MacLeod
Переглядів: 310

Відео

USACO 2023 December Gold Explanations, Problem 3: Haybale Distribution
Переглядів 2468 місяців тому
Code: github.com/womogenes/usaco-2023-dec-gold Problem: usaco.org/index.php?page=viewproblem2&cpid=1355 Part 1: ua-cam.com/video/lQFZ9PW-jXQ/v-deo.html Part 2: ua-cam.com/video/gJM8JtTz3oA/v-deo.html In this video, I explain the third problem from the USACO 2023 December Gold contest.
USACO 2023 December Gold Explanations, Problem 2: Minimum Longest Trip
Переглядів 1868 місяців тому
Code: github.com/womogenes/usaco-2023-dec-gold Problem: usaco.org/index.php?page=viewproblem2&cpid=1354 Part 1: ua-cam.com/video/lQFZ9PW-jXQ/v-deo.html Part 3: ua-cam.com/video/_fTl_1nqxa4/v-deo.html In this video, I explain the second problem from the USACO 2023 December Gold contest.
USACO 2023 December Gold (promo'ed to platinum!) Explanations, Problem 1: Flight Routes
Переглядів 3788 місяців тому
Code: github.com/womogenes/usaco-2023-dec-gold Problem: usaco.org/index.php?page=viewproblem2&cpid=1353 Part 2: ua-cam.com/video/gJM8JtTz3oA/v-deo.html Part 3: ua-cam.com/video/_fTl_1nqxa4/v-deo.html I finally promoted to USACO Platinum division with a full score on the 2023 December Gold contest! In this video, I explain the first problem from that contest. Part 3 coming soon.
Day 17: Clumsy Crucible | Advent of Code 2023
Переглядів 4079 місяців тому
Code: github.com/womogenes/AoC-2023-Solutions Puzzles: adventofcode.com/2023/day/17 AoC 2023 playlist: ua-cam.com/play/PLsqh-jhhTL292ZlyyruyLTXFcFj1RqkG0.html
Day 16: The Floor Will Be Lava | Advent of Code 2023
Переглядів 2159 місяців тому
Code: github.com/womogenes/AoC-2023-Solutions Puzzles: adventofcode.com/2023/day/16 AoC 2023 playlist: ua-cam.com/play/PLsqh-jhhTL292ZlyyruyLTXFcFj1RqkG0.html
Day 15: Lens Library | Advent of Code 2023
Переглядів 7339 місяців тому
Code: github.com/womogenes/AoC-2023-Solutions Puzzles: adventofcode.com/2023/day/15 AoC 2023 playlist: ua-cam.com/play/PLsqh-jhhTL292ZlyyruyLTXFcFj1RqkG0.html 00:00 Intro 00:30 Solve 00:44 Part 1 explanation 03:40 Part 2 explanation 10:51 Outtro
Day 14: Parabolic Reflector Dish | Advent of Code 2023
Переглядів 7759 місяців тому
Code will be uploaded to the repo soon. Code: github.com/womogenes/AoC-2023-Solutions Puzzles: adventofcode.com/2023/day/14 AoC 2023 playlist: ua-cam.com/play/PLsqh-jhhTL292ZlyyruyLTXFcFj1RqkG0.html 00:00 Intro 00:25 Solve 00:38 Part 1 explanation 05:08 Part 2 explanation 12:39 Outtro
Day 13: Point of Incidence | Advent of Code 2023
Переглядів 1,2 тис.9 місяців тому
Code: github.com/womogenes/AoC-2023-Solutions Puzzles: adventofcode.com/2023/day/13 AoC 2023 playlist: ua-cam.com/play/PLsqh-jhhTL292ZlyyruyLTXFcFj1RqkG0.html 00:00 Intro 00:26 Solve 00:40 Part 1 explanation 07:02 Part 2 explanation 11:01 Outtro
Day 12: Hot Springs | Advent of Code 2023
Переглядів 4 тис.10 місяців тому
Code: github.com/womogenes/AoC-2023-Solutions Puzzles: adventofcode.com/2023/day/12 Today brought a bit of an algorithmic challenge! I explain my bash solution to part 1 and my dynamic programming approach to part 2. AoC 2023 playlist: ua-cam.com/play/PLsqh-jhhTL292ZlyyruyLTXFcFj1RqkG0.html 00:00 Intro 00:21 Solve 00:35 Part 1 explanation 04:25 Part 2 explanation 16:58 Outtro
Day 11: Cosmic Expansion | Advent of Code 2023
Переглядів 45410 місяців тому
Code: github.com/womogenes/AoC-2023-Solutions Puzzles: adventofcode.com/2023/day/11 AoC 2023 playlist: ua-cam.com/play/PLsqh-jhhTL292ZlyyruyLTXFcFj1RqkG0.html 00:00 Intro 00:27 Solve 00:40 Part 1 explanation 03:54 Part 2 explanation 04:37 Outtro
Day 10: Pipe Maze | Advent of Code 2023
Переглядів 4,4 тис.10 місяців тому
Puzzles: adventofcode.com/2023/day/10 Code: github.com/womogenes/AoC-2023-Solutions Breadth-first search (BFS): en.wikipedia.org/wiki/Breadth-first_search Puzzle difficulty is ramping up 😬 AoC 2023 playlist: ua-cam.com/play/PLsqh-jhhTL292ZlyyruyLTXFcFj1RqkG0.html 00:00 Intro 00:21 Solve 00:35 Part 1 explanation 05:13 Part 2 explanation 11:37 Outtro
Day 9: Mirage Maintenance | Advent of Code 2023
Переглядів 69910 місяців тому
Ranked 85/44 today :) Puzzles: adventofcode.com/2023/day/9 Code: github.com/womogenes/AoC-2023-Solutions AoC 2023 playlist: ua-cam.com/play/PLsqh-jhhTL292ZlyyruyLTXFcFj1RqkG0.html 00:00 Intro 00:45 Solve 00:48 Part 1 explanation 06:29 Part 2 explanation 07:20 Outtro
Day 8: Haunted Wasteland | Advent of Code 2023
Переглядів 1,9 тис.10 місяців тому
Puzzles: adventofcode.com/2023/day/8 Code: github.com/womogenes/AoC-2023-Solutions AoC 2023 playlist: ua-cam.com/play/PLsqh-jhhTL292ZlyyruyLTXFcFj1RqkG0.html 00:00 Intro 00:34 Solve 00:48 Part 1 explanation 04:23 Part 2 explanation 10:44 Outtro
Day 7: Camel Cards | Advent of Code 2023
Переглядів 1,2 тис.10 місяців тому
Puzzles: adventofcode.com/2023/day/7 Code: github.com/womogenes/AoC-2023-Solutions AoC 2023 playlist: ua-cam.com/play/PLsqh-jhhTL292ZlyyruyLTXFcFj1RqkG0.html 00:00 Intro 00:27 Solve 00:40 Part 1 explanation 07:17 Part 2 explanation 10:21 Outtro
(Rank 35/6) Day 6: Wait For It | Advent of Code 2023
Переглядів 98910 місяців тому
(Rank 35/6) Day 6: Wait For It | Advent of Code 2023
Day 5: If You Give A Seed A Fertilizer | Advent of Code 2023
Переглядів 6 тис.10 місяців тому
Day 5: If You Give A Seed A Fertilizer | Advent of Code 2023
Day 4: Scratchcards | Advent of Code 2023
Переглядів 1,4 тис.10 місяців тому
Day 4: Scratchcards | Advent of Code 2023
Day 3: Gear Ratios | Advent of Code 2023
Переглядів 6 тис.10 місяців тому
Day 3: Gear Ratios | Advent of Code 2023
Day 2: Cube Conundrum | Advent of Code 2023
Переглядів 1,2 тис.10 місяців тому
Day 2: Cube Conundrum | Advent of Code 2023
1% Editing Skills, 99% Automation Skills
Переглядів 781Рік тому
1% Editing Skills, 99% Automation Skills
How to Simulate Gravity in Scratch
Переглядів 780Рік тому
How to Simulate Gravity in Scratch
Harvard-MIT Math Tournament February 2023: A vlog
Переглядів 1,4 тис.Рік тому
Harvard-MIT Math Tournament February 2023: A vlog
Merry Christmas! 🎄 Day 25/25: Full of Hot Air | Advent of Code 2022 Explanations
Переглядів 1,2 тис.Рік тому
Merry Christmas! 🎄 Day 25/25: Full of Hot Air | Advent of Code 2022 Explanations
Day 24/25: Blizzard Basin | Advent of Code 2022 Explanations
Переглядів 913Рік тому
Day 24/25: Blizzard Basin | Advent of Code 2022 Explanations
Day 23/25: Unstable Diffusion | Advent of Code 2022 Explanations
Переглядів 1,2 тис.Рік тому
Day 23/25: Unstable Diffusion | Advent of Code 2022 Explanations
Day 22/25: Monkey Math | Advent of Code 2022 Explanations
Переглядів 936Рік тому
Day 22/25: Monkey Math | Advent of Code 2022 Explanations
Day 21/25: Monkey Math | Advent of Code 2022 Explanations
Переглядів 739Рік тому
Day 21/25: Monkey Math | Advent of Code 2022 Explanations
Day 20/25: Grove Positioning System | Advent of Code 2022 Explanations
Переглядів 800Рік тому
Day 20/25: Grove Positioning System | Advent of Code 2022 Explanations
Day 18/25: Boiling Boulders | Advent of Code 2022 Explanations
Переглядів 2,1 тис.Рік тому
Day 18/25: Boiling Boulders | Advent of Code 2022 Explanations

КОМЕНТАРІ

  • @tempdeltavalue
    @tempdeltavalue 8 годин тому

    03:09 it's not exactly true because you can remove similar pairs like "1 - 2" and "2 - 1" so you will get O(n^2 / 2)

    • @mateusvmv
      @mateusvmv 40 хвилин тому

      Big O ignores constants like the division by two, but yeah that's an optimization in fact, big O is too stupid sometimes: if your algorithm had a fixed amount of particles and kept all of them somewhere very far away until you chose to spawn them, but ran the quadratic algorithm to calculate the gravity, then it would be O(1) because the running time would be constant (as in, constantly the worst lol)

  • @pawelokowidza
    @pawelokowidza 9 днів тому

    15:58 ♫

  • @LakieshaKuzyk-h7l
    @LakieshaKuzyk-h7l 11 днів тому

    Damon Landing

  • @photonicsauce7729
    @photonicsauce7729 13 днів тому

    Hi just have a question. Since n-body problems (for n > 2) are known to be chaotic, isnt the barnes hut algorithm unsuitable for long time scales? The error accumulation may be significant right?

  • @pnachtwey
    @pnachtwey Місяць тому

    Use Storm's theorem.

  • @kaiyueguo1624
    @kaiyueguo1624 2 місяці тому

    Really good illustration, appreciate a lot❤❤❤

  • @Niashi24
    @Niashi24 2 місяці тому

    Good solution but it annoys me greatly when advent of code makes it so that the only way to solve the problem is to look at your specific input data for patterns and make assumptions that weren't in the instructions or the example. Going back to the previous years and this seems to be the only one in 2021 that does (unless day 25 has it, haven't gotten to it yet) but 2023 had like 5 of these. Is it really that hard to just...make the assumptions part of the problem?

  • @suryanshsingh7247
    @suryanshsingh7247 2 місяці тому

    thats was amazing

  • @askforinfo
    @askforinfo 2 місяці тому

    Which software you has been used for this presentation?

  • @BrillCodeCS
    @BrillCodeCS 2 місяці тому

    This is the best explanation of Miller-Rabin Test I've seen so far. Thanks for this.

  • @andreaslundin192
    @andreaslundin192 2 місяці тому

    This is an interesting solution for problem 4, but I am still trying to fully understand it. I can see how the location of a specific cut fully determines a set of subsets, and the number of steps we get for this given cut. However, I struggle to convince myself why one of the optimal solutions must exist among those provided by the cuts.

  • @Rozy754-i8g
    @Rozy754-i8g 2 місяці тому

    could you please provide the codes here?

  • @sloodey8315
    @sloodey8315 3 місяці тому

    thanks

  • @coopergates9680
    @coopergates9680 4 місяці тому

    My recommendation for dealing with cases where the base and test number are not relatively prime is to only remove all factors of the test number from the base if the base is indeed a multiple of the test number. If the test number is prime but is not relatively prime to the base, then the test number must divide the base, and removing all factors of it will yield a "new" base that is indeed relatively prime to the test number, so the Miller-Rabin test can still run (if the resulting "new" base is all the way down to 1, pass the test number for that base right away). This guarantees that if a composite test number does not divide the base and the test number and base are not relatively prime, the test will properly flag the test number as composite, while still allowing primes that divide an original base to pass the test.

  • @integrantedavidanoturna
    @integrantedavidanoturna 4 місяці тому

    The explanation was good enough until you brough the tortoise and the hare. Then I had to sub.

  • @potzko2552
    @potzko2552 4 місяці тому

    I "invented" this when I was in eleventh grade learning how to program, it was my first real "hard" problem I solved kinda neat seeing someone else talk about it :)

    • @WilliamYFeng
      @WilliamYFeng 2 місяці тому

      yo that's so cool :D looking back on this now I realize how many steps this actually involves, so kudos to you!

  • @TarkTheConlanger
    @TarkTheConlanger 4 місяці тому

    I feel really stupid for still not understanding how this works

  • @tanhnguyen2025
    @tanhnguyen2025 5 місяців тому

    very easy to understand.

  • @metallust
    @metallust 5 місяців тому

    why lcm??

  • @zweitekonto9654
    @zweitekonto9654 5 місяців тому

    Doesn't part2 takes like a second to run with just looping over all the edge points like this?

  • @dreawmy2912
    @dreawmy2912 5 місяців тому

    coding in word...

  • @aaronmorgan4466
    @aaronmorgan4466 6 місяців тому

    Dijkstra's algorithm, ua-cam.com/video/EFg3u_E6eHU/v-deo.html.

  • @wansichen3743
    @wansichen3743 6 місяців тому

    the age of the universe is 13.8 billion years ago

  • @ricksgarage-jf8pv
    @ricksgarage-jf8pv 7 місяців тому

    Great summary of the Pi algorithms!

  • @leducphuclong
    @leducphuclong 7 місяців тому

    Please continue, I will follow constantly!!

  • @leducphuclong
    @leducphuclong 7 місяців тому

    How a good exp !!

  • @b0nes95
    @b0nes95 8 місяців тому

    I am trying to learn dynamic programming, and for the most basic of problems like the staircase stepping I fully understand how to reach those objectie function/recurrence relationships. I had no idea how to apply DP to this problem and I thank you for taking the time to exlain it it in a table manner (non-recursive) because it truly captures the essence of dynamic programming that way, it feels like to me at least.

  • @Minji00001
    @Minji00001 8 місяців тому

    In this year i'll go😊😊

    • @akoshhh_3226
      @akoshhh_3226 6 місяців тому

      how did u know that u were accepted ? have u already sent responses to ur applications?

  • @aaditya4998
    @aaditya4998 8 місяців тому

    Just add this line before the part one if else statements #also i used value instead of amount if len(value) != 0 : value[-1] += joker else: value = [joker]

  • @0MVR_0
    @0MVR_0 8 місяців тому

    this idea is coherent as a lagrange point

  • @kaleoxy
    @kaleoxy 8 місяців тому

    Congrats on plat!

  • @filmamundo9194
    @filmamundo9194 8 місяців тому

    wtf, i was trying to do systems of equations with conservation of energy when it was this easy

  • @CursedOneShot
    @CursedOneShot 9 місяців тому

    Really Amazing video :D

  • @TheFrogfather1
    @TheFrogfather1 9 місяців тому

    Welcome back! I bailed around day 10 but am still interested in seeing the solutions for later puzzles.

  • @aspuzling
    @aspuzling 9 місяців тому

    Thank you for reminding me to rewatch the UA-cam classic Amateur by Lasse Gjertsen and for putting a different spin on it.

  • @footybite-gt1by
    @footybite-gt1by 9 місяців тому

    12.2 has been kicking my ass for 2 weeks now, I understand the purpose of pushing solutions to a map to reduce the amount of time spent processing solutions. People have tried to explain using a fib() function, which makes sense. Instinct tells me I should be running the original 12.1 to get solutions for each individual block, then multiplying out for the five. What throws me is how the combination works, there's an extra ? in the middle so the original solutions only make sense if every additional ? is a . I'm trying to understand dynamic programming and I keep getting "it's complicated, I won't go into it" 😂 I'm sat there like no, please do!

  • @HoSza1
    @HoSza1 9 місяців тому

    ok, now let's do 2048 bits 😂

  • @AlfredZhong
    @AlfredZhong 9 місяців тому

    Really solved my problem. I had no idea about the part2 as I have never heard of the Ray Casting Algorithm. 😂Thank you.

  • @lee-uq6pm
    @lee-uq6pm 9 місяців тому

    i still didnt understand how do you know to append in which box? i dont get the logic

    • @vegeta3993
      @vegeta3993 9 місяців тому

      I implemented the "hashmap" as a list of dictionaries (python3). The list is 256 elements long, and the index of the list to either place the lens into or pop from is the result of the hashing algorithm developed in part 1 on the first letters in the current line in the sequence (ie. 'rn', 'cm', 'qp', ...). Hope that helps.

  • @krige
    @krige 9 місяців тому

    Thank you for the explanation of part 2, that was very clear. Would be interesting to know what made you think to look into the input data and how you came up to the conclusion that the nodes looped. I tried to solve it by spawning a thread for each starting node and then let them run until they all reach a node ending with 'Z': this will be super fast, I thought, but instead it took forever. It never occurred to me to look into possible patterns in the input data. I am kind of disappointed about the fact they did not give any hint about the input pattern.

    • @Irakli008
      @Irakli008 9 місяців тому

      I reached the same conclusion that William did, but only after trying to do parallel runs for all of them, like you. When I tried to debug it, I took a single starting point and made it loop 10 times and logged the amount of steps per loop. I noticed that the 10th loop was 10x bigger than the 1st loop, and everything in between was also a multiple.

  • @Telepriester
    @Telepriester 9 місяців тому

    I like your videos a lot. thanks for sharing.👍

  • @agnesakne4409
    @agnesakne4409 9 місяців тому

    Your explanation is not superb

  • @DingoDummy2026
    @DingoDummy2026 9 місяців тому

    I wish I saw this before taking number theory, would have helped so much 🥲

  • @agnesakne4409
    @agnesakne4409 10 місяців тому

    when will you get married

  • @TheTrienco
    @TheTrienco 10 місяців тому

    Kept coming back to this one. From brute force (2.5min), to multithreaded (45s), to parallel reverse lookup (75ms) and finally splitting the ranges from back to front (450us). Amazing how much difference an approach can make

    • @briandawley7808
      @briandawley7808 9 місяців тому

      For reverse lookup do you mean start with locations? I couldn't figure out how to handle when something "upstream" doesn't have a mapped downstream value so instead just uses itself in that case.

    • @TheTrienco
      @TheTrienco 9 місяців тому

      @@briandawley7808 yes. But you have to pretty much start at 0 and count up, because the default mapping says "if no mapping, value maps to itself". So you can't just look at the location ranges, since all values are potentially possible.

    • @briandawley7808
      @briandawley7808 9 місяців тому

      @TheTrienco yeah I tried going from zero but the "use self if unmapped" rule tripped me up.

  • @TeemuSa
    @TeemuSa 10 місяців тому

    In part 2, Instead of trying every substitution, I iterated over rows, and kept a tally of the total number of differing characters. If that exceeded 1, I had an early stop, and if it wasn't 1 in the end the line wasn't a smudged mirror location.

  • @TheTrienco
    @TheTrienco 10 місяців тому

    For part 1 I was happy with my one pass approach. Making it more generic for part 2 somewhat ruined the neatness. Rolling a column north just keeps track of the next valid destination as it goes, so no nested loops needed (swapping ranges with indexing for clarity): int64_t dst_row = 0; for (row...) { if (grid[row][col] == 'O') { swap(grid[dst_row++][col], grid[row][col]); } else if (grid[row][col] == '#') { dst_row = row + 1; } } Still can't get part under 19ms, though. All the copies to keep a history up to the first cycle must be killing it.

  • @TheFrogfather1
    @TheFrogfather1 10 місяців тому

    In part one we have a method that finds a reflection point (horizontal or vertical) where there are 0 errors between reflected lines. So for part two we can run the same method but looking for exactly one error instead of 0! I tried this thinking I was probably missing something and was quite surprised when it worked!

  • @seboqw7099
    @seboqw7099 10 місяців тому

    In part 2 there is no need to count the rem_jokers variable and also add it in if condition because it will always be 0. Remove it, think about it and see that the result will be the same.

  • @LeandroCoutinho
    @LeandroCoutinho 10 місяців тому

    Nice! In the second grid in the sample, it changes the fifth symbol in row 2, but why couldn't it be the fifth in row 1 to a dot, please? #...##..# #....#..#