LeetCode 217 & 219: Contains Duplicate I & II - Interview Prep Ep 46

แชร์
ฝัง
  • เผยแพร่เมื่อ 5 พ.ย. 2024

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

  • @LittleKittenWarrior
    @LittleKittenWarrior 2 ปีที่แล้ว +2

    Very well explained, thank you for going through the examples!

    • @FisherCoder
      @FisherCoder  2 ปีที่แล้ว

      Glad it was helpful!

  • @selvamraman4229
    @selvamraman4229 3 ปีที่แล้ว +1

    @fisherCoder your approach is valid but code may not correct. what happen in the input is [1,1] and k=2. your code will return true whereas it should return false. you missed to add size check in the first if condition. Let me know if i am wrong.

  • @emilyhuang2759
    @emilyhuang2759 4 ปีที่แล้ว

    This was very well explained. Thank you!
    A lot of solutions also includes
    if (k > 30000) return false;
    at the top, which seems to lower the runtime. Why would it return false for this case?

  • @Turnpost2552
    @Turnpost2552 4 ปีที่แล้ว +1

    Very good solution, very good wholesome video.

  • @harir7676
    @harir7676 4 ปีที่แล้ว +1

    is this the best case approach for this problem - Time complexity: O(n)
    Space complexity: O(min(n, k))

    • @alfaa.originals
      @alfaa.originals 4 ปีที่แล้ว

      Yes, We can do this in O(n) time and O(1) space.

  • @AmitKumar-we8dm
    @AmitKumar-we8dm 4 ปีที่แล้ว

    And how will you approach the problem if the difference is to at least k instead of atmost k?

  • @AmitKumar-we8dm
    @AmitKumar-we8dm 4 ปีที่แล้ว

    Thanks very nice approach.Tell me why below code works and accepted by leetcode even when input array isn't sorted:
    public boolean containsNearbyDuplicate(int[] nums, int k)
    {
    int len = nums.length;

    for(int i=0; i

    • @amitthakur9715
      @amitthakur9715 2 ปีที่แล้ว

      Sleek Binary Search broo.. Why did I not thought of this before...

  • @parvezrafisparta
    @parvezrafisparta 3 ปีที่แล้ว

    where do you work?

  • @vedantmondkar9963
    @vedantmondkar9963 4 ปีที่แล้ว +2

    It will be much better if you start explaining algorithms than typing the code itself

    • @FisherCoder
      @FisherCoder  4 ปีที่แล้ว

      Good call! Will do, thanks!