Array -18: Find 1st occurrence of a value if adjacent values differ by at most K

Sdílet
Vložit
  • čas přidán 16. 09. 2019
  • Code: thecodingsimplified.com/find-...
    Solution:
    Brute force: Iterate each element of array starting from 0th index & check if value matches the given target value.
    - Complexity - O(n)
    Optimized Solution:
    - We can use the given property that adjacent elemnents differ by atmost K
    - We'll start from 0th index & take the diff = (difference between it's value & target value) / K.
    - Now jump your index to diff as we're sure that if they're differ by at most k, it means target value can't occur in between
    - Complexity: worst case O(n), but it'll be optmized & will have less than O(n)
    Please check video for more info:
    This problem is similar to:
    array find value if adjacent values differ by at most k,
    array find value in array,
    adjacent values differ by atmost k ,
    find,
    adjacent,
    differ by atmost K,
    array,
    java tutorial,
    coding simplified,
    java
    CHECK OUT CODING SIMPLIFIED
    / codingsimplified
    ★☆★ VIEW THE BLOG POST: ★☆★
    thecodingsimplified.com
    I started my CZcams channel, Coding Simplified, during Dec of 2015.
    Since then, I've published over 400+ videos.
    ★☆★ SUBSCRIBE TO ME ON CZcams: ★☆★
    czcams.com/users/codingsimplif...
    ★☆★ Send us mail at: ★☆★
    Email: thecodingsimplified@gmail.com

Komentáře • 11