XOR Queries of a Subarray - Leetcode 1310 - Python

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

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

  • @anirudhbhat3099
    @anirudhbhat3099 28 дней назад +19

    Hey Neet, I just got placed in a company through the on-campus drive and want to thank you for your videos and the roadmap you created. There are quite a few teachers who use Python for LeetCoding but I found out that your explanations really helped me understand the concepts deeply and was able to give the interviews with confidence🙏

    • @NeetCodeIO
      @NeetCodeIO  28 дней назад +7

      LFG!!! congratulations you earned it my man

    • @anirudhbhat3099
      @anirudhbhat3099 28 дней назад

      @@NeetCodeIO Thanks a lot man😄

    • @M.V.CHOWDARI
      @M.V.CHOWDARI 28 дней назад

      Can please share your resume or suggest some projects ​@@NeetCodeIO

    • @anonymousgreen5080
      @anonymousgreen5080 28 дней назад +1

      Congratulations man. Could u give us some suggestions about interview ? Like are they same or a bit different from the old videos ?

    • @rohangupta1266
      @rohangupta1266 28 дней назад

      What college ?

  • @freecourseplatformenglish2829
    @freecourseplatformenglish2829 28 дней назад +1

    Solved it on my own. Huge credit goes to your teaching style. Thanks man.

  • @adilansari-hq9ge
    @adilansari-hq9ge 28 дней назад +4

    Bro, I Liked so much the style of having multiple solutions . It is useful to learn mutiple techniques.

  • @MehmetDemir-xi3yy
    @MehmetDemir-xi3yy 28 дней назад +1

    Hey man, I don't know if you did this but could you upload a video that you solve a segment tree problem. That way, you could teach us basics and usage of segment tree like you did for union find in the past. Thanks 🎉

  • @petercheng1725
    @petercheng1725 14 дней назад

    For the second solution, can you add a 0 to the end of arr so if we go out of bounds we would index the last element which is 0. Very specific to python but similar thought to adding a 0 at the front.

  • @MP-ny3ep
    @MP-ny3ep 28 дней назад

    Great explanation as always. Thank you for doing the daily problems

  • @abhinavnair4577
    @abhinavnair4577 28 дней назад +2

    a simpler way to optimize this code is
    for left, right in queries:
    if left == 0:
    ans.append(prefix[right])
    else:
    ans.append(prefix[right]^prefix[left-1])
    # in ur case maybe do prefix[right+1]^prefix[left] , if u have len(prefix) =len(arr)+1
    -this also gives runtime 300 ms
    Complete solution -
    class Solution:
    def xorQueries(self, arr: List[int], queries: List[List[int]]) -> List[int]:
    l = len(arr)
    ans =[]
    prefix = [0]*l
    prefix[0] = arr[0]
    for i in range(1,l):
    prefix[i] = prefix[i-1] ^ arr[i]
    for left, right in queries:
    if left == 0:
    ans.append(prefix[right])
    else:
    ans.append(prefix[right]^prefix[left-1])
    return ans

  • @sirk3v
    @sirk3v 28 дней назад

    Thank you for providing. What math topics does one need be familiar with for DSA?

  • @albin_joby
    @albin_joby 28 дней назад

    for i in range(1,len(arr)):
    arr[i] = arr[i-1]^arr[i]
    res = []
    for query in queries:
    left,right = query[0],query[1]
    if left == 0:
    res.append(arr[right])
    else:
    res.append(arr[right]^arr[left-1])
    return res

  • @ShinAkuma
    @ShinAkuma 28 дней назад

    You don't need extra space. Just store the prefix xor value in the original array.

    • @NeetCodeIO
      @NeetCodeIO  28 дней назад +1

      Isn't that what I did?

    • @ShinAkuma
      @ShinAkuma 28 дней назад

      @@NeetCodeIO Nevermind, I commented before watching the second approach.

  • @business_central
    @business_central 27 дней назад

    I thought the time complexity would be O(n * m) since we are going through each query and also the input arr for the calculations.
    Can anyone please clarify?

  • @eshukla15
    @eshukla15 28 дней назад

    thank you neetcode

  • @M.V.CHOWDARI
    @M.V.CHOWDARI 28 дней назад +1

    Hey, neet Code please suggest some advance projects

  • @VijayKrishnaKumar-o4o
    @VijayKrishnaKumar-o4o 28 дней назад

    Hii bro please make video on open Ai o1

  • @MWKING
    @MWKING 28 дней назад

    second