Painting the Walls - Leetcode 2742 - Python

Поділитися
Вставка
  • Опубліковано 12 лис 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!

  • @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!

  • @mxwelljt
    @mxwelljt Рік тому +12

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

  • @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 9 місяців тому

      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

  • @vishnusunil9610
    @vishnusunil9610 Рік тому

    Absolutely stunning piece of code Thank you for the clear explanation

  • @johnniewalkerjohnniewalker2459

    Great explanation!!!

  • @krateskim4169
    @krateskim4169 Рік тому

    Your efforts are so valuable , thanks for your time

  • @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.

  • @MP-ny3ep
    @MP-ny3ep Рік тому

    Great explanation as always . Thank you

  • @GuruPrasadShukla
    @GuruPrasadShukla Рік тому

    watched understood done!

  • @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

  • @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

  • @thuglife-ff7im
    @thuglife-ff7im Рік тому

    Thanks bro

  • @1000iq_gaming
    @1000iq_gaming Рік тому

    Honestly I was expecting some Priority Queue solution.

  • @saivishnuadabala2447
    @saivishnuadabala2447 Рік тому

    Even though i used the memorization, i got TLE

  • @pastori2672
    @pastori2672 Рік тому +1

    Whats up with the dp problems lately

    • @NeetCodeIO
      @NeetCodeIO  Рік тому +1

      yeah and theyre all hards lately

  • @Romany_M
    @Romany_M Рік тому +1

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

  • @Pippiwazza
    @Pippiwazza Рік тому

    take a shot every time he says 'pai'.

  • @HimanshuSaini-ur6by
    @HimanshuSaini-ur6by Рік тому +1

    Bro woke up and chose vi-... Leetcode

  • @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

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

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

  • @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)

  • @satwiktatikonda764
    @satwiktatikonda764 Рік тому

    my comments are disappearing !!!