Largest Odd Number in String - Leetcode 1903 - Python

SdĂ­let
VloĆŸit
  • čas pƙidĂĄn 9. 07. 2024
  • 🚀 neetcode.io/ - A better way to prepare for Coding Interviews
    đŸ§‘â€đŸ’Œ LinkedIn: / navdeep-singh-3aaa14161
    đŸ„· Discord: / discord
    🐩 Twitter: / neetcode1
    🐼 Support the channel: / neetcode
    ⭐ BLIND-75 PLAYLIST: ‱ Two Sum - Leetcode 1 -...
    💡 DYNAMIC PROGRAMMING PLAYLIST: ‱ House Robber - Leetco...
    Problem Link: leetcode.com/problems/largest...
    0:00 - Read the problem
    0:30 - Drawing Explanation
    4:10 - Coding Explanation
    leetcode 1903
    #neetcode #leetcode #python

Komentáƙe • 16

  • @akshayiithyd
    @akshayiithyd Pƙed 7 měsĂ­ci +3

    r = len(num) - 1
    res = ''
    if len(num) == 0:
    return res
    while r >=0 and int(num[r])%2 == 0:
    r -= 1
    return res + num[:r+1]

  • @shaiksoofi3741
    @shaiksoofi3741 Pƙed měsĂ­cem

    Thank you

  • @34535fff
    @34535fff Pƙed 7 měsĂ­ci +1

    Thanks, finally I did good solution before your video, yeah it's just an easy problem, but I am happy)

  • @thebosslevelstudios995
    @thebosslevelstudios995 Pƙed 7 měsĂ­ci +1

    Can we use heap for the following?

  • @amanchavhan4159
    @amanchavhan4159 Pƙed 7 měsĂ­ci +1

    If we start from 0->n(cpp)
    It shows memory limit exceeded.
    Why???

    • @Vancha112
      @Vancha112 Pƙed 7 měsĂ­ci

      Looks like you're out of bounds, try n-1 :)

  • @dk4882
    @dk4882 Pƙed 7 měsĂ­ci

    Easy one

  • @ajith4249
    @ajith4249 Pƙed 7 měsĂ­ci

    def largestOddNumber(self, num):
    for i in range(len(num)-1,-1,-1):
    if int(num[i])%2==1:
    return num[:i+1]
    return ""

  • @winwin2369
    @winwin2369 Pƙed 7 měsĂ­ci

    Way too easy problem it won't be asked 😂

  • @chrischika7026
    @chrischika7026 Pƙed 7 měsĂ­ci

    I thought list slicing was O(N) so why is it not O(N^2)

    • @jessezigi2419
      @jessezigi2419 Pƙed 7 měsĂ­ci +1

      You only do list slicing once

    • @Azikkii
      @Azikkii Pƙed 7 měsĂ­ci

      What? Your answer is in your question.

    • @Vancha112
      @Vancha112 Pƙed 7 měsĂ­ci

      Yeah in the code there's only one slice, which makes it o(n) :)

    • @leeroymlg4692
      @leeroymlg4692 Pƙed 7 měsĂ­ci

      it would only be N^2 if you were to do a slicing operation for every iteration of the loop of the input parameter. But in this case, it is only done once

  • @RexSacriticulus
    @RexSacriticulus Pƙed 7 měsĂ­ci +2

    A more elegant and pretentious way to check if a number is odd is n & 1.