Special Array I - Leetcode 3151 - Python

แชร์
ฝัง
  • เผยแพร่เมื่อ 7 ก.พ. 2025

ความคิดเห็น • 26

  • @hlebushik
    @hlebushik 7 วันที่ผ่านมา +33

    You know the problem is hard when video is 3 minutes long…

  • @business_central
    @business_central 7 วันที่ผ่านมา +8

    first day of the month is always the best. can't wait for Feb 14th...

  • @jthepj108
    @jthepj108 7 วันที่ผ่านมา +2

    I kept over thinking a solution to this problem until i saw that this video was 3 minutes long.
    Then I came up with a simple solution without even watching the video. I'm growing thanks to your videos💜

  • @yhbarve
    @yhbarve 7 วันที่ผ่านมา +4

    We can also check if (num[i] + num[i-1]) is odd. If it is even, then the two elements have to both be even or odd.

    • @yhbarve
      @yhbarve 7 วันที่ผ่านมา

      Not sure if this improves the TC though. Maybe a very minor improvement.

    • @pyrohugs
      @pyrohugs 7 วันที่ผ่านมา

      @@yhbarve Same time complexity.

  • @sandeepsalwan2911
    @sandeepsalwan2911 7 วันที่ผ่านมา

    Thank you neetcode for all that you do, I wouldn't do dailies if it wasn't for your motivation. I know these vids don't get awfully many views but please keep it at it, appreciate ur explanations

  • @user-my6yf1st8z
    @user-my6yf1st8z 6 วันที่ผ่านมา

    thanks chief

  • @mayurbhoi
    @mayurbhoi 7 วันที่ผ่านมา +1

    what i used is:
    even + even = even
    odd + odd = even
    even + odd = odd

  • @sleepypixie8828
    @sleepypixie8828 7 วันที่ผ่านมา

    solved this problem first then came to this video and listened to it in french (i don't understand french)

  • @shahukor4505
    @shahukor4505 7 วันที่ผ่านมา

    I came up with my own solution, and it also beats 100%. But after seeing this code, I felt dumb because it was so easy, I unnecessarily complicated my approach.
    Here's my approach :
    class Solution:
    def isArraySpecial(self, nums: List[int]) -> bool:
    if len(nums)==1:
    return True
    if nums[0]%2==0:
    even=1
    odd=0
    elif nums[0]%2!=0:
    even=0
    odd=1
    for i in range(1,len(nums)):
    if nums[i]%2==0:
    even+=1
    odd-=1
    else:
    odd+=1
    even-=1
    if even==-1 or odd==-1:
    return False
    return True

  • @cameronmccoy2204
    @cameronmccoy2204 7 วันที่ผ่านมา +1

    lost my 60 day streak to this one

    • @adarshsasidharan254
      @adarshsasidharan254 7 วันที่ผ่านมา +1

      nah man, what the hell

    • @3227998
      @3227998 7 วันที่ผ่านมา +1

      you can do timetravel for 70 credit and restore your streak. Not that it matters, just saying if you didn't know.

  • @emilturbo5
    @emilturbo5 7 วันที่ผ่านมา

    If this was me a month ago, I would have thought about using a hash map just to sort the given keys (which they're not even given in this problem to my knowledge) and sort them into their corresponding values, without even thinking about how I should then implement a pointer arithmetic to check if the given values at their corresponding indices are even special or not, making the solution unclear and costly time and space wise :P

    • @meghna1915
      @meghna1915 4 วันที่ผ่านมา

      oh hell naw

  • @markopolo2224
    @markopolo2224 7 วันที่ผ่านมา +1

    refreshing problem

  • @fahimmimtiaz366
    @fahimmimtiaz366 7 วันที่ผ่านมา

    Lets goo, coming here after failing an OA hihihi

  • @meghna1915
    @meghna1915 4 วันที่ผ่านมา

    i used (nums[i] ^ nums[i-1]) % 2 == 0 ) return false

  • @mehdiamiri5418
    @mehdiamiri5418 7 วันที่ผ่านมา +1

    Man, i'm so disappointed of not getting interview or getting but getting rejections. I'm in San Francisco and most of the companies I am applying for ask me hard leetcode questions and they even want to make it optimized. It is insane. Also they say 2025 is ending of swe. Should i stop attempting on solving leetcode questions?

    • @user-my6yf1st8z
      @user-my6yf1st8z 6 วันที่ผ่านมา

      "YES, YOU SHOULD STOP" - your competition

  • @qulinxao
    @qulinxao 7 วันที่ผ่านมา

    return all((a+b)%2 for a,b in pairwise(nums))