Painting the Walls - Leetcode 2742 - Python

Поделиться
HTML-код
  • Опубликовано: 27 окт 2024

Комментарии • 45

  • @HtotheG
    @HtotheG Год назад +1

    Because of watching your videos on the daily problems for the past several weeks, I was able to solve today's hard problem on my own before your video even dropped. Thank so much for all your help, I'll still watch when you drop today because I will still learn something for sure. Keep up the great work!

  • @mxwelljt
    @mxwelljt Год назад +12

    Thanks for these each day, it is helping me with my LeetCode routine greatly 🙏

  • @jonathanalvarado7558
    @jonathanalvarado7558 Год назад

    u don't know how much this helped me, usually I can get the intuition down, but the coding part is still really hard for me, thanks for showing the code!

  • @hossainurrahaman
    @hossainurrahaman Год назад +15

    I failed my Google interview second time today... 😐... Will continue to leetcode.... Hopefully i will be prepared enough to clear it one day

    • @lakshmanvengadesan9096
      @lakshmanvengadesan9096 Год назад +9

      Atleast your resume is getting shortlisted bro

    • @kareemadesola6522
      @kareemadesola6522 Год назад

      @@lakshmanvengadesan9096 Ikr😂

    • @kareemadesola6522
      @kareemadesola6522 Год назад +2

      I'm sorry to hear that you failed your Google interview. I know how hard it can be to prepare for such a competitive and challenging process. But don't give up on your dream! You have the skills and the passion to succeed, and I'm sure you will get another chance to prove yourself.💪

    • @aneeinaec
      @aneeinaec 8 месяцев назад

      Tell us about kins of questions bro

  • @mehulgoyal5-yeariddcivilen832
    @mehulgoyal5-yeariddcivilen832 Год назад +4

    i learn two new concepts regarding dp
    1.tricky way to boil down three variable to two
    2. introduce dp as a set

    • @HoppyGamer
      @HoppyGamer Год назад

      Can you explain how he made 3 variables into two? and why is sum(time) >= remaining walls

    • @mehulgoyal5-yeariddcivilen832
      @mehulgoyal5-yeariddcivilen832 Год назад

      ​@@HoppyGamer
      So the first variable is Ind
      Second is total time
      Third is total elements remain
      Since the observation is if we get the sum of time of the wall painted by the paid painter and if the remain wall is less or equal to the total time then free painter would paint all these remains wall in 1 sec each as stated in ques so we just want to minimize the cost of the paid painter

  • @Raymond-Wu
    @Raymond-Wu Год назад +4

    I tried for way too long to get a greedy approach working. Tried making different metrics like cost per time thinking that I'd want to keep the paid painter occupied for as long and cheap as possible while the free painter handles all the expensive

    • @vanchark
      @vanchark Год назад +1

      Same here.. I thought I had a greedy algorithm that worked for all these different test cases, but eventually realized I missed a test case where it didn't work. In retrospect I should've thought of other approaches first (even if they don't seem the most optimal), and think about a greedy approach last. If I am thinking of the greedy approach, I should try harder to disprove its correctness rather than prove it.

    • @Raymond-Wu
      @Raymond-Wu Год назад

      @@vanchark But sometimes the greedy approach is the intended solution ¯\_(ツ)_/¯ There's literally a category on LC for greedy problems

  • @johnniewalkerjohnniewalker2459
    @johnniewalkerjohnniewalker2459 Год назад +3

    Great explanation!!!

  • @vishnusunil9610
    @vishnusunil9610 Год назад

    Absolutely stunning piece of code Thank you for the clear explanation

  • @The_Sad_Cactus
    @The_Sad_Cactus Год назад +1

    Can you make a series of dynamic programming videos where rather than explaining what dp is like other youtubers, you explain the intutions that a beginner might get when seeing such hard questions and try to code it, point out the mistakes and complexities, show how dp is originated or realized from exploring those ideas and then explain the dp solutions. I know a lot of work for you but it might help a lot of people like myself.

    • @leeroymlg4692
      @leeroymlg4692 Год назад

      This pls

    • @pronoob5664
      @pronoob5664 Год назад

      there's an indian youtuber who has a DP playlist, search "Striver DP playlist", there are around 56 videos explaining the pattern of each DP problem.

  • @NishanPnab
    @NishanPnab Год назад +3

    pls help to solve this :
    Given a string of the type "---F-FD-F" you need to group together all the F tiles ,You can do the following:
    swap F with - tile whcih will cost you x
    2.Change a D to - whcih will cost you y.
    here F represents tile with FOOD on it and D is dirty tile and - is clean tile
    you can only swap F with - and not D directly(you can convert D to - then swap it with F so the cost will be for both swapping and changing D (x+y).
    write a code to find the minimum cost to group together all the F tile so that the cost is minimised. (python code plssss)
    in the above example "---F-FD-F"
    the min cost for x=0 and y=10 will be 10 . swap First F with the - next to it whcihc will result in "----FFD-F" and cost x=0
    then convert D to - with cost y=10(total cost 0+10) which gives "----FF--F" . then swap the last F with - whcih will cost 0 and give the string ----FFF--?

    • @ayo_whatup3064
      @ayo_whatup3064 Год назад +1

      bro is this from the Trimble OA?

    • @NishanPnab
      @NishanPnab Год назад

      @@ayo_whatup3064 yeah , did you solve this one?

    • @ayo_whatup3064
      @ayo_whatup3064 Год назад

      @@NishanPnab nah bro, only partial testcases passed🥲 I used greedy

  • @krateskim4169
    @krateskim4169 Год назад

    Your efforts are so valuable , thanks for your time

  • @MP-ny3ep
    @MP-ny3ep Год назад

    Great explanation as always . Thank you

  • @GuruPrasadShukla
    @GuruPrasadShukla Год назад

    watched understood done!

  • @thuglife-ff7im
    @thuglife-ff7im Год назад

    Thanks bro

  • @SANCHARITHAKUR
    @SANCHARITHAKUR Год назад

    my approach is :
    class Solution {
    public:
    int paintWalls(vector& cost, vector& time) {
    int n1 = cost.size();
    for (int i = 0; i < n1; i++) {
    for (int j = i + 1; j < n1; j++) {
    if (cost[i] > cost[j]) {
    swap(cost[i], cost[j]);
    swap(time[i], time[j]);
    }
    }
    }
    int sum = 0 ;
    for(int i = 0 ; i

  • @pastori2672
    @pastori2672 Год назад +1

    Whats up with the dp problems lately

    • @NeetCodeIO
      @NeetCodeIO  Год назад +1

      yeah and theyre all hards lately

  • @Aquilesxd
    @Aquilesxd Год назад

    why i cant pass in test 2293 / 2557 ?
    cost = [42,8,28,35,21,13,21,35]
    time = [2,1,1,1,2,1,1,2]
    my output = 64
    expected = 63
    the only possible sum of values to result in 63 is 42+8+13, but thats like 2+1+1 time for the paid painter and 1+1+1+1+1 time for the free painter, the free painter cant work more than the paid one, right?, can someone help me? i think i miss something

  • @Romany_M
    @Romany_M Год назад +1

    the @cache didn't speed it up
    it throw memory limit exceeding:(

  • @1000iq_gaming
    @1000iq_gaming Год назад

    Honestly I was expecting some Priority Queue solution.

  • @saivishnuadabala2447
    @saivishnuadabala2447 Год назад

    Even though i used the memorization, i got TLE

  • @dingus2332
    @dingus2332 Год назад

    Can anyone tell , whats wrong with my code ? -
    class Solution:
    def paintWalls(self, cost: List[int], time: List[int]) -> int:
    dp = {}
    def dfs(i, occupied):
    if i == len(time):
    return 0

    if (i , occupied) in dp :
    return dp[(i,occupied)]

    if occupied != 0:
    freePainterWork = dfs(i+1, occupied-1)
    paidPainterWork = cost[i] + dfs(i+1 , occupied)
    dp[(i,occupied)] = min(freePainterWork , paidPainterWork)
    else:

    paidPainterWork = cost[i] + dfs(i+1 , time[i])
    dp[(i,occupied)] = paidPainterWork
    return dp[(i,occupied)]
    return dfs(0 , 0)

  • @Pippiwazza
    @Pippiwazza Год назад

    take a shot every time he says 'pai'.

  • @HimanshuSaini-ur6by
    @HimanshuSaini-ur6by Год назад +1

    Bro woke up and chose vi-... Leetcode

  • @parthbhatia341
    @parthbhatia341 3 месяца назад

    Am I too dumb to not come up with this even with solving 300 problems?

  • @satwiktatikonda764
    @satwiktatikonda764 Год назад

    my comments are disappearing !!!