1550. Three Consecutive Odds || LeetCode POTD || Explained in HINDI

Поділитися
Вставка
  • Опубліковано 29 чер 2024
  • Instagram link:- / reelcoding
    / @reelcoding
    Approach 1:-
    Loop: We iterate from the start of the array to the position arr.length - 2 to ensure we can check the next two elements without going out of bounds.
    Condition Check: For each element at index i, we check if arr[i], arr[i + 1], and arr[i + 2] are all odd using the modulo operator (% 2).
    Return Result:
    If we find three consecutive odd numbers, we immediately return true.
    If the loop completes without finding such a triplet, we return false.
    Time and Space Complexity
    Time Complexity:
    The algorithm runs in O(n) time, where n is the length of the array. This is because we traverse the array once.
    Space Complexity:
    The space complexity is O(1) since we use a constant amount of extra space regardless of the input size.
    Approach 2:-
    Initialization:
    consecOdd is initialized to 0 to track consecutive odd numbers.
    Loop:
    We iterate through each element of the array.
    If the current element is odd (arr[i] % 2 == 1), we increment the consecOdd counter.
    If the current element is even, we reset the consecOdd counter to 0.
    Condition Check:
    During each iteration, we check if consecOdd has reached 3.
    If yes, we return true indicating that we have found three consecutive odd numbers.
    If the loop completes without the counter reaching 3, we return false.
    Time Complexity:
    The algorithm runs in O(n) time, where n is the length of the array. This is because we traverse the array only once.
    Space Complexity:
    The space complexity is O(1) as we are using a constant amount of extra space regardless of the input size.
    Approach 3:-
    Initialization:
    No additional initialization is needed beyond the standard setup.
    Loop:
    We iterate through each element of the array up to arr.length - 2 to ensure we have enough elements for a triplet.
    For each element at index i, we calculate the product of arr[i], arr[i+1], and arr[i+2].
    Condition Check:
    During each iteration, we check if the product of the triplet is odd using prod % 2 == 1.
    If the condition is met, we return true indicating that we have found three consecutive odd numbers.
    If the loop completes without finding such a triplet, we return false.
    Time Complexity:
    The algorithm runs in O(n) time, where n is the length of the array. This is because we traverse the array only once, and each product calculation is constant time.
    Space Complexity:
    The space complexity is O(1) as we are using a constant amount of extra space regardless of the input size.
    Background Music for Videos: www.bluetreeaudio.com
    Whether you're new to problem-solving or seeking insights into Java programming techniques, this video offers valuable insights into tackling similar challenges effectively.
    Do join with me guys for daily problem solving on LeetCode.
    Please like and subscribe this channel and share among your friends, it helps me to motivate and bring more videos for you guys. ❤️❤️
    Soon, DSA batch (Hinglish) is going to launch on this channel. So, do subscribe so that you will get the notification for all new videos.👍👍🔔🔔.
    Do comment if any doubts left. Thank you 😊
    #leetcode #computerscience #leetcodesolutions #leetcodequestionandanswers #code #learning #dsalgo #dsa
    #CodingExplanation #AlgorithmTutorial #JavaProgramming #DataStructures #DynamicProgramming #CodeExplanation #ProgrammingTutorial #AlgorithmExplanation #TechTutorial #LearnToCode #ProblemSolving #ProgrammingConcepts #SoftwareDevelopment #TechEducation #CodingCommunity #CodeBreakdown #ComputerScience
    #JavaTutorial #AlgorithmAnalysis #EducationalContent
    1550. Three Consecutive Odds
    Leetcode 1550
    Three Consecutive Odds
    Leetcode daily challenge
    Leetcode potd
    1550 Three Consecutive Odds
    leetcode potd today solution
    leetcode potd today
    leetcode grind
    leetcode questions for interview
    leetcode series
    leetcode hindi

КОМЕНТАРІ • 1

  • @reelcoding
    @reelcoding  9 днів тому +1

    Code link:- leetcode.com/problems/three-consecutive-odds/solutions/5394812/java-solution-explained-in-hindi-3-approaches/