<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Mahedi Hasan Jisan on Medium]]></title>
        <description><![CDATA[Stories by Mahedi Hasan Jisan on Medium]]></description>
        <link>https://medium.com/@mahedihasanjisan?source=rss-3ccbddc05ddf------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*k41jp5PFYb1JL2ty.</url>
            <title>Stories by Mahedi Hasan Jisan on Medium</title>
            <link>https://medium.com/@mahedihasanjisan?source=rss-3ccbddc05ddf------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 18:05:06 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mahedihasanjisan/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Programming Techniques]]></title>
            <link>https://mahedihasanjisan.medium.com/programming-techniques-acade1327eb6?source=rss-3ccbddc05ddf------2</link>
            <guid isPermaLink="false">https://medium.com/p/acade1327eb6</guid>
            <category><![CDATA[data-structures]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[dynamic-programming]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[graph]]></category>
            <dc:creator><![CDATA[Mahedi Hasan Jisan]]></dc:creator>
            <pubDate>Thu, 12 Sep 2024 21:53:57 GMT</pubDate>
            <atom:updated>2024-09-12T21:53:57.618Z</atom:updated>
            <content:encoded><![CDATA[<p>This article focuses on some of the most popular problem-solving techniques that are widely used.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NvjnDwEZEVpGJb3pjooJ2Q.jpeg" /><figcaption>Photo By: Author</figcaption></figure><h3>Technique: Prefix Sum Array</h3><p>A <strong>Prefix Sum Array</strong> is an array where each element holds the sum of all the previous elements. In other words, each component of the prefix sum array is the cumulative sum up to that point in the original array.</p><h4><strong>Problem Statement:</strong></h4><p>For an array arr[] of length n, the prefix sum array prefix_sum[] is defined as:</p><blockquote>prefix_sum[0] = arr[0]<br>prefix_sum[i] = prefix_sum[i-1] + arr[i] for i &gt; 0</blockquote><p><strong>Example:</strong></p><pre>arr = [1, 2, 3, 4, 5]<br>prefix_sum[0] = 1<br>prefix_sum[1] = prefix_sum[0] + prefix_sum[1] = 3<br>prefix_sum[2] = prefix_sum[2] + prefix_sum[1] = 6<br>prefix_sum[3] = prefix_sum[3] + prefix_sum[2] = 10<br>prefix_sum[4] = prefix_sum[4] + prefix_sum[3] = 15<br>prefix_sum = [1, 3, 6, 10, 15]</pre><p>Now that we have calculated the prefix sum array, we can find the sum of a specific position or range.</p><ul><li>What is the prefix sum of index 3? → 10</li><li>What is the prefix sum of the range from index i=2 to j=4? → 12</li></ul><h4>Algorithm:</h4><pre>sum(i, j) = prefix_sum[j] - prefix_sum[i-1] (if i &gt; 0)<br>If i = 0, then sum(0, j) = prefix_sum[j]</pre><blockquote><strong>Time Complexity</strong>: <strong>O(n)</strong> (constructing the prefix sum array).<br><strong>Space Complexity</strong>: <strong>O(n)</strong> (storing the prefix sum array). <strong>O(1)</strong> (if can use the original array)</blockquote><h3>Technique: Two Pointers</h3><p>The <a href="https://mahedihasanjisan.medium.com/competitive-programming-1-two-pointers-algorithm-64a812f39fc1"><strong><em>two-pointer technique</em></strong></a> is an efficient way to search or iterate over arrays. Often, this technique reduces time complexity from O(n²) to O(n).</p><h4><strong>Concepts:</strong></h4><ul><li>One pointer starts at the beginning, and another at the end of an array, string, etc.</li><li>The pointers move toward each other based on the condition to solve problems such as palindrome checks, finding a pair of elements, solving a subarray problem, or merging sorted arrays.</li></ul><h4>Problem Statement:</h4><p><strong>Palindrome Check: </strong>The reversed string is the same as the original string.</p><h4>Algorithm:</h4><pre>s = &#39;abcba&#39;<br>i = 0 # pointer A<br>j = len(s) - 1 # pointer B<br>while i &lt; j:<br>  if s[i] != s[j]:<br>      return False<br>  i += 1 # pointer A moving towards to pointer B<br>  j -= 1 # pointer B moving towards to pointer A<br>return True</pre><h4>Problem Statement:</h4><p><strong>Finding a pair of elements with a given sum: </strong>The task is to find a pair of elements equal to the given sum (The array is sorted).</p><h4>Algorithm:</h4><pre>arr = [1, 2, 3, 4, 6, 8, 9]<br>target = 10<br>left = 0 # pointer A<br>right = len(arr) - 1 # pointer B<br>while left &lt; right:<br>  sum = arr[left] + arr[right]<br>  if sum == target:<br>    return True<br>  if sum &lt; target:<br>    left += 1 # moving pointer A if the sum is less than the target; array is sorted<br>  else:<br>    right -= 1 # moving pointer B if the sum is greater than the target; array is sorted<br>return []</pre><blockquote><strong>Time Complexity</strong>: <strong>O(n)<br>Space Complexity</strong>: <strong>O(1)</strong></blockquote><h3>Technique: Sliding Window</h3><p>The <a href="https://mahedihasanjisan.medium.com/competitive-programming-1-sliding-window-technique-ff790f571ea2"><strong><em>sliding window</em></strong></a> is an optimized technique to solve problems involving all subarrays or substrings of a specific size. Instead of looping on the array or string multiple times, the sliding window allows us to do that once and find the desired result based on conditions and constraints.</p><p><strong>Types of Sliding Window:</strong></p><ol><li><strong>Fixed-size Sliding Window</strong>: The size of the window remains constant.</li><li><strong>Dynamic-size Sliding Window</strong>: The size of the window changes based on some condition (e.g., when a target condition is met).</li></ol><h4>Problem Statement:</h4><p>Maximum Sum of a Subarray of Size k</p><h4>Algorithm:</h4><pre># find the initial sum of the sliding window<br>value = sum(nums[:sliding_window])<br>max_sum = value<br><br># sliding window from left to right<br>for i in range(1, len(nums) - sliding_window + 1):<br>    value = value - nums[i-1] + nums[i+sliding_window-1]<br>    max_sum = max(value, max_sum)<br>return max_sum<br><br><br>arr = [2, 3, 5, 8, 9, 10]<br>sliding_window = 3</pre><p>This optimization code only sums once for the sliding window, substructing the element left behind and adding the new element that enters the sliding window.</p><blockquote><strong>Time Complexity</strong>: <strong>O(n)<br>Space Complexity</strong>: <strong>O(1)</strong></blockquote><h3>Technique: Fast &amp; Slow Pointers</h3><p>Fast and slow pointer is a modified version of the two-pointer technique. This technique involves two pointers, where one pointer moves fast and another moves slowly. Eventually, the fast pointer will catch up to the slow pointer.</p><p>If there is a cycle in the data structure (e.g., a linked list), the fast pointer will eventually catch the slow pointer, and they will meet. If there is no cycle, the fast pointer will reach the end of the list.</p><h4><strong>Problem Statement:</strong></h4><p>Detecting a cycle in a linked list. The goal is to find a cycle in a linked list using fast and slow pointers.</p><h4>Algorithm:</h4><pre>1 -&gt; 2 -&gt; 3 -&gt; 4 -&gt; 5 -&gt; 3 (cycle starts again at node 3)<br>def has_cycle(head):<br>  # Initialize two pointers<br>  slow = head # slow pointers<br>  fast = head # fast pointers<br>  <br>  # Traverse the list<br>  while fast and fast.next:<br>      slow = slow.next  # Move slow pointer by 1 step<br>      fast = fast.next.next  # Move fast pointer by 2 steps<br>      <br>      # If the two pointers meet, there is a cycle<br>      if slow == fast:<br>          return True<br>  <br>  # If fast pointer reaches the end, there is no cycle<br>  return False</pre><h4>Problem Statement:</h4><p>Finding the starting point of a cycle in a linked list. The goal is to find the start of the cycle, and we can do that by doing the following:</p><ol><li>Move the slow pointer back to the head of the list.</li><li>Move both the slow and fast pointers one step at a time.</li><li>The point where they meet again will be the <strong>start of the cycle</strong>.</li></ol><h4>Algorithm:</h4><pre>def find_cycle_start(head):<br>    # Detect if there is a cycle<br>    slow, fast = head, head<br>    has_cycle = False<br>    <br>    # Step 1: Detect cycle using slow and fast pointers<br>    while fast and fast.next:<br>        slow = slow.next<br>        fast = fast.next.next<br>        if slow == fast:<br>            has_cycle = True<br>            break<br>    <br>    # If no cycle is found, return None<br>    if not has_cycle:<br>        return None<br>    <br>    # Step 2: Find the start of the cycle<br>    slow = head<br>    while slow != fast:<br>        slow = slow.next<br>        fast = fast.next<br>    <br>    # The point where slow and fast meet is the start of the cycle<br>    return slow</pre><h4>Problem Statement:</h4><p>Finding the middle of a linked list. If there is no cycle, the slow and fast pointer technique can be used to find the middle of a linked list. The slow pointer moves one step at a time, while the fast pointer moves two steps. When the fast pointer reaches the end, the slow pointer will be at the middle.</p><h4>Algorithm:</h4><pre>def find_middle(head):<br>    slow = head # slow pointer<br>    fast = head # fast pointer<br>    <br>    # Move the slow pointer one step, and the fast pointer two steps<br>    while fast and fast.next:<br>        slow = slow.next<br>        fast = fast.next.next<br>    <br>    # Slow pointer is now at the middle<br>    return slow</pre><h4>Problem Statement:</h4><p>Checking for duplicates or patterns in arrays. Given an array of n + 1 integers where each integer is between 1 and n (inclusive), there is precisely <strong>one duplicate number</strong> in the array. Your task is to find this duplicate number <strong>without modifying the array</strong> and using <strong>constant extra space</strong> (i.e., space complexity should be O(1)).</p><h4>Algorithm:</h4><pre>def find_duplicate(arr):<br>    # Step 1: Use slow and fast pointer to find the cycle<br>    slow = arr[0]<br>    fast = arr[0]<br>    <br>    # Move slow one step and fast two steps until they meet<br>    while True:<br>        slow = arr[slow]<br>        fast = arr[arr[fast]]<br>        if slow == fast:<br>            break<br>    <br>    # Step 2: Find the starting point of the cycle (the duplicate number)<br>    slow = arr[0]<br>    while slow != fast:<br>        slow = arr[slow]<br>        fast = arr[fast]<br>    <br>    # The point where slow and fast meet is the duplicate number<br>    return slow</pre><blockquote><strong>Time Complexity</strong>: <strong>O(n)<br>Space Complexity</strong>: <strong>O(1)</strong></blockquote><h3>Technique: LinkedList In-place Reversal</h3><p><strong>Linked List In-place Reversal</strong> refers to reversing a linked list by manipulating the pointers directly to reverse the direction of the linked list nodes.</p><h4><strong>Problem Statement:</strong></h4><ul><li>The basic idea is to reverse the next pointers of the nodes in the linked list so that they point to the previous node instead of the next node.</li><li>This process is done iteratively, traversing the list once and adjusting the pointers individually.</li></ul><p><strong>Approach:</strong></p><p>Initialize three pointers:</p><ul><li>prev (initially None): This will store the previous node as we reverse the links.</li><li>current (initially pointing to the head): This will be the node currently being processed.</li><li>next_node (initially None): This will store the next node in the list so we don&#39;t lose track of the list during reversal.</li></ul><h4>Algorithm</h4><pre>Input: 1 -&gt; 2 -&gt; 3 -&gt; 4 -&gt; 5<br>Output: 5 -&gt; 4 -&gt; 3 -&gt; 2 -&gt; 1<br><br>def reverse_linked_list(head):<br>    prev = None # first pointer<br>    current = head # second pointer<br>    <br>    while current:<br>        # Store the next node<br>        next_node = current.next # third pointer<br>        # Reverse the current node&#39;s pointer<br>        current.next = prev<br>        # Move pointers one step forward<br>        prev = current<br>        current = next_node<br>    <br>    # prev will be the new head of the reversed list<br>    return prev</pre><blockquote><strong>Time Complexity</strong>: <strong>O(n)<br>Space Complexity</strong>: <strong>O(1)</strong></blockquote><h3>Technique: Monotonic Stack</h3><p>A <strong>Monotonic Stack</strong> is a stack data structure in which the elements are arranged in a specific order, either <strong>monotonically increasing</strong> or <strong>monotonically decreasing</strong>. This means that the stack either maintains an increasing or decreasing sequence of elements from bottom to top. It is often used to solve problems related to finding the <strong>next greater element or</strong> <strong>next smaller element</strong> and other range-based or window-based problems.</p><h4>Problem Statement:</h4><p>Next Greater Element<strong><br></strong>Given an array, find the next element greater for each component. The idea is to traverse the array and use a stack to keep track of indices where the next greater element has yet to be found. Once a greater element is found, the indices from the stack are popped, and the corresponding result array is updated with the next greater element.</p><h4>Algorithm:</h4><pre>n = len(arr)         # Get the length of the array<br>stack = []           # Initialize an empty stack to store indices<br>result = [-1] * n    # Initialize the result array with -1<br><br>for i in range(n):   # Iterate through the array<br>    while stack and arr[i] &gt; arr[stack[-1]]:  # While stack is not empty and current element is greater than the element at the index stored at the top of the stack<br>        result[stack.pop()] = arr[i]          # Pop the index from the stack and update result at that index with the current element (next greater element)<br>    stack.append(i)   # Push the current index to the stack<br><br>return result        # Return the result array containing the next greater elements for each element in the input array</pre><h4>Problem Statement:</h4><p>Next Smaller Element<strong><br></strong>Given an array, find the next smaller element for each element.</p><h4>Algorithm:</h4><pre>n = len(arr)<br>result = [-1] * n  # Initialize the result array with -1<br>stack = []  # Monotonically increasing stack<br><br># Traverse the array from left to right<br>for i in range(n):<br>    # Pop elements from the stack while they are greater than the current element<br>    while stack and arr[i] &lt; arr[stack[-1]]:<br>        result[stack.pop()] = arr[i]  # Current element is the next smaller element for popped elements<br>    <br>    # Push the current index to the stack<br>    stack.append(i)<br><br>return result</pre><h4>Problem Statement:</h4><p>Largest Rectangle in Histogram<strong><br></strong>Find the largest rectangle in a histogram based on bar heights.</p><h4>Algorithm:</h4><ol><li><strong>Initialize a stack</strong> to store the indices of the histogram bars.</li><li><strong>Iterate through the heights</strong> array. For each height, check if the current bar is shorter than the bar at the top of the stack. If it is, pop the bar from the stack and calculate the area of the rectangle where the popped bar is the smallest height. The rectangle&#39;s width can be calculated using the difference between the current index and the index of the bar just below the popped bar in the stack.</li><li><strong>After the loop</strong>, pop any remaining bars in the stack and calculate their corresponding areas.</li><li>Keep track of the maximum rectangle area encountered.</li></ol><pre>stack = []  # Stack to store the indices of the histogram bars<br>max_area = 0<br>n = len(heights)<br><br>for i in range(n):<br>    # Ensure the stack is monotonically increasing<br>    while stack and heights[i] &lt; heights[stack[-1]]:<br>        height = heights[stack.pop()]  # Pop the top of the stack<br>        width = i if not stack else i - stack[-1] - 1  # Calculate width<br>        max_area = max(max_area, height * width)  # Calculate area<br>    <br>    # Push current bar&#39;s index to the stack<br>    stack.append(i)<br><br># After the loop, process any remaining bars in the stack<br>while stack:<br>    height = heights[stack.pop()]<br>    width = n if not stack else n - stack[-1] - 1<br>    max_area = max(max_area, height * width)<br><br>return max_area</pre><blockquote><strong>Time Complexity</strong>: <strong>O(n)<br>Space Complexity</strong>: <strong>O(n)</strong></blockquote><h3>Technique: Top K Elements</h3><p>The <strong>Top ‘K’ Elements</strong> problem is a common algorithmic problem where you are asked to find the top K largest or smallest elements in a given collection. Depending on the specific constraints, this problem can be solved efficiently using different approaches, such as sorting, heaps, or quickselect algorithms.</p><h4>Problem Statement:</h4><p>Given an array arr[] of n elements and an integer K, find the K largest (or smallest) elements from the array.</p><pre>arr = [3, 1, 5, 12, 2, 11]<br>K = 3<br>Top 3 largest elements: [12, 11, 5]</pre><p>The sorting approach is often time-consuming, taking O(n log n) time. Here, we discuss the Heaps and Quick Select algorithms.</p><h4>Algorithm:</h4><h4>Min-Heap</h4><p>The more efficient approach, especially when K is much smaller than n, is to use a <strong>min-heap</strong> (priority queue). This approach works as follows:</p><ul><li>First, build a min-heap of size K using the first K elements of the array.</li><li>For each remaining element in the array, compare it with the root of the heap.</li><li>If it is larger than the root, replace the root with the current element and heapify.</li><li>The heap will store the K largest elements.</li></ul><p>This method ensures that you maintain the top K largest elements, and because the heap only stores K elements, the complexity is optimized.</p><pre>import heapq<br><br>def top_k_elements_min_heap(arr, K):<br>    # Build a min-heap with the first K elements<br>    min_heap = arr[:K]<br>    # Convert to a min-heap<br>    heapq.heapify(min_heap)<br>    <br>    # Iterate over the remaining elements<br>    for i in range(K, len(arr)):<br>        if arr[i] &gt; min_heap[0]:  # If current element is greater than the heap&#39;s root<br>            heapq.heappop(min_heap)  # Remove the smallest element<br>            heapq.heappush(min_heap, arr[i])  # Add the current element<br>    <br>    # The heap contains the top K largest elements<br>    return list(min_heap)</pre><blockquote><strong>Time Complexity: O(n log K)<br>Space Complexity: O(K)</strong></blockquote><h4>Quickselect</h4><p>Quickselect is an efficient selection algorithm for finding the K-th smallest or largest element in an unordered list. It is related to the quicksort algorithm and can find the top K elements in expected linear time, though its worst-case time complexity is O(n^2).</p><p>Here is a high-level overview of how quickselect works:</p><ul><li>Choose a pivot element from the array.</li><li>Partition the array into elements smaller than the pivot and elements larger than the pivot.</li><li>Recursively apply quickselect to one of the partitions, depending on the value of K.</li></ul><p>This approach is especially efficient when K is relatively small.</p><pre>def partition(arr, left, right):<br>    pivot = arr[right]<br>    i = left<br>    for j in range(left, right):<br>        if arr[j] &gt; pivot:  # Change to &#39;&lt;&#39; for smallest K elements<br>            arr[i], arr[j] = arr[j], arr[i]<br>            i += 1<br>    arr[i], arr[right] = arr[right], arr[i]<br>    return i<br><br>def quickselect(arr, left, right, K):<br>    if left == right:<br>        return arr[left]<br>    <br>    pivot_index = partition(arr, left, right)<br>    <br>    if K == pivot_index:<br>        return arr[pivot_index]<br>    elif K &lt; pivot_index:<br>        return quickselect(arr, left, pivot_index - 1, K)<br>    else:<br>        return quickselect(arr, pivot_index + 1, right, K)<br><br>def top_k_elements_quickselect(arr, K):<br>    return quickselect(arr, 0, len(arr) - 1, K - 1)</pre><blockquote><strong>Time Complexity: O(n)<br>Space Complexity: O(1)</strong></blockquote><h3>Technique: Overlapping Intervals</h3><p><strong>Overlapping Intervals</strong> refer to intervals on a number line where one interval either fully or partially overlaps another. Given two intervals [a1, b1] and [a2, b2], they overlap if they share any common points, i.e., if:</p><ul><li>a1 &lt;= b2 and a2 &lt;= b1.</li></ul><p>When working with a collection of intervals, the problem often involves merging all overlapping intervals into one larger interval and ensuring non-overlapping intervals remain separate.</p><h4>Problem Statement:</h4><p>Given a list of intervals [[1, 3], [2, 6], [8, 10], [15, 18]], the overlapping intervals [1, 3] and [2, 6] should be merged to form [1, 6], and the rest remain unchanged. The final output will be [[1, 6], [8, 10], [15, 18]].</p><h4>Algorithm:</h4><ul><li><strong>Sort the Intervals:</strong> First, sort the intervals by their starting point (or endpoint if needed).</li><li><strong>Iterate Through the Intervals:</strong> Iterate through the sorted list and check if the current interval overlaps the previous one.</li><li><strong>Merge Overlapping Intervals:</strong> If they overlap, merge them into a single interval by taking the maximum end time of the two intervals. If they do not overlap, store the previous interval and move to the next one.</li><li><strong>Return the Result:</strong> Once all intervals have been processed, return the list of merged intervals.</li></ul><pre>def merged_intervals(intervals):<br>    if not intervals:<br>        return []<br><br>    # sort the intervals by their starting point<br>    intervals.sort(key=lambda x: x[0])<br><br>    # take the first interval as a starting point<br>    result = [intervals[0]]<br><br>    # Iterate through the sorted list<br>    for current_interval in intervals[1:]:<br>        # fetch the last interval from the result<br>        check_interval = result[-1]<br><br>        # check if the current interval overlaps the previous one.<br>        if current_interval[0] &lt;= check_interval[1]:<br>            # overlap exists and merge the intervals by updating the end time of the current interval<br>            check_interval[1] = max(check_interval[1], current_interval[1])<br>        else:<br>            # no overlaps<br>            result.append(current_interval)<br>    return result<br><br><br>intervals = [[1, 3], [2, 6], [8, 10], [15, 18]]<br>merged = merged_intervals(intervals)<br>print(&quot;Merged intervals:&quot;, merged)</pre><blockquote><strong>Time Complexity: O(n log n)<br>Space Complexity: O(n)</strong></blockquote><h3>Technique: Binary Search</h3><p><a href="https://medium.com/@mahedihasanjisan/competitive-programming-3-binary-search-05cf2c0b318e"><strong>Binary search</strong></a> is a robust algorithm that functions efficiently in O(log n) time under specific conditions. To successfully apply binary search, two crucial requirements must be met:</p><p>1. Monotonicity (Sorted or Ordered Data):<br> — Data must adhere to a consistent order, whether sorted in ascending/descending order or monotonic (strictly increasing, decreasing, or non-decreasing/non-increasing).<br> — Binary search divides the search space, necessitating an ordered structure to effectively determine which half contains the desired value.</p><p>2. Deterministic Condition:<br> — An unambiguous condition is critical to decide which half of the data to search next.<br> — This condition helps eliminate half the search space after each comparison, streamlining the binary search process.</p><p>Confirming that the data meets these conditions is vital to harnessing the power of binary search.</p><h4>Algorithm Blueprint:</h4><pre>def binary_search(array) -&gt; int:<br>    def condition(value) -&gt; bool:<br>        pass<br><br>    left, right = min(search_space), max(search_space)<br>    while left &lt; right:<br>        mid = left + (right - left) // 2<br>        if condition(mid):<br>            right = mid<br>        else:<br>            left = mid + 1<br>    return left</pre><blockquote><strong><em>Time Complexity: </em>O<em>(</em>log n<em>)<br>Space Complexity: O(log n)</em></strong></blockquote><h3>Technique: Backtracking</h3><p>A <a href="https://medium.com/@mahedihasanjisan/competitive-programming-3-backtracking-c9ccb5a1a6ea"><strong>backtracking algorithm</strong></a> is a powerful algorithmic technique that incrementally solves problems by building solution candidates step by step. If a candidate doesn’t achieve the desired outcome, it gracefully “backtracks” by undoing the last step and exploring alternative possibilities.</p><h4>Problem Statement:</h4><p><strong>N-Queens Problem</strong>: Strategizing the placement of N queens on an NxN board.</p><p>Backtracking involves the following features:</p><ul><li>Generate Candidates</li><li>Validity Check</li><li>Backtracking Steps</li></ul><h4>Algorithm for N-Queens and Overall Backtracking Problem:</h4><pre>def is_complete_solution(solution, n):<br>    # Solution is complete if we have placed N queens<br>    return len(solution) == n<br><br><br>def is_valid(candidate, solution):<br>    # Check if the queen placement is valid or not<br>    row, col = candidate<br>    for r, c in solution:<br>        if c == col or abs(r - row) == abs(c - col):  # Same column or diagonal<br>            return False<br>    return True<br><br><br>def generate_candidate(solution, n):<br>    # The current row where a queen needs to be placed<br>    row = len(solution)<br>    # Try all columns in the current row<br>    return [(row, col) for col in range(n)]<br><br><br>def process_solution(solution, solutions):<br>    # Append the valid solution to the solutions list<br>    solutions.append(solution[:])  # Add a copy of the solution<br><br><br>def n_queens(n):<br>    solutions = []  # To store all valid solutions<br><br>    def backtrack(solution):<br>        # Check if we found a solution<br>        if is_complete_solution(solution, n):<br>            # Save the solution<br>            process_solution(solution, solutions)<br>            return<br>        # Explore the candidates<br>        for candidate in generate_candidate(solution, n):<br>            if is_valid(candidate, solution):<br>                solution.append(candidate)  # Choose<br>                backtrack(solution=solution)  # Explore<br>                solution.pop()  # Undo (backtrack)<br><br>    backtrack([])  # Start with an empty solution<br>    return solutions  # Return the list of all valid solutions<br><br><br># Get all solutions for n=4 queens<br>solutions = n_queens(4)<br><br># Print all solutions<br>for idx, solution in enumerate(solutions):<br>    print(f&quot;Solution {idx + 1}: {solution}&quot;)</pre><blockquote><strong>Time Complexity: O(N!)<br>Space Complexity: O(N+N!)</strong></blockquote><h3>Technique: Binary Tree Traversal</h3><p>The binary tree traversal technique involves traversing all the nodes in a binary tree in a specific order.</p><p>Traversing orders are:</p><ul><li>Pre-order: root → left → right</li><li>In-order: left → root → right</li><li>Post-order: left → right → root</li></ul><h4>Problem Statement:</h4><p>Traver a binary tree using all the traversing order.</p><h4>Algorithm:</h4><p>Binary Tree</p><pre># designing a class to make binary tree<br>class Tree():<br>    def __init__(self, val=0, left=None, right=None):<br>        self.val = val<br>        self.left = left<br>        self.right = right<br><br><br># binary tree<br>def binary_tree():<br>    root = Tree(1)<br>    root.left = Tree(2)<br>    root.right = Tree(3)<br>    root.left.left = Tree(4)<br>    root.left.right = Tree(5)<br>    root.right.right = Tree(6)<br>    return root</pre><p><strong>Pre-Order &amp; In-Order &amp; Post-Order Traverse:</strong></p><pre># pre order traversal<br>def pre_order_traverse(root):<br>    if root is None:<br>        return []<br>    return [root.val] + pre_order_traverse(root=root.left) + \<br>        pre_order_traverse(root=root.right)<br><br><br># in order traversal<br>def in_order_traverse(root):<br>    if root is None:<br>        return []<br>    return in_order_traverse(root=root.left) + [root.val] + \<br>        in_order_traverse(root=root.right)<br><br><br># post order traversal<br>def post_order_traverse(root):<br>    if root is None:<br>        return []<br>    return post_order_traverse(root=root.left) + \<br>        post_order_traverse(root=root.right) + [root.val]</pre><blockquote><strong><em>Time Complexity: </em>O<em>(</em>n<em>)<br>Space Complexity: O(log n)</em></strong></blockquote><h3>Technique: Depth-First Search (DFS)</h3><p><strong>Depth-first search (DFS)</strong> is an algorithm for traversing or searching tree or graph data structures. Starting from the root node, DFS explores each branch as far along as possible before backtracking. It uses a <strong>LIFO (Last-In, First-Out)</strong> approach, typically implemented using recursion or an explicit stack.</p><h4>Applications of DFS:</h4><ol><li><strong>Pathfinding and Puzzle Solving</strong> (e.g., mazes).</li><li><strong>Finding Connected Components</strong> in a graph.</li><li><strong>Topological Sorting</strong> (in Directed Acyclic Graphs).</li><li><strong>Detecting Cycles</strong> in a graph.</li><li><strong>Solving problems with backtracking</strong> such as N-Queens, Sudoku, etc.</li></ol><h4>Problem Statement:</h4><p>Traverse a graph using the DFS technique.</p><h4>Algorithm</h4><p><strong>Recursive technique</strong></p><pre>def dfs_recursive(graph, node, visited=None):<br>    if visited is None:<br>        visited = set()<br><br>    # add the root node to visited<br>    visited.add(node)<br>    print(node, end=&#39; &#39;)<br><br>    # exploring the neighbors<br>    for neighbor in graph[node]:<br>        if neighbor not in visited:<br>            dfs_recursive(graph, neighbor, visited)<br><br><br># graph<br>graph = {<br>    1: [2, 3],<br>    2: [4, 5],<br>    3: [],<br>    4: [],<br>    5: []<br>}</pre><p><strong>Using stack</strong></p><pre>def dfs_stack(graph, start):<br>    # track of visited node<br>    visited = set()<br>    # using stack for DFS<br>    stack = [start]<br><br>    while stack:<br>        node = stack.pop()<br><br>        if node not in visited:<br>            print(node, end=&#39; &#39;)<br>            visited.add(node)<br><br>        for neighbor in reversed(graph[node]):<br>            if neighbor not in visited:<br>                stack.append(neighbor)<br><br><br># graph<br>graph = {<br>    1: [2, 3],<br>    2: [4, 5],<br>    3: [],<br>    4: [],<br>    5: []<br>}</pre><blockquote><strong>Time Complexity: O(V+E); V = Vertices/nodes &amp; E = Edges<br>Space Complexity: O(V)</strong></blockquote><h3>Technique: Breadth-First Search (BFS)</h3><p><strong>Breadth-First Search (BFS)</strong> is a graph traversal algorithm that explores the nodes of a graph (or tree) level by level. Starting from the root node, BFS explores all its neighbours before moving on to their neighbours. This exploration continues until all nodes are visited. It uses a <strong>queue (FIFO)</strong> data structure to keep track of the nodes at each level.</p><h4>Applications of BFS:</h4><ol><li><strong>Shortest Path in Unweighted Graphs</strong>: BFS guarantees to find the shortest path regarding the number of edges in an unweighted graph.</li><li><strong>Connected Components</strong>: BFS can help find connected components in a graph.</li><li><strong>Cycle Detection</strong>: BFS can be used to detect cycles in undirected graphs.</li><li><strong>Solving Puzzles</strong>: BFS is ideal for solving puzzles like mazes, where all possible moves are explored level by level.</li><li><strong>Web Crawlers</strong>: BFS explores the web level by level (i.e., site by site).</li></ol><h4>Problem Statement:</h4><p>Traverse a graph using the DFS technique.</p><h4>Algorithm:</h4><pre>from collections import deque<br><br><br>def bfs(graph, root):<br>    # visited nodes, queue to implement FIFO<br>    visited = set()<br>    queue = deque([root])<br>    visited.add(root)<br><br>    while queue:<br>        # FIFO<br>        node = queue.popleft()<br>        print(node, end=&#39; &#39;)<br>        # exploring the neighbors<br>        for neighbor in graph[node]:<br>            if neighbor not in visited:<br>                queue.append(neighbor)<br>                visited.add(neighbor)<br><br><br>graph = {<br>    1: [2, 3],<br>    2: [4, 5],<br>    3: [],<br>    4: [],<br>    5: []<br>}<br>print(&quot;BFS Traversal:&quot;, end=&quot; &quot;)<br>bfs(graph, 1)</pre><p><strong>BFS in a binary tree or Level-Order Traversal:</strong></p><pre>def bfs_binary_tree(root):<br>    if root is None:<br>        return []<br>    queue = deque([root])<br>    while queue:<br>        # FIFO<br>        node = queue.popleft()<br>        print(node, end=&#39; &#39;)<br>        if node.left:<br>            queue.append(node.left)<br>        if node.right:<br>            queue.append(node.right)</pre><blockquote><strong>Time Complexity: O(V+E); V = Vertices/nodes &amp; E = Edges<br>Space Complexity: O(V)</strong></blockquote><h3>Technique: Matrix Traversal</h3><p><strong>Matrix traversal</strong> refers to visiting or iterating over the elements in a 2D matrix (grid) in a specific order. A matrix is a 2D array where each element is identified by its row and column indices.</p><h4>A DFS approach to traverse the matrix:</h4><pre>def dfs(matrix, i, j, visited):<br>    rows = len(matrix)<br>    cols = len(matrix[0])<br><br>    # base case<br>    if i &lt; 0 or j &gt;= rows or j &lt; 0 or j &gt;= cols or visited[i][j]:<br>        return<br><br>    visited[i][j] = True<br>    print(matrix[i][j], end=&#39; &#39;)<br><br>    # explore in all four directions: up, down, left, right<br>    dfs(matrix, i-1, j, visited) # up<br>    dfs(matrix, i+1, j, visited) # down<br>    dfs(matrix, i, j-1, visited) # left<br>    dfs(matrix, i, j+1, visited) # right<br><br><br>def dfs_traversal(matrix):<br>    rows = len(matrix)<br>    cols = len(matrix[0])<br>    visited = [[False for _ in range(cols)] for _ in range(rows)]<br><br>    # Traverse starting from (0, 0) for the whole matrix<br>    dfs(matrix, 0, 0, visited)</pre><h4>Problem Statement:</h4><p>The <strong>Flood Fill</strong> algorithm is similar to the “paint bucket” tool in graphics programs, where you start from a given pixel and fill all connected pixels with a new colour. The connection between pixels is typically based on the four neighbouring cells (up, down, left, and right) that share the same initial colour as the starting pixel.</p><p>The goal is to traverse all the connected cells (based on the same colour) and change them to the new colour.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8l3JpZIviTk--SDWsrayqg.png" /><figcaption>Photo By: Author</figcaption></figure><h4>Algorithm:</h4><pre>from collections import deque<br><br><br>def flood_fill_dfs(image, sr, sc, newColor):<br>    # using DFS<br>    original_color = image[sr][sc]<br><br>    # base condition: if it&#39;s already the same color<br>    if original_color == newColor:<br>        return image<br><br>    def dfs(i, j):<br>        # base condition: check other constraints<br>        if i &lt; 0 or i &gt;= len(image) or j &lt; 0 or j &gt;= len(image[0]) or \<br>                image[i][j] != original_color:<br>            return<br>        # Change the color of the current cell<br>        image[i][j] = newColor<br><br>        # perform dfs to all possible directions<br>        dfs(i - 1, j)  # Up<br>        dfs(i + 1, j)  # Down<br>        dfs(i, j - 1)  # Left<br>        dfs(i, j + 1)  # Right<br>    dfs(sr, sc)<br>    return image<br><br><br>def flood_fill_bfs(image, sr, sc, newColor):<br>    original_color = image[sr][sc]<br><br>    # base condition: if it&#39;s already the same color<br>    if original_color == newColor:<br>        return image<br>    queue = deque([sr, sc])<br><br>    # BFS<br>    while queue:<br>        x, y = queue.popleft()<br>        # explore all four directions<br>        for dx, dy in [(-1, 0), (1, 0), (0, -1), (0, 1)]:<br>            new_x, new_y = dx + x, dy + y<br><br>            # check if new coordinates are valid and have the original color<br>            if 0 &lt;= new_x &lt; len(image) and 0 &lt;= new_y &lt; len(image[0]) and \<br>                    image[new_x][new_y] == original_color:<br>                # Change the color and add the cell to the queue<br>                image[new_x][new_y] = newColor<br>                queue.append((new_x, new_y))<br>    return image</pre><blockquote><strong>Time Complexity: O(m * n)<br>Space Complexity: O(m * n)</strong></blockquote><h3>Technique: Dynamic Programming</h3><p>Dynamic programming (DP) is an algorithmic technique for solving optimization problems. It involves breaking them down into simpler subproblems, solving each subproblem just once, and storing its solution to avoid recomputing it multiple times. DP is beneficial for problems with overlapping subproblems and optimal substructure.</p><h4>Critical Concepts of Dynamic Programming:</h4><ol><li><strong>Overlapping Subproblems</strong>: The problem can be divided into subproblems reused multiple times.</li><li><strong>Optimal Substructure</strong>: The optimal solution of the original problem can be constructed from the optimal solutions of its subproblems.</li><li><strong>Memoization</strong>: Storing the results of expensive function calls and reusing them when the same inputs occur again. This is usually a top-down approach.</li><li><strong>Tabulation</strong>: Solving the problem iteratively and storing the results in a table (often a 2D array). This is a bottom-up approach.</li></ol><h4>Problem Statement:</h4><p>Finding Fibonacci sequence for a given number using top-down and bottom-up approaches.</p><h4>Algorithm:</h4><p><strong>Top-Down Approach:</strong></p><pre>def dp_top_down(problem_params):<br>    # Memoization table (dictionary or array) to store already computed subproblem solutions<br>    memo = {}<br><br>    # Helper function to solve the subproblems recursively<br>    def solve(subproblem_params):<br>        # Base case: If the subproblem is trivial or already known<br>        if is_base_case(subproblem_params):<br>            return base_case_value(subproblem_params)<br><br>        # If the result for this subproblem is already computed, return it<br>        if subproblem_params in memo:<br>            return memo[subproblem_params]<br><br>        # Break the subproblem into smaller subproblems and solve them<br>        result = float(&#39;inf&#39;)  # Initialize result with an impossible or infinity value<br>        for smaller_subproblem in get_subproblems(subproblem_params):<br>            result = min(result, solve(smaller_subproblem))  # Modify as per the problem needs<br><br>        # Store the computed result in memo table<br>        memo[subproblem_params] = result<br>        return result<br><br>    # Call the recursive function with the initial problem parameters<br>    return solve(problem_params)</pre><p><strong>Fibonacci Sequence</strong></p><pre>def fibonacci_top_down(n):<br>    memo = {}<br><br>    def fib(n):<br>        if n &lt;= 1:<br>            return n<br>        if n in memo:<br>            return memo[n]<br>        memo[n] = fib(n - 1) + fib(n - 2)<br>        return memo[n]<br><br>    return fib(n)<br><br># Example usage<br>print(fibonacci_top_down(10))  # Output: 55</pre><p><strong>Bottom-Up Approach</strong></p><pre>def dp_bottom_up(problem_size):<br>    # Create a table (array or 2D matrix) to store the results of subproblems<br>    dp_table = [0] * (problem_size + 1)  # Modify size and initialization as per problem needs<br><br>    # Initialize base case(s) in the table<br>    dp_table[0] = base_case_value  # Example: set the base case<br><br>    # Iterate through and fill the table by solving smaller subproblems<br>    for i in range(1, problem_size + 1):<br>        dp_table[i] = float(&#39;inf&#39;)  # Set an initial impossible value<br>        for subproblem in get_possible_subproblems(i):<br>            dp_table[i] = min(dp_table[i], dp_table[subproblem] + some_cost)  # Modify as per the problem needs<br><br>    # The answer to the original problem is now stored in dp_table[problem_size]<br>    return dp_table[problem_size]</pre><p><strong>Fibonacci Sequence</strong></p><pre>def fibonacci_bottom_up(n):<br>    if n &lt;= 1:<br>        return n<br>    dp = [0] * (n + 1)<br>    dp[0], dp[1] = 0, 1<br>    for i in range(2, n + 1):<br>        dp[i] = dp[i - 1] + dp[i - 2]<br>    return dp[n]<br><br># Example usage<br>print(fibonacci_bottom_up(10))  # Output: 55</pre><blockquote><strong>Time Complexity: O(n)<br>Space Complexity: O(n)</strong></blockquote><h3>Conclusion</h3><p>This article delves into the most utilized programming concepts, offering various resources from various sources and experiences. It aims to assist you in tackling numerous problems and preparing for interviews. Best of luck with your endeavours! Thank you for taking the time to read it. 🙌</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=acade1327eb6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Competitive Programming #4: Backtracking]]></title>
            <link>https://mahedihasanjisan.medium.com/competitive-programming-3-backtracking-c9ccb5a1a6ea?source=rss-3ccbddc05ddf------2</link>
            <guid isPermaLink="false">https://medium.com/p/c9ccb5a1a6ea</guid>
            <category><![CDATA[backtracking]]></category>
            <category><![CDATA[backtracking-algorithm]]></category>
            <category><![CDATA[recursion]]></category>
            <category><![CDATA[algorithms]]></category>
            <dc:creator><![CDATA[Mahedi Hasan Jisan]]></dc:creator>
            <pubDate>Tue, 10 Sep 2024 01:17:25 GMT</pubDate>
            <atom:updated>2024-09-10T01:17:53.611Z</atom:updated>
            <content:encoded><![CDATA[<p>A backtracking algorithm is a powerful algorithmic technique that incrementally solves problems by building solution candidates step by step. If a candidate doesn&#39;t achieve the desired outcome, it gracefully &quot;backtracks&quot; by undoing the last step and exploring alternative possibilities.</p><h4>Every backtracking algorithm necessitates two fundamental components:</h4><ul><li>A problem that can be incrementally built up, such as generating all permutations or solving mazes.</li><li>A solution space that allows for the exploration of each partial solution.</li></ul><p>Backtracking in programming involves a recursive function that systematically explores potential partial solutions and validates each step. If a partial solution is deemed invalid, the process initiates a backtrack.</p><h4>Exploring the critical components of the Backtracking algorithm:</h4><p>-Base Case: It&#39;s crucial to check if the current solution is complete and valid.</p><p>-Generate Candidates: A set of candidates is generated at each recursive step.</p><p>-Validity Check: Ensuring that adding a candidate doesn&#39;t violate any problem constraints.</p><p>-Backtracking Step: Exploring a candidate and its possibilities, then backtracking by removing the last candidate to try another.</p><p>Understanding these components is essential for effective problem-solving using Backtracking.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1um3X_nYk7F1U0M-lmFbVA.png" /><figcaption>Photo By: Author</figcaption></figure><blockquote>Backtracking explores many possible candidate solutions, so its time complexity can vary widely depending on the problem. For example, in the N-Queens problem, the worst-case time complexity is O(N!), where N is the board size because the algorithm explores many permutations of placements.</blockquote><p>Backtracking is a powerful technique that can help solve various combinatorial and constraint satisfaction issues. Some of the critical problems it can tackle include:</p><ol><li><strong>N-Queens Problem</strong>: Strategizing the placement of N queens on an NxN board.</li><li><strong>Sudoku</strong>: Filling a Sudoku board while adhering to specific number constraints.</li><li><strong>Permutations and Combinations</strong>: Generating all possible permutations or combinations of a given set.</li><li><strong>Subset Sum</strong>: Identifying subsets of a set that add up to a particular value.</li><li><strong>Knapsack Problem</strong>: Solve the 0/1 knapsack problem by selecting the optimal items to fit in a bag with a weight restriction.</li></ol><h3>N-Queens Problem:</h3><p>The <strong>N-Queens problem</strong> is a classic combinatorial problem in which you are tasked with placing N queens on an NxN chessboard so that no two queens threaten each other. A queen can attack another queen if they are on the same:</p><ul><li>Row</li><li>Column</li><li>Diagonal</li></ul><p>The goal is to find all possible ways to arrange N queens on the board so that no two can attack each other.</p><h4>Problem Statement:</h4><p>Given an integer N, place N queens on an N x N Chessboard such that no two queens are in the same row, column, or diagonal. The output should list all the valid arrangements (solutions) where the queens are safely placed.</p><h4>Base Case:</h4><p>If the solution has all the queens, then we can print the solution and exit the backtracking algorithm.</p><h4>Generate Candidates:</h4><p>We need to iterate all the columns in the current row to place the queen.</p><h4>Validity Check:</h4><p>We need to check if the queen&#39;s position is valid, which means checking if another queen is in the same row, column, or diagonally.</p><h4>Backtracking Step:</h4><p>If the candidate is valid, we can add it to the solution and explore or backtrack on it. If the exploration gives us the base case satisfaction, we continue with the next candidate and store it to the solution; otherwise, we discard that existing solution and pursue another one.</p><pre>def is_complete_solution(solution, n):<br>    # Solution is complete if we have placed N queens<br>    return len(solution) == n<br><br><br>def is_valid(candidate, solution):<br>    # Check if the queen placement is valid or not<br>    row, col = candidate<br>    for r, c in solution:<br>        if c == col or abs(r - row) == abs(c - col):  # Same column or diagonal<br>            return False<br>    return True<br><br><br>def generate_candidate(solution, n):<br>    # The current row where a queen needs to be placed<br>    row = len(solution)<br>    # Try all columns in the current row<br>    return [(row, col) for col in range(n)]<br><br><br>def process_solution(solution, solutions):<br>    # Append the valid solution to the solutions list<br>    solutions.append(solution[:])  # Add a copy of the solution<br><br><br>def n_queens(n):<br>    solutions = []  # To store all valid solutions<br><br>    def backtrack(solution):<br>        # Check if we found a solution<br>        if is_complete_solution(solution, n):<br>            # Save the solution<br>            process_solution(solution, solutions)<br>            return<br>        # Explore the candidates<br>        for candidate in generate_candidate(solution, n):<br>            if is_valid(candidate, solution):<br>                solution.append(candidate)  # Choose<br>                backtrack(solution=solution)  # Explore<br>                solution.pop()  # Undo (backtrack)<br><br>    backtrack([])  # Start with an empty solution<br>    return solutions  # Return the list of all valid solutions<br><br><br># Get all solutions for n=4 queens<br>solutions = n_queens(4)<br><br># Print all solutions<br>for idx, solution in enumerate(solutions):<br>    print(f&quot;Solution {idx + 1}: {solution}&quot;)</pre><h4>Output</h4><blockquote>Solution 1: [(0, 1), (1, 3), (2, 0), (3, 2)]<br>Solution 2: [(0, 2), (1, 0), (2, 3), (3, 1)]</blockquote><h4>Complexity:</h4><ul><li><strong>Time Complexity</strong>: O(N!)</li><li><strong>Space Complexity</strong>: O(N+N!)</li></ul><p>The time complexity is factorial due to the problem&#39;s constraints (trying all possible placements of queens). In contrast, the space complexity depends on the recursion depth and the number of valid solutions stored.</p><h3>Conclusion</h3><p>This template will find all the solutions for N-queen problems. The same template can be used for the other examples mentioned above.</p><p>Understanding the Backtracking Algorithm Blueprint can be a game-changer! By defining the solution space, setting up structures, and following the recursive backtracking function, you can efficiently solve complex problems. Backtracking allows you to explore all possibilities systematically and construct solutions increments. It&#39;s a powerful tool that enables decision-making one step at a time, ensuring efficient problem-solving.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c9ccb5a1a6ea" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Competitive Programming #3: Binary Search]]></title>
            <link>https://mahedihasanjisan.medium.com/competitive-programming-3-binary-search-05cf2c0b318e?source=rss-3ccbddc05ddf------2</link>
            <guid isPermaLink="false">https://medium.com/p/05cf2c0b318e</guid>
            <category><![CDATA[binary-search]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[algorithms]]></category>
            <dc:creator><![CDATA[Mahedi Hasan Jisan]]></dc:creator>
            <pubDate>Sun, 08 Sep 2024 01:16:47 GMT</pubDate>
            <atom:updated>2024-09-08T16:58:05.138Z</atom:updated>
            <content:encoded><![CDATA[<h3>Binary Search</h3><p>Binary search is a robust algorithm that functions efficiently in O(log n) time under specific conditions. To successfully apply binary search, two crucial requirements must be met:</p><p>1. Monotonicity (Sorted or Ordered Data):<br> — Data must adhere to a consistent order, whether sorted in ascending/descending order or monotonic (strictly increasing, decreasing, or non-decreasing/non-increasing).<br> — Binary search divides the search space, necessitating an ordered structure to determine which half contains the desired value effectively.</p><p>2. Deterministic Condition:<br> — An unambiguous condition is critical to decide which half of the data to search next.<br> — This condition helps eliminate half the search space after each comparison, streamlining the binary search process.</p><p>Confirming that the data meets these conditions is vital to harnessing the power of binary search.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A-bZgkYoDA_rXOJyyXRwhg.png" /><figcaption><a href="https://www.digitalocean.com/community/tutorials/js-linear-vs-binary-search">Author By</a></figcaption></figure><pre>def binary_search(array) -&gt; int:<br>    def condition(value) -&gt; bool:<br>        pass<br><br>    left, right = min(search_space), max(search_space)<br>    while left &lt; right:<br>        mid = left + (right - left) // 2<br>        if condition(mid):<br>            right = mid<br>        else:<br>            left = mid + 1<br>    return left</pre><h4>Cases Where Binary Search Does Not Work:</h4><ol><li><strong>Unordered or Random Data</strong>: If the data is unordered or random, binary search cannot be directly applied because you cannot guarantee which half contains the target. A linear search would be required in such cases.</li><li><strong>Non-Monotonic Functions</strong>: Binary search does not apply to problems where the search space is not structured in a way that allows you to reduce it by half consistently. For example, if the data oscillates or doesn’t follow a precise order, a binary search won’t work.</li><li><strong>Dynamic Data (without re-sorting)</strong>: If the data changes dynamically, you must sort it again before using binary search. If sorting takes O(n log n) time, the benefits of using binary search for small or frequently changing datasets may outweigh the benefits.</li></ol><h4>Steps of Binary Search:</h4><ul><li>Divide the array in half.</li><li>Compare the target to the middle element.</li><li>Continue searching in the left or right half based on the comparison/conditional function.</li></ul><h4>Time Complexity:</h4><ul><li><strong>Best case:</strong> O(1) — when the middle element is the target element.</li><li><strong>Average case and worst case:</strong> O(log⁡n)— because the array size is halved in each step, making the algorithm logarithmic in time complexity, where n is the number of elements in the array.</li></ul><h4>Space Complexity:</h4><ul><li><strong>Iterative implementation:</strong> O(1) — since only a few variables (like the middle index and search range) are needed.</li><li><strong>Recursive implementation:</strong> O(log⁡n) — due to the recursive call stack, where n is the size of the array.</li></ul><p>Let’s discuss an interesting problem.</p><p>Problem: <a href="https://leetcode.com/problems/minimum-number-of-days-to-make-m-bouquets/">1482. Minimum Number of Days to Make m Bouquets</a></p><pre>You are given an integer array bloomDay, an integer m and an integer k.<br><br>You want to make m bouquets. To make a bouquet, you need to use k adjacent flowers from the garden.<br><br>The garden consists of n flowers, the ith flower will bloom in the bloomDay[i] and then can be used in exactly one bouquet.<br><br>Return the minimum number of days you need to wait to be able to make m bouquets from the garden. If it is impossible to make m bouquets return -1.<br><br> <br><br>Example 1:<br><br>Input: bloomDay = [1,10,3,10,2], m = 3, k = 1<br>Output: 3<br>Explanation: Let us see what happened in the first three days. x means flower bloomed and _ means flower did not bloom in the garden.<br>We need 3 bouquets each should contain 1 flower.<br>After day 1: [x, _, _, _, _]   // we can only make one bouquet.<br>After day 2: [x, _, _, _, x]   // we can only make two bouquets.<br>After day 3: [x, _, x, _, x]   // we can make 3 bouquets. The answer is 3.</pre><blockquote>You might think of improvising some programming skills to solve the issue.</blockquote><p>Now, let’s debunk this issue:</p><ol><li>The array element in bloomDay indicates the flower blooming day ; <br>[1 (day 1), 10 (day 10), 3 (day 3), 10 (day 10), 2 (day 2)]</li><li>m = 3; we need to make three bouquets, and k = 1; we need at least flower to make a bouquet.</li><li>However, another special constraint exists for other cases; we must use k adjacent flowers to make the bouquet.</li></ol><blockquote>Outcome Required: Return <em>the minimum number of days you need to wait to be able to make </em>m<em> bouquets from the garden</em>. If it is impossible to make m bouquets return -1.</blockquote><h4>Base Case:</h4><pre>if len(bloomDay) &lt; (m * k):<br>    return -1</pre><p>From the description, we could find our solution in various days. We need the minimum number of days from that range, and that’s where we can apply a binary search algorithm to reduce our search space.</p><pre>while left &lt; right:<br>  mid = left + (right - left) // 2<br>  if condition(mid):<br>      right = mid<br>  else:<br>      left = mid + 1</pre><p>We will send the mid value to the conditional function, where we can make some conditions to reduce our search space that doesn’t produce the outcome.</p><pre>def feasible(val):<br>    consequetive_flower = 0<br>    bouquet = 0 <br>    for f in bloomDay:<br>        if f &lt;= val:<br>            consequetive_flower += 1 <br>            if consequetive_flower == k:<br>                bouquet += 1<br>                consequetive_flower = 0<br>        else:<br>            consequetive_flower = 0<br>        if bouquet &gt;= m:<br>            return True<br>    return False</pre><p>Since the mid-value and the bloodDay elements represent the day number, and we can check which element in the list is within the mid-value and keep track of the consecutive or adjacent day-bloomed flowers. if the consequetive_flower value met the k then we can make a bouquet. Check if the bouquet number is equal to or greater than the required m , then return true; otherwise false.</p><p>Therefore, using binary search and a conditional function yields the desired result and produces an optimal solution in terms of time and space complexity.</p><pre>class Solution:<br>    def minDays(self, bloomDay: List[int], m: int, k: int) -&gt; int:<br>        # Helper function to check if we can make &#39;m&#39; bouquets by day &#39;val&#39;<br>        def feasible(val):<br>            consequetive_flower = 0<br>            bouquet = 0  # Track how many bouquets we can make<br>            for f in bloomDay:<br>                if f &lt;= val:<br>                    consequetive_flower += 1  # Found a flower bloomed on or before &#39;val&#39;<br>                    if consequetive_flower == k:<br>                        bouquet += 1  # We made one bouquet<br>                        consequetive_flower = 0  # Reset counter after making a bouquet<br>                else:<br>                    consequetive_flower = 0  # Reset consecutive counter if flower not bloomed<br>                if bouquet &gt;= m:<br>                    return True  # We have enough bouquets<br>            return False<br><br>        # If there are not enough flowers to make &#39;m&#39; bouquets<br>        if len(bloomDay) &lt; (m * k):<br>            return -1<br><br>        left, right = min(bloomDay), max(bloomDay)<br>        while left &lt; right:<br>            mid = left + (right - left) // 2<br>            if feasible(mid):<br>                right = mid  # Try to find a smaller day<br>            else:<br>                left = mid + 1  # Increase the minimum number of days needed<br>        return left if feasible(left) else -1</pre><blockquote>Time Complexity: <em>O</em>(<em>NLog</em>(<em>Max</em>(<em>Bloomday</em>)))<br>Space Complexity: O(1)</blockquote><p>Binary search is highly efficient but is only a universal solution for some search problems. The essential requirements are that the data or function must be ordered or monotonic, and you need a condition that can reliably help you eliminate half of the search space in each step. If these conditions are met, binary search can be applied. Otherwise, other search algorithms (like linear search) or techniques must be considered.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=05cf2c0b318e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Jenkins Architecture and Pipelines]]></title>
            <link>https://blog.devops.dev/jenkins-architecture-and-pipelines-a17edac84f6d?source=rss-3ccbddc05ddf------2</link>
            <guid isPermaLink="false">https://medium.com/p/a17edac84f6d</guid>
            <category><![CDATA[jenkins]]></category>
            <category><![CDATA[continuous-integration]]></category>
            <category><![CDATA[jenkins-pipeline]]></category>
            <category><![CDATA[ci-cd-pipeline]]></category>
            <category><![CDATA[jenkinsfile]]></category>
            <dc:creator><![CDATA[Mahedi Hasan Jisan]]></dc:creator>
            <pubDate>Wed, 28 Aug 2024 19:07:40 GMT</pubDate>
            <atom:updated>2024-09-04T18:53:53.054Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NDQbu3hlyDrGp8yMfmNpdg.png" /><figcaption>Photo By: Author</figcaption></figure><p>In software development, Jenkins is an open-source automation server for continuous integration and delivery, also known as CI/CD.</p><p>Jenkins consists of the following two categories:</p><ol><li><strong>Jenkins Server</strong>: Manages the pipeline and the associated jobs. The Jenkins server or controller sends the pipeline instructions to Jenkins Agents and receives and stores the results.</li><li><strong>Jenkins Agents</strong>: Jenkins agents receive the pipeline instructions from the controller and execute the jobs. After executing the jobs, agents return the job results to the controller. There can be more than one jenkins agent to make the process faster.</li></ol><h4>What is a Job?</h4><p>Jenkins job is a set of tasks that jenkins performs, like building code, running tests, and deploying an application. Jobs can be configured individually and triggered by various events such as code commit. Traditionally, a job might execute only a single task.</p><p>More Information <a href="https://www.jenkins.io/doc/book/using/working-with-projects/">Here</a>.</p><h4>What is a Pipeline?</h4><p>A Jenkins pipeline is a set of automated processes that can define multiple jobs to complete the build and deployment process.</p><p>Types of Jenkins Pipeline:</p><p><strong>Declarative Pipeline</strong>: A structured block-syntax approach to defining multiple stages in the pipeline makes it easier to write and maintain.</p><pre>pipeline {<br>    agent any<br>    stages {<br>        stage(&#39;Build&#39;) {<br>            steps {<br>                echo &#39;Building...&#39;<br>            }<br>        }<br>        stage(&#39;Test&#39;) {<br>            steps {<br>                echo &#39;Testing...&#39;<br>            }<br>        }<br>        stage(&#39;Deploy&#39;) {<br>            steps {<br>                echo &#39;Deploying...&#39;<br>            }<br>        }<br>    }<br>}</pre><p><strong>Scripted Pipeline</strong>: An approach to define pipeline stages using Groovy-like syntax. It allows the application of complex and customized pipeline configurations that require a deeper understanding of Jenkins DSL.</p><pre>node {<br>    stage(&#39;Build&#39;) {<br>        echo &#39;Building...&#39;<br>    }<br>    stage(&#39;Test&#39;) {<br>        echo &#39;Testing...&#39;<br>    }<br>    stage(&#39;Deploy&#39;) {<br>        echo &#39;Deploying...&#39;<br>    }<br>}</pre><blockquote>Freestyle jobs in Jenkins do not support the “pipeline as code” principle, which leads to significant challenges in modern CI/CD practices. Since configurations in freestyle jobs are done via the Jenkins UI and are not version-controlled, it becomes difficult to track, review, or revert changes, undermining best practices in DevOps that emphasize automation, version control, and repeatability. Additionally, setting up complex workflows with freestyle jobs often requires extensive use of plugins, resulting in fragmented and hard-to-manage setups.</blockquote><p>Previous Article: <a href="https://medium.com/@mahedihasanjisan/how-to-run-jenkins-using-docker-03dce5ae1920">How to run Jenkins using Docker?</a></p><h4>How to create a Job?</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SGZ3GJAqBSo9WE-UAUThvA.png" /><figcaption>Photo By: Author</figcaption></figure><p>Provide a name, select “freestyle-project,” and click okay to create your first job. Now, we will configure “Build Steps” where a shell command will be executed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b0K7C3o6jPynLuR_iOA1ww.png" /><figcaption>Photo By: Author</figcaption></figure><p>Now, we are going to build and run the job.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RANksRiiLLYQpCs7ay6thg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1005/1*ZqbqzlZxwjJOC9HX14GHaw.png" /><figcaption>Photo By: Author</figcaption></figure><p>The job is successfully executed, and the console returns the output we wrote in the shell script in the build stage.</p><h4>How to create a Pipeline?</h4><p>Use the above steps, and instead of “Freestyle project”, select “Pipeline” and click okay to create the jenkins pipeline. The window will redirect you to the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hjWJUrTm8OTDyAbrXHoQ8A.png" /><figcaption>Photo By: Author</figcaption></figure><p>Multiple stages are created in the pipeline to make a sandwich and serve it to a friend or anybody you want! 😉 Using the Groovy syntax, you can easily create a pipeline with several stages to build, test, and deploy your application.</p><p>If you “Build Now” the pipeline, it will be executed, and you can see the build history in Jenkins.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qNveetDz-6scbDGd0meAmQ.png" /><figcaption>Photo By: Author</figcaption></figure><p>It is reasonably easy to create jobs and pipelines using Jenkins. For example, you can write a wrong command in the pipeline script and see what happens when you try to build it. Happy hunting. 😂</p><p>This article discusses the primary concepts of Jenkins architecture, jobs, and pipelines. A future article will provide a more in-depth discussion of the Jenkin pipeline. Hopefully, this article will get you going with the basic concepts of the jenkins. Thanks for the read. 🙌</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a17edac84f6d" width="1" height="1" alt=""><hr><p><a href="https://blog.devops.dev/jenkins-architecture-and-pipelines-a17edac84f6d">Jenkins Architecture and Pipelines</a> was originally published in <a href="https://blog.devops.dev/">DevOps.dev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Competitive Programming #2: Two Pointers]]></title>
            <link>https://mahedihasanjisan.medium.com/competitive-programming-1-two-pointers-algorithm-64a812f39fc1?source=rss-3ccbddc05ddf------2</link>
            <guid isPermaLink="false">https://medium.com/p/64a812f39fc1</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[competitive-programming]]></category>
            <category><![CDATA[lists]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Mahedi Hasan Jisan]]></dc:creator>
            <pubDate>Mon, 26 Aug 2024 20:24:30 GMT</pubDate>
            <atom:updated>2024-09-08T21:21:06.422Z</atom:updated>
            <content:encoded><![CDATA[<p>The two-pointer technique is a common algorithmic approach for solving problems on arrays or linked lists. <em>It involves using two pointers to iterate through the data structure, often leading to more efficient solutions</em>. This technique finds pairs, subarrays, or meeting conditions involving elements at different data structure positions.</p><p>Issue #1: Find an array&#39;s target sum of two elements.</p><h4>Consideration: Sorted Array</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v4ymrxJOiUJsnH1hMdaajw.png" /><figcaption>Two Pointers * Photo By Author</figcaption></figure><p>In the above example, we are trying to find a target sum of two numbers from a sorted array where two pointers are started from two ends and iterate the array based on the following condition:</p><ol><li><strong>If P1 + P2 &gt; Target; then move P2</strong></li><li><strong>If P1 + P2 &lt; Target; then move P1</strong></li></ol><pre>def tpa(target, arr):<br>    i = 0<br>    j = len(arr) - 1<br>    while i &lt; j:<br>        find_sum = arr[i] + arr[j]<br>        if find_sum &gt; target:<br>            j -= 1<br>        elif find_sum &lt; target:<br>            i += 1<br>        else:<br>            return f&quot;Found the target and the values are: {arr[i]}, {arr[j]}&quot;<br>    return &quot;Target not found!&quot;<br><br><br>print(tpa(29, [3, 4, 8, 20, 25, 30]))</pre><ul><li><strong>Time Complexity:</strong> O(n)</li><li><strong>Space Complexity:</strong> O(1)</li></ul><blockquote>In the <strong>two-pointer</strong> technique, the pointers often move toward each other rather than maintaining a contiguous “window.”</blockquote><h4>Consideration: Unsorted Array</h4><p>What about an unsorted array? Can we still apply the two-pointers?</p><p>The answer is yes. We still can, but we need to sort the array.</p><p><strong>Sorting + Two Pointers:</strong></p><ul><li><strong>Step 1:</strong> First, sort the array. This takes O(n log⁡n) time.</li><li><strong>Step 2:</strong> Apply the two-pointer technique for a sorted array.</li><li><strong>Total Time Complexity:</strong> O(n log⁡n) due to the sorting step.</li></ul><p><strong>Question</strong>: Is there any way we can make the process faster?</p><p><strong>Answer</strong>: Yes, we can use a hash set.</p><pre>def tpa_unsorted_array(target, arr):<br>    store = set()<br>    for i in arr:<br>        find_sum = target - i<br>        if find_sum in store:<br>            return (find_sum, i)<br>        store.add(i)</pre><ul><li><strong>Time Complexity:</strong> O(n)</li><li><strong>Space Complexity:</strong> O(n) because of the hash set.</li></ul><p>Let&#39;s consider a fairly complex example to understand the concept of the two pointers:</p><p>&quot;Given two strings s and t, return true <em>if they are equal when both are typed into empty text editors</em>. &#39;#&#39; Means a backspace character.</p><p><strong>Note</strong> that the text will continue empty after backspacing an empty text.&quot;</p><blockquote>Reference: <a href="https://leetcode.com/problems/backspace-string-compare/">Backspace String Compare</a> <br><strong>Follow up:</strong> Can you solve it in O(n) time and O(1) space?</blockquote><p>Target:</p><p>In the problem, &quot;#&quot; means a backspace needs to be done in the string. There can be multiple backspaces, and based on that, we need to do backspace, which means removing a character from the string.</p><ol><li>Find a valid index to compare.</li><li>If the index number isn&#39;t valid, then return false.</li><li>If the comparison doesn&#39;t match, then return False.</li><li>Otherwise, return true.</li></ol><pre>def backspaceCompare(self, s: str, t: str) -&gt; bool:<br>        def valid_index(s: str, index: int) -&gt; int:<br>            backspace_count = 0<br>            while index &gt;= 0:<br>                if s[index] == &#39;#&#39;:<br>                    backspace_count += 1<br>                elif backspace_count &gt; 0:<br>                    backspace_count -= 1<br>                else:<br>                    break<br>                index -= 1<br>            return index<br>                    <br>        s1 = len(s) - 1<br>        t1 = len(t) - 1<br><br>        while s1 &gt;= 0 or t1 &gt;= 0:<br>            s1 = valid_index(s, s1)<br>            t1 = valid_index(t, t1)<br><br>            if s1 &gt;= 0 and t1 &gt;= 0 and s[s1] != t[t1]:<br>                return False<br>            if (s1 &gt;= 0) != (t1 &gt;= 0):<br>                return False<br><br>            s1 -= 1<br>            t1 -= 1<br>        return True</pre><p>Let&#39;s explain both if condition where it returns False.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k2M6QJ1yWCci3zl00oHWCw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ggx6N8IfoMPVEVKGdsKUtg.png" /><figcaption>Photo By: Author</figcaption></figure><p>In the solution, the valid_index() function sends back the current index after backspacing the string. After applying the backspace, these indexes are returned, and the index values are checked to see if they are valid. If valid and both characters match, return true; otherwise, return false.</p><p>The two-pointer is successfully applied in the above problem.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/455/1*z670jDpY1pM6XAK56mAxwA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/455/1*17Q_C79i7hW9kBNveoch6Q.png" /><figcaption>Photo By: Author</figcaption></figure><h4>When to use the two-pointer technique?</h4><ol><li>Sorted Array/Linked Lists</li><li>Palindrome Check</li><li>Merging Two Sorted Arrays/Linked Lists</li><li>Partitioning Problems</li><li>Sliding Window Problems</li><li>Finding the Middle of a Linked List: Finding the middle element in one pass. Use two pointers: one that moves one step at a time (slow pointer) and another that moves two steps at a time (fast pointer). The slow pointer will be in the middle when the fast pointer reaches the end.</li></ol><p>Early termination and reducing redundant operations could lead to an optimal solution during the two-pointer technique.</p><p>The two-pointer technique is robust for various problems, especially involving sorting. You can gain efficiency by moving pointers in opposite directions. The key to using it optimally lies in understanding the problem constraints and ensuring that the pointers are transferred in a way that progressively narrows down the search space.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=64a812f39fc1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to run Jenkins using Docker?]]></title>
            <link>https://blog.devops.dev/how-to-run-jenkins-using-docker-03dce5ae1920?source=rss-3ccbddc05ddf------2</link>
            <guid isPermaLink="false">https://medium.com/p/03dce5ae1920</guid>
            <category><![CDATA[dockerfiles]]></category>
            <category><![CDATA[jenkins]]></category>
            <category><![CDATA[docker-compose]]></category>
            <category><![CDATA[jenkins-pipeline]]></category>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[Mahedi Hasan Jisan]]></dc:creator>
            <pubDate>Sat, 24 Aug 2024 21:19:19 GMT</pubDate>
            <atom:updated>2024-09-04T18:52:16.210Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>This article aims</strong> to run Jenkins using a Docker container, where Jenkins can also run the Docker CLI, that is, Docker in Docker. The primary concepts of Docker and Jenkins are given, along with proper examples of how to run Jenkins using Docker.</p><h3>What is Docker?</h3><p>Docker is an open-source platform that automates application deployment, scaling, and management by packaging an application and its dependencies into a standardized <strong>container unit</strong>. Containers are lightweight, portable, and isolated environments that can run on any system supporting Docker, whether on a developer&#39;s laptop, a testing environment, or a production server in the cloud.</p><h4>Docker Benefits?</h4><ul><li><strong>Portability</strong>: Containers can run consistently across different environments, ensuring that an application behaves the same way in development, testing, and production.</li><li><strong>Efficiency</strong>: Containers share the host system&#39;s kernel and use fewer resources than traditional virtual machines.</li><li><strong>Scalability</strong>: Docker makes scaling applications up or down easier by running multiple containers or services.</li><li><strong>Isolation</strong>: Containers provide process and filesystem isolation, reducing conflicts between applications.</li></ul><p>Some helpful articles on Docker:</p><ol><li><a href="https://medium.com/@mahedihasanjisan/everything-on-docker-37068fdc967c">Everything on Docker! (Part l)</a></li><li><a href="https://medium.com/@mahedihasanjisan/everything-on-docker-part-ll-e982730d41fd">Everything on Docker (Part ll)</a></li><li><a href="https://medium.com/@mahedihasanjisan/everything-on-docker-part-lll-d541b92c656b">Everything on Docker (Part lll)</a></li></ol><h3>What is Jenkins?</h3><p>Jenkins is an open-source automation server widely used for continuous integration (CI) and continuous delivery (CD) in software development. It automates the process of building, testing, and deploying applications, making it easier to integrate changes and efficiently deliver updated applications to users.</p><h4>Critical Concepts of Jenkins?</h4><ol><li><strong>Continuous integration</strong>: Jenkins automatically builds and tests each code change, thus helping developers detect and fix early issues.</li><li><strong>Continuous Delivery</strong>: Jenkins can push the code to production, ensuring the application stays up-to-date.</li><li><strong>Pipeline</strong>: The Jenkins pipeline plugin supports building and deploying complex delivery pipelines. Pipelines can be created in two ways: declarative and scripted. The declarative pipeline is straightforward and defines the entire CI/CD pipeline. Scripted pipelines offer more flexibility and are suitable for complex pipelines. In both cases, knowledge of Groovy scripting is required.</li></ol><h4>Benefits of Jenkins?</h4><ul><li><strong>Automation</strong>: Automates repetitive tasks, reducing manual intervention and human error.</li><li><strong>Scalability</strong>: Supports distributed builds across multiple agents, enabling scalability.</li><li><strong>Flexibility</strong>: Highly customizable through a vast range of plugins and integrations.</li><li><strong>Open Source</strong>: Free to use and backed by a large community, ensuring continuous improvement and support.</li><li><strong>Easy Integration</strong>: Integrates seamlessly with various tools and services used in software development, such as version control systems, build tools, and deployment platforms.</li></ul><p>This article assumes you have your Docker already installed in your system.</p><p>→ Verification of docker installation:</p><pre>&gt; docker run hello-world<br><br>Hello from Docker!<br>This message shows that your installation appears to be working correctly.<br><br>To generate this message, Docker took the following steps:<br> 1. The Docker client contacted the Docker daemon.<br> 2. The Docker daemon pulled the &quot;hello-world&quot; image from the Docker Hub.<br>    (arm64v8)<br> 3. The Docker daemon created a new container from that image which runs the<br>    executable that produces the output you are currently reading.<br> 4. The Docker daemon streamed that output to the Docker client, which sent it<br>    to your terminal.<br><br>To try something more ambitious, you can run an Ubuntu container with:<br> $ docker run -it ubuntu bash<br><br>Share images, automate workflows, and more with a free Docker ID:<br> https://hub.docker.com/<br><br>For more examples and ideas, visit:<br> https://docs.docker.com/get-started/</pre><p>If you run docker run hello-world the terminal will show you the above content, which means you have successfully installed Docker on your system.</p><h3>Goal: Run Jenkins using Docker</h3><p>To achieve that, we need a dockerfile and docker-compose.yml file.</p><h4>Dockerfile</h4><p>A <strong>Dockerfile</strong> is a text file that contains instructions for creating a Docker image. Each instruction tells <strong>Docker how to build your application</strong> or service from the ground up, layer by layer. The Dockerfile allows you to <strong>automate the process of creating Docker images</strong>, making it easy to reproduce and share application environments.</p><p>Let&#39;s Create a Dockerfile to load Jenkins Image:</p><p><strong>Image</strong>: <a href="https://hub.docker.com/r/jenkins/jenkins">https://hub.docker.com/r/jenkins/jenkins</a></p><pre>FROM jenkins/jenkins:lts-jdk17</pre><pre>USER root<br># Install the Docker CLI<br>RUN apt-get update &amp;&amp; \<br>    apt-get install -y \<br>    curl \<br>    apt-transport-https \<br>    ca-certificates &amp;&amp; \<br>    curl -fsSLo /usr/share/keyrings/docker-archive-keyring.asc https://download.docker.com/linux/debian/gpg &amp;&amp; \<br>    echo &quot;deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.asc] https://download.docker.com/linux/debian bullseye stable&quot; &gt; /etc/apt/sources.list.d/docker.list &amp;&amp; \<br>    apt-get update &amp;&amp; \<br>    apt-get install -y docker-ce-cli &amp;&amp; \<br>    rm -rf /var/lib/apt/lists/*<br>USER jenkins</pre><p>Explanation:dockerfile →</p><ol><li><strong>FROM jenkins/jenkins:lts-jdk17</strong>: This is the base image used to create the custom image. The base image is an official Jenkins image that includes the Long-Term Support (LTS) version of Jenkins, bundled with JDK 17.</li><li><strong>USER root</strong>: Granting the superuser permission to ensure the execution of the higher privileged command.</li><li><strong>apt-get update</strong>: This command updates the package index, ensuring that the package lists from the repositories are up-to-date.</li><li><strong>curl</strong>: A tool to transfer data from or to a server. It is used here to download the Docker GPG key.</li><li><strong>apt-transport-https</strong>: Enables APT to use HTTPS to fetch packages, ensuring the security of package downloads.</li><li><strong>ca-certificates</strong>: Provides trusted CA certificates for validating SSL certificates when downloading files over HTTPS.</li><li><strong>curl -fsSLo /usr/share/keyrings/docker-archive-keyring.asc </strong><a href="https://download.docker.com/linux/debian/gpg"><strong>https://download.docker.com/linux/debian/gpg</strong></a>: Download the official GPG key from the docker official repository and store it in this <strong>/usr/share/keyrings </strong>directory. This key is to verify the integrity of packages from the docker repository.</li><li><strong>echo “deb [arch=$(dpkg — print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.asc] </strong><a href="https://download.docker.com/linux/debian"><strong>https://download.docker.com/linux/debian</strong></a><strong> bullseye stable” &gt; /etc/apt/sources.list.d/docker.list</strong>: Adds Docker&#39;s official APT repository to the system&#39;s sources list. This repository is used to install the Docker CLI. The architecture is dynamically determined by dpkg — print-architecture, and the repository is set for the bullseye distribution.</li><li><strong>apt-get update</strong>: Updates the package lists again, now including Docker&#39;s repository, ensuring the Docker CLI package is available for installation.</li><li><strong>apt-get install -y docker-ce-cli</strong>: Installs the Docker CLI, which is the command-line interface for Docker. <strong>This tool allows Jenkins to execute Docker commands (like building and running Docker containers)</strong>.</li><li><strong>rm -rf /var/lib/apt/lists/*</strong>: Cleans up the local repository of retrieved package files to reduce the image size. This command removes the cached files no longer needed after the installation, ensuring the image remains as small as possible.</li><li><strong>USER jenkins</strong>: Switching the user context back to <strong>Jenkins</strong>, the default user for running Jenkins. After installing the necessary packages as <strong>root</strong>, Jenkins should run under its standard user account to follow best practices for <strong>security and permissions</strong>.</li></ol><h4>Docker-Compose</h4><p>A docker-compose.yml file is a configuration file used by Docker Compose, which helps you define and manage <strong>multi-container applications</strong>. This file specifies how the different services that make up your application should be configured and connected. It allows you to define, build, and run multi-container Docker applications with a single command.</p><p>Now, let&#39;s create a docker-compose yml file:</p><pre>version: &#39;3.7&#39;<br><br>services:<br>  jenkins-docker:<br>    image: docker:dind<br>    container_name: jenkins-docker<br>    privileged: true<br>    environment:<br>      - DOCKER_TLS_CERTDIR=/certs<br>    volumes:<br>      - jenkins-docker-certs:/certs/client<br>      - jenkins-data:/var/jenkins_home<br>    ports:<br>      - &quot;2376:2376&quot;<br>    networks:<br>      jenkins:<br>        aliases:<br>          - docker<br>    command: --storage-driver overlay2<br><br>  my-jenkins:<br>    image: my-jenkins<br>    container_name: my-jenkins<br>    restart: on-failure<br>    environment:<br>      - DOCKER_HOST=tcp://docker:2376<br>      - DOCKER_CERT_PATH=/certs/client<br>      - DOCKER_TLS_VERIFY=1<br>    volumes:<br>      - jenkins-data:/var/jenkins_home<br>      - jenkins-docker-certs:/certs/client:ro<br>    ports:<br>      - &quot;8080:8080&quot;<br>      - &quot;50000:50000&quot;<br>    networks:<br>      - jenkins<br><br>networks:<br>  jenkins:<br>    driver: bridge<br><br>volumes:<br>  jenkins-docker-certs:<br>  jenkins-data:</pre><p>Explanation: Docker-Compose →</p><h4>Services:</h4><p>This section defines the different containers (services) that will be running.</p><h4>jenkins-docker</h4><p>This service provides a Docker-in-Docker (DinD) environment. It is responsible for running a Docker daemon inside a Docker container, which enables other containers (like Jenkins) to communicate with Docker and manage Docker images and containers.image: docker:dind: This service uses the <strong>Docker:dind</strong> image, <strong>&quot;Docker in Docker.&quot;</strong> It allows Docker to run within Docker containers, which is necessary for <strong>Jenkins to build Docker images</strong>.</p><ol><li>container_name: jenkins-docker: Container name.</li><li>privileged: true: Grants the container extended privileges required to run Docker in Docker.</li><li>environment: Defines environment variables for the container.<br>DOCKER_TLS_CERTDIR=/certs: Sets up Docker with TLS enabled, storing certificates in the /certs directory.</li><li>volumes: Maps directories between the host and container. <strong>Host-role</strong>: It provides the operating system, hardware resources, and network interfaces that the Docker containers use. <strong>container-role</strong>: Containers run the applications and services defined in Docker images. They use the host&#39;s kernel but have their own filesystem, networking, and process space.</li><li>jenkins-docker-certs:/certs/client: Maps the Docker volume named jenkins-docker-certs to the /certs/client directory inside the jenkins-docker container. This means that the contents of the jenkins-docker-certs host&#39;s volume will be available /certs/client inside the container to store TLS certificates.</li><li>jenkins-data:/var/jenkins_home: Maps the Docker volume named jenkins-data to the /var/jenkins_home directory inside the my-jenkins container. This means that the contents of the jenkins-data host&#39;s volume will be available /var/jenkins_home inside the container.</li><li>ports: Maps ports from the container to the host. “2376:2376”: Exposes Docker&#39;s secure API on port 2376, which Jenkins will use to communicate with Docker.</li><li>networks: Connects the container to the Jenkins network.</li><li>aliases: Defines an alias for the container on the network.</li><li>docker: Aliases the jenkins-docker container as Docker so that other containers can reference it as Docker.</li><li>command: — storage-driver overlay2: Uses the overlay2 storage driver, which is a modern and efficient storage driver for Docker.</li></ol><h4>my-jenkins</h4><p>This is the Jenkins server container. It runs the Jenkins application and manages the continuous integration/continuous deployment (CI/CD) processes.</p><ol><li>my-jenkins: image: my-jenkins: Specifies a custom Jenkins image, my-jenkins. This could be a Jenkins image with pre-installed plugins and configurations.</li><li>container_name: my-jenkins: Names the container my-jenkins.</li><li>restart: on-failure: Configures the container to restart if it fails automatically.</li><li>environment: Sets environment variables for Jenkins.<br>DOCKER_HOST=tcp://docker:2376: Points Jenkins to the Docker daemon running on jenkins-docker via TCP on port 2376.<br>DOCKER_CERT_PATH=/certs/client: Specifies the path to the TLS certificates for secure communication with Docker.<br>DOCKER_TLS_VERIFY=1: Enables TLS verification for secure Docker communication.</li><li>volumes: Maps volumes between the host and container.<br>jenkins-data:/var/jenkins_home: Maps the Jenkins home directory, which is the same as in jenkins-docker, ensuring persistence.<br>jenkins-docker-certs:/certs/client:ro: Maps the jenkins-docker-certs volume to /certs/client as read-only (ro), ensuring Jenkins can access the Docker certificates.</li><li>ports: Maps ports from the container to the host.<br>“8080:8080”: Exposes Jenkins&#39; web interface on port 8080.<br>“50000:50000”: Exposes the port used by Jenkins agents to communicate with the Jenkins master.</li><li>networks: Connects the container to the jenkins network.</li></ol><h4>Networks:</h4><ul><li><strong>jenkins</strong>: Defines a custom network named jenkins using the bridge driver. This allows both services (jenkins-docker and my-jenkins) to communicate with each other on an isolated network.</li></ul><h4>Volumes:</h4><ul><li><strong>jenkins-docker-certs</strong>: A named volume for storing Docker TLS certificates, ensuring they persist across container restarts.</li><li><strong>jenkins-data</strong>: A named volume for storing Jenkins data, ensuring Jenkins configurations, jobs, and plugins persist.</li></ul><h4>Time to create Docker Image:</h4><pre>docker build -t my-jenkins .</pre><p>The command creates a Docker image from a Dockerfile in the current directory. Here&#39;s a detailed explanation of each part of the command:</p><ol><li>docker build: This is the Docker command used to build a Docker image from a Dockerfile.</li><li>-t my-jenkins: The -t option tags the image with a name.</li><li>.: The dot (.) refers to the current directory. Docker will look in this directory for a Dockerfile and any files needed to build the image.</li></ol><pre> &gt; docker build -t my-jenkins .<br>[+] Building 16.7s (7/7) FINISHED                                                                                                                                                              docker:desktop-linux<br> =&gt; [internal] load build definition from Dockerfile                                                                                                                                                           0.0s<br> =&gt; =&gt; transferring dockerfile: 687B                                                                                                                                                                           0.0s<br> =&gt; [internal] load metadata for docker.io/jenkins/jenkins:lts-jdk17                                                                                                                                           0.6s<br> =&gt; [auth] jenkins/jenkins:pull token for registry-1.docker.io                                                                                                                                                 0.0s<br> =&gt; [internal] load .dockerignore                                                                                                                                                                              0.0s<br> =&gt; =&gt; transferring context: 2B                                                                                                                                                                                0.0s<br> =&gt; CACHED [1/2] FROM docker.io/jenkins/jenkins:lts-jdk17@sha256:2bafb1fb2d6489bccadc1b7c172937e9b56a888ed77e625a4ebe59a6b038221e                                                                              0.0s<br> =&gt; [2/2] RUN apt-get update &amp;&amp;     apt-get install -y     curl     apt-transport-https     ca-certificates &amp;&amp;     curl -fsSLo /usr/share/keyrings/docker-archive-keyring.asc https://download.docker.com/li  15.8s<br> =&gt; exporting to image                                                                                                                                                                                         0.3s<br> =&gt; =&gt; exporting layers                                                                                                                                                                                        0.3s<br> =&gt; =&gt; writing image sha256:6082ff2ede1bc15b14e087298a9a48aed0caccff8b035503aabb7ecfda0df476                                                                                                                   0.0s <br> =&gt; =&gt; naming to docker.io/library/my-jenkins                                                                                                                                                                  0.0s <br>                                                                                                                                                                                                                    <br>What&#39;s next:                                                                                                                                                                                                        <br>    View a summary of image vulnerabilities and recommendations → docker scout quickview</pre><p>Now, you can see the my-jenkins image after running this command.</p><h4>Time to run the services:</h4><pre>docker compose up -d</pre><p>The command starts and runs containers defined in a docker-compose.yml File in detached mode. Here&#39;s a detailed explanation of each part of the command:</p><ol><li>docker compose up: This is the base command to start the services defined in a docker-compose.yml file. The up command creates and starts containers based on the configuration in the file.</li></ol><p>2. -d: This stands for &quot;detached mode&quot;. When this option is used, Docker Compose runs the containers in the background and immediately returns control to the terminal.</p><pre>&gt; docker compose up -d<br>WARN[0000] /Users/jisan06/Desktop/pipeline/install-jenkins-docker/docker-compose.yml: the attribute `version` is obsolete, it will be ignored, please remove it to avoid potential confusion <br>[+] Running 17/17<br> ✔ jenkins-docker Pulled                                                                                                                                                                                      18.1s <br>   ✔ 690e87867337 Pull complete                                                                                                                                                                                1.4s <br>   ✔ 729161d0df24 Pull complete                                                                                                                                                                                1.9s <br>   ✔ 4f4fb700ef54 Pull complete                                                                                                                                                                                1.9s <br>   ✔ 38b9491762d2 Pull complete                                                                                                                                                                                1.9s <br>   ✔ a3fdb7ce0e7c Pull complete                                                                                                                                                                                6.6s <br>   ✔ f99813ceebae Pull complete                                                                                                                                                                                7.1s <br>   ✔ 316a30f1c6a0 Pull complete                                                                                                                                                                                9.3s <br>   ✔ 5c0d611bb206 Pull complete                                                                                                                                                                                9.3s <br>   ✔ 5d9b0bb07621 Pull complete                                                                                                                                                                                9.3s <br>   ✔ d75f172f02f3 Pull complete                                                                                                                                                                                9.3s <br>   ✔ be962662e1ee Pull complete                                                                                                                                                                                9.7s <br>   ✔ bcaa410c9938 Pull complete                                                                                                                                                                                9.7s <br>   ✔ aa7c5d6bc99e Pull complete                                                                                                                                                                                9.7s <br>   ✔ 4d14c79f09c6 Pull complete                                                                                                                                                                               17.2s <br>   ✔ 4a0b48cb369a Pull complete                                                                                                                                                                               17.2s <br>   ✔ 759f97cc6693 Pull complete                                                                                                                                                                               17.3s <br>[+] Running 3/3<br> ✔ Network install-jenkins-docker_jenkins  Created                                                                                                                                                             0.0s <br> ✔ Container jenkins-docker                Started                                                                                                                                                             0.3s <br> ✔ Container my-jenkins                    Started      </pre><p>After running the command, we can now see that both services that are established in the docker-compose.yml file is running.</p><p>You can go to your localhost to see if the jenkins can be accessed:</p><pre>http://localhost:8080/</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XRdQGUW5B68u0ZSwtKx3Iw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GIlZVmLmjyx332jYBSJuVA.png" /><figcaption>Photo By: Author</figcaption></figure><p>Before that, there would be some setup process. It will ask you for a password from a location in the container my-jenkins, and when you enter it, you can follow the steps.</p><p>The location for the initial password:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CFZyAa9NjSUbUfiduTjCSw.png" /></figure><p>You can use the following command to stop the Jenkins/containers:</p><pre>&gt; docker compose down<br>WARN[0000] /Users/jisan06/Desktop/pipeline/install-jenkins-docker/docker-compose.yml: the attribute `version` is obsolete, it will be ignored, please remove it to avoid potential confusion <br>[+] Running 3/3<br> ✔ Container jenkins-docker                Removed                                                                                                                                                             1.1s <br> ✔ Container my-jenkins                    Removed                                                                                                                                                             0.2s <br> ✔ Network install-jenkins-docker_jenkins  Removed  </pre><p>Overall, You can install Jenkins using Docker and play around with it. This is the cleanest way because it doesn&#39;t t affect your system directly. And to remove jenkins, volumes and images, run the following command:</p><pre>docker compose down --volumes --rmi all</pre><p>Hopefully, this article is useful for you to learn about Docker, jenkins and how to run jenkins using Docker. Thanks for the read. 🙌</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=03dce5ae1920" width="1" height="1" alt=""><hr><p><a href="https://blog.devops.dev/how-to-run-jenkins-using-docker-03dce5ae1920">How to run Jenkins using Docker?</a> was originally published in <a href="https://blog.devops.dev/">DevOps.dev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Competitive Programming #1: Sliding Window Technique]]></title>
            <link>https://mahedihasanjisan.medium.com/competitive-programming-1-sliding-window-technique-ff790f571ea2?source=rss-3ccbddc05ddf------2</link>
            <guid isPermaLink="false">https://medium.com/p/ff790f571ea2</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[data-structures]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[sliding-window-algorithm]]></category>
            <dc:creator><![CDATA[Mahedi Hasan Jisan]]></dc:creator>
            <pubDate>Fri, 23 Aug 2024 21:21:42 GMT</pubDate>
            <atom:updated>2024-09-08T21:20:20.386Z</atom:updated>
            <content:encoded><![CDATA[<p>An algorithm technique for efficiently solving a problem for arrays and lists. The goal is to iterate through or slide the data structure from one end to another, maintaining the sliding window. Using this technique, you can solve problems such as finding the maximum sum and longest substring, etc., within that window.</p><p>Let’s consider an example where an array has a size of six and contains some values. For now, we will check how the sliding window works.</p><p>sliding window = 3</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dr8zMGoMQGbQ5LHJI6Vxdw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FfXZsEsPTTrqb-AZxP2F4Q.png" /><figcaption>Photo By: Author</figcaption></figure><p>Sliding window techniques start from index 0 (left) to index 5 (right). Iteration starts from index 0 and stops at index three because the given sliding window is three, and this sliding window needs to be maintained constantly.</p><p>That said, we can’t do sliding at index four because (index + sliding window) is more than the array size.</p><p>There are two types of sliding windows:</p><ol><li><strong>Fixed window</strong>: The sliding window size is permanently fixed or constant.</li><li><strong>Variable window</strong>: The sliding window size can increase or decrease based on some conditions.</li></ol><p>Let’s look at a problem and find a solution:</p><blockquote><strong>Problem</strong>: Find the maximum sum of k consecutive elements in an array.</blockquote><pre>&#39;&#39;&#39;<br>Find the maximum sum of k consecutive elements in an array.<br>&#39;&#39;&#39;<br><br><br>def max_sum_subarray(nums, sliding_window):<br>    # init<br>    max_sum = -1<br><br>    # sliding window from left to right<br>    for i in range(len(nums) - sliding_window + 1):<br>        value = sum(nums[i: i + sliding_window])<br>        if value &gt; max_sum:<br>            max_sum = value<br>    return max_sum<br><br><br>arr = [2, 3, 5, 8, 9, 10]<br>sliding_window = 3<br>print(&quot;maximum sum of k consecutive elements in an array is: &quot;,<br>      max_sum_subarray(arr, sliding_window))</pre><p>As described in the above section, the solution to this problem follows the same trend: we iterate from left to right with the sliding window to find the maximum sum of k consecutive elements.</p><p>Now, let’s look at an optimized version of the code:</p><pre>&#39;&#39;&#39;<br>Find the maximum sum of k consecutive elements in an array.<br>&#39;&#39;&#39;<br><br><br>def max_sum_subarray(nums, sliding_window):<br>    # find the initial sum of the sliding window<br>    value = sum(nums[:sliding_window])<br>    max_sum = value<br><br>    # sliding window from left to right<br>    for i in range(1, len(nums) - sliding_window + 1):<br>        value = value - nums[i-1] + nums[i+sliding_window-1]<br>        max_sum = max(value, max_sum)<br>    return max_sum<br><br><br>arr = [2, 3, 5, 8, 9, 10]<br>sliding_window = 3<br>print(&quot;maximum sum of k consecutive elements in an array is: &quot;,<br>      max_sum_subarray(arr, sliding_window))</pre><p>This optimization code only sums once for the sliding window, substructing the element left behind and adding the new element that enters the sliding window. Pretty simple.</p><blockquote><strong>Time Complexity:</strong> O(n). The complexity is linear since each element is added and subtracted only once.</blockquote><p><strong>Further Optimization</strong>: In some cases, additional optimizations can be applied by dynamically adjusting the sliding window size or combining the sliding window with other techniques, such as <strong>binary search</strong> or <strong>dynamic programming</strong>.</p><p>Let’s solve a complicated problem from Leetcode using the sliding window technique:</p><p>Problem: <a href="https://leetcode.com/problems/substring-with-concatenation-of-all-words/description/">https://leetcode.com/problems/substring-with-concatenation-of-all-words/description/</a></p><pre>You are given a string s and an array of strings words. All the strings of words are of the same length.<br><br>A concatenated string is a string that exactly contains all the strings of any permutation of words concatenated.<br><br>For example, if words = [&quot;ab&quot;,&quot;cd&quot;,&quot;ef&quot;], then &quot;abcdef&quot;, &quot;abefcd&quot;, &quot;cdabef&quot;, &quot;cdefab&quot;, &quot;efabcd&quot;, and &quot;efcdab&quot; are all concatenated strings. &quot;acdbef&quot; is not a concatenated string because it is not the concatenation of any permutation of words.<br>Return an array of the starting indices of all the concatenated substrings in s. You can return the answer in any order.<br><br> <br><br>Example 1:<br><br>Input: s = &quot;barfoothefoobarman&quot;, words = [&quot;foo&quot;,&quot;bar&quot;]<br><br>Output: [0,9]<br><br>Explanation:<br><br>The substring starting at 0 is &quot;barfoo&quot;. It is the concatenation of [&quot;bar&quot;,&quot;foo&quot;] which is a permutation of words.<br>The substring starting at 9 is &quot;foobar&quot;. It is the concatenation of [&quot;foo&quot;,&quot;bar&quot;] which is a permutation of words.</pre><p>One way to solve this is to get the permutations of the list of words, then check if permutation exists in the string “s”; if it does, then get the starting index number and append it to a list.</p><pre>&#39;&#39;&#39;<br>https://leetcode.com/problems/substring-with-concatenation-of-all-words/description/<br>&#39;&#39;&#39;<br><br><br>def permute_list(words):<br>    # Base case<br>    if len(words) == 1:<br>        return [words]<br>    # store the permutations of strings inside the list<br>    permutations = []<br><br>    for i in range(len(words)):<br>        current = words[i]<br>        remaining = words[:i] + words[i+1:]<br>        # recursively permute the remaining words<br>        for j in permute_list(remaining):<br>            permutations.append([current] + j)<br>    return permutations<br><br><br>def findSubstring(s, words):<br>    permutations = permute_list(words)<br>    # conver the permutations into list of strings<br>    permutation_strings = [&#39;&#39;.join(p) for p in permutations]<br><br>    # result strting index<br>    result = []<br>    for p in permutation_strings:<br>        if p in s:<br>            index = s.find(p)<br>            result.append(index)<br><br>    return result<br><br><br>print(findSubstring(&quot;barfoothefoobarman&quot;, [&quot;foo&quot;, &quot;bar&quot;]))</pre><blockquote><strong>Time Complexity</strong>: O(n×n!+n!×m×k)<br><strong>Space Complexity</strong>: O(n!×(n+k))</blockquote><p>This brute-force approach could be more inefficient for significant inputs. Now, set that aside and focus on the sliding window technique. That’s our goal, after all.</p><pre>&#39;&#39;&#39;<br>https://leetcode.com/problems/substring-with-concatenation-of-all-words/description/<br>&#39;&#39;&#39;<br>from collections import defaultdict<br><br><br>def findSubstring(s, words):<br>    # base case<br>    if not s and not words:<br>        return []<br><br>    # tracking the words<br>    word_count = defaultdict(int)<br>    for i in words:<br>        word_count[i] += 1<br><br>    # sliding window, word length, word count, &amp; results<br>    sliding_window = len(words) * len(words[0])<br>    word_length = len(words[0])<br>    result = []<br><br>    # initial sliding iteration of the string<br>    for i in range(len(s) - sliding_window + 1):<br>        exists = defaultdict(int)<br>        j = i<br>        check = 0<br>        while j &lt; i + sliding_window:<br>            word = s[j:j + word_length]<br>            if word in word_count:<br>                exists[word] += 1<br>                if exists[word] &gt; word_count[word]:<br>                    check = -1<br>                    break<br>            else:<br>                check = -1<br>                break<br>            j += word_length<br>        if check == 0:<br>            result.append(i)<br>    return result<br><br>print(findSubstring(&quot;barfoothefoobarman&quot;, [&quot;foo&quot;, &quot;bar&quot;]))</pre><p>Considering you have already gone through the problem description, the solution is to utilize the sliding window technique and iterate the string from left to right until it’s valid. A Python library keeps track of word occurrences in the string “s” based on the requirements. Each index has another loop to iterate substrings utilizing word length to make the process faster.</p><blockquote><strong>Time Complexity</strong>: O(n * m), where n is the length of the string s and m is the number of words in the words list.<br><strong>Space Complexity</strong>: O(k), where k is the number of unique words in the words list.</blockquote><h4>Template:</h4><pre>def sliding_window_example(arr, target):<br>    i = 0<br>    current_sum = 0<br>    for j in range(len(arr)):<br>        current_sum += arr[j]<br>        <br>        # Shrink the window as long as the current sum exceeds the target<br>        while current_sum &gt; target:<br>            current_sum -= arr[i]<br>            i += 1<br><br>        # Now you can process or check the current window<br>        print(&quot;Current window:&quot;, arr[i:j+1])</pre><blockquote>The <strong>size of</strong> the sliding window is dynamically adjusted based on conditions. Both pointers (i and j) move independently as you expand and shrink the window.</blockquote><p>The sliding window technique is helpful for data structure problems, especially when working with lists and linked lists. Hopefully, this article will help you with the concept of the sliding window technique. Thanks for the read.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ff790f571ea2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to connect to a remote server using SSH Key?]]></title>
            <link>https://mahedihasanjisan.medium.com/how-to-connect-to-a-remote-server-using-ssh-key-f51bf5a0f05d?source=rss-3ccbddc05ddf------2</link>
            <guid isPermaLink="false">https://medium.com/p/f51bf5a0f05d</guid>
            <category><![CDATA[ssh]]></category>
            <category><![CDATA[ssh-keys]]></category>
            <category><![CDATA[authentication]]></category>
            <dc:creator><![CDATA[Mahedi Hasan Jisan]]></dc:creator>
            <pubDate>Mon, 19 Aug 2024 18:21:40 GMT</pubDate>
            <atom:updated>2024-08-19T18:25:19.587Z</atom:updated>
            <content:encoded><![CDATA[<h4>Linux, macOS</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*r9tPzN7SqBB6VU-5.png" /><figcaption>Photo By: <a href="https://www.keycdn.com/support/create-ssh-key">Keycdn</a></figcaption></figure><p>We often need to remember to use an SSH key to connect to a remote server. We don&#39;t want to always use credential-based authentication while doing development work. Here&#39;s a quick guide on how to set up an SSH key on your local host and remote server so that the authentication is smooth and hassle-free.</p><p>This post is targeted at Linux and Mac OS users. Therefore, the instructions are command-based.</p><p><strong><em>Step #1:</em></strong> Check if your ssh folder exists on your system:</p><pre>cat ~/.ssh</pre><p>This command will inform you if you have an existing SSH key in your system. Now, let&#39;s consider that there is no SSH key or .ssh folder in your home directory.</p><p><strong><em>Step #2:</em></strong> Let&#39;s create an SSH key using the ssh-keygen command:</p><pre>ssh-keygen -t ed25519 -C &quot;email address&quot;<br>ssh-keygen -t rsa -b 4096 -C &quot;email address&quot;</pre><p>In the above commands, &lt;-t&gt; is to set the encryption, and &lt;-C&gt; is the associated email address for the key. Feel free to choose one of the above commands to create the keys.</p><pre>&gt;&gt; Generating public/private ALGORITHM key pair.</pre><p>While invoking the above command, you will be prompted with some questionnaires. Just hit enter to complete the step.</p><pre>user@MacBook-Pro ~ % cd ~/.ssh <br>user@MacBook-Pro .ssh % ls<br>id_ed25519 id_ed25519.pub </pre><p><strong><em>Step #3:</em></strong> We need to create an SSH config file so the host can point to the private key and complete the authentication when connecting to a remote server.</p><pre>user@MacBook-Pro ~ % touch ~/.ssh/config<br>user@MacBook-Pro ~ % vim ~/.ssh/config</pre><p>After creating the config file, put the following content using &lt;vim&gt; or another package you prefer.</p><pre>HOST *<br>  AddKeysToAgent yes<br>  IdentityFile ~/.ssh/id_ed25519</pre><p><strong><em>Step #4:</em></strong> Finally, <a href="https://superuser.com/questions/360686/what-exactly-does-ssh-add-do">ssh-add</a> add private key identities (from your ~/.ssh directory) to the authentication agent (ssh-agent), so that the ssh-agent can take care of the authentication for you, and you don’t have to type in passwords at the terminal.</p><pre>ssh-add ~/.ssh/id_ed25519</pre><p>After completing the above steps, you can copy the public key&#39;s content and add it to a remote host, such as GitHub.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*38qrECZ0bg46LaCVR0bXrg.png" /></figure><p>Or, in a remote server, add the public key to this file:</p><pre>~/.ssh/authorized_keys</pre><p>The setup is complete. Now, what the above system will do is that the host machine will recognize the public in the remote server. Also, the host machine knows the associated private key to verify the authentication.</p><p>Hopefully, this article will help you to avoid the authentication struggle during development. Cheers. 🙌</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f51bf5a0f05d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deploy Docker Containers to Azure App Services!]]></title>
            <link>https://mahedihasanjisan.medium.com/deploy-docker-containers-to-azure-app-services-f4ac96ae7531?source=rss-3ccbddc05ddf------2</link>
            <guid isPermaLink="false">https://medium.com/p/f4ac96ae7531</guid>
            <category><![CDATA[flask]]></category>
            <category><![CDATA[nltk]]></category>
            <category><![CDATA[microsoft-azure]]></category>
            <category><![CDATA[azure]]></category>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[Mahedi Hasan Jisan]]></dc:creator>
            <pubDate>Wed, 17 Nov 2021 17:53:29 GMT</pubDate>
            <atom:updated>2021-11-17T17:53:29.170Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*oRC3-JllhQKTjCQ0B44QEg.png" /></figure><p>This article would be pretty short because we will only focus on how to deploy docker images to Azure Container Registry resources and run it there.</p><p>If you have something on your own, that is completely okay. But if you want to check my example, then you can use the following GitHub repo:</p><p><a href="https://github.com/Krypton3/jPy/tree/main/sentiment-analysis">jPy/sentiment-analysis at main · Krypton3/jPy</a></p><p>Let’s look into the code and verify it in the local machine:</p><p><strong>→ App.py:</strong></p><pre>from flask import Flask<br>import nltk<br>nltk.download(&#39;punkt&#39;)<br>nltk.download(&#39;averaged_perceptron_tagger&#39;)</pre><pre>app = Flask(__name__)</pre><pre>@app.route(&#39;/&lt;string:line&gt;&#39;)<br>def main(line: str):<br>  tokens  = nltk.word_tokenize(line)<br>  return {<br>    &#39;POS-Tagging&#39;: nltk.pos_tag(tokens)<br>  }</pre><pre>if __name__ == &#39;__main__&#39;:<br>  app.run(host=&#39;0.0.0.0&#39;, port=80)</pre><p>It’s a simple flask app. <a href="https://www.nltk.org/">We have used NLTK to word tokenize a sentence and return the results of poss-tagging.</a></p><p><strong>→ Dockerfile:</strong></p><pre># base image<br>FROM ubuntu:18.04</pre><pre># setting the directory in the container<br>COPY . /usr/src/app<br>WORKDIR /usr/src/app</pre><pre># Installing update and upgrade along with python<br>RUN apt-get update<br>RUN apt-get upgrade -y<br>RUN apt-get install -y python3<br>RUN apt-get install -y python3-pip</pre><pre># Installing the other dependencies<br>RUN pip3 install -r requirements.txt</pre><pre># Exposing the port<br>EXPOSE 80</pre><pre># The startup command<br>CMD [ &quot;python3&quot;, &quot;/usr/src/app/app.py&quot; ]</pre><p>In this example, <strong>we have created our own image. </strong>We took <strong>ubuntu</strong> as our base image. Then, we installed everything that is needed to run our app:<strong> python, pip, requirements.txt! </strong>We exposed the app on <strong>port 80! And specified the startup command of the container.</strong></p><p><strong>→ Fire it up:</strong></p><pre>docker build -t <strong>jisan.azurecr.io/flask-docker-demo:latest<br>docker run -d -p 80:80 jisan.azurecr.io/flask-docker-demo:latest</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/570/1*hZPZumTQ8LNvIVp-7JqX_A.png" /><figcaption>localhost:80</figcaption></figure><p><strong>→ Microsoft Azure:</strong></p><p>Create an account: <a href="https://portal.azure.com/#hom">https://portal.azure.com/#hom</a>e</p><ul><li>Step 1: <strong>Create resource → containers → Create a new container registry! (Basic)</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ClxNDQfq3HaJEe6Wi8Cmgw.png" /><figcaption>After initial setup!</figcaption></figure><ul><li>Download the repository and create the image using docker-compose. To build the image, tag it with your <strong>azure login server name</strong>.</li></ul><p>Example: “<strong>docker run -d -p 80:80 jisan.azurecr.io/flask-docker-demo:latest</strong>”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*a1oXQ3by5_va_j1f5hCmdg.png" /></figure><ul><li>Install Azure CLI</li></ul><blockquote>curl -sL <a href="https://aka.ms/InstallAzureCLIDeb">https://aka.ms/InstallAzureCLIDeb</a> | sudo bash</blockquote><p>→ Check Version: <strong>az — version</strong></p><ul><li>Login to <strong>Azure Registry</strong>:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3WtvtJCHDAkxbR7-f4kpew.png" /></figure><ul><li>Push the image to the <strong>Azure container registry</strong>:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0wKaC2dIS5yVcW-R-viIBw.png" /></figure><ul><li>Find the image in the repositories section:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZQfraEnTn_eEm9Vwzcf4wA.png" /></figure><ul><li><strong>Registry admin enable:</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4Dmd5ZXvW9G1sFx-HqfyqQ.png" /></figure><ul><li>Now, we are going to create a <strong>container instance: (specify the port you set in your application)</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/986/1*dQdK-rbKjEhK2ZKIYx7J0w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/879/1*r0pxnYBXON_u-tX3cc7T7g.png" /></figure><ul><li>Let’s see it in the <strong>live view</strong>:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/866/1*QQ9O81IKfjU7sQ-_rvjUmQ.png" /><figcaption>&lt;IP&gt;/&lt;string&gt;</figcaption></figure><p>Simple and Effective! That’s it for today! Cheers! 🙌</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f4ac96ae7531" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Multi-Container Docker with Flask, Redis & Celery]]></title>
            <link>https://mahedihasanjisan.medium.com/multi-container-docker-with-flask-redis-celery-678c2f2c4dfa?source=rss-3ccbddc05ddf------2</link>
            <guid isPermaLink="false">https://medium.com/p/678c2f2c4dfa</guid>
            <category><![CDATA[flask]]></category>
            <category><![CDATA[celery]]></category>
            <category><![CDATA[docker-compose]]></category>
            <category><![CDATA[redis]]></category>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[Mahedi Hasan Jisan]]></dc:creator>
            <pubDate>Fri, 12 Nov 2021 02:35:46 GMT</pubDate>
            <atom:updated>2021-11-12T02:35:46.805Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*eLrkU6ij0k2RvbE5iYvSzA.jpeg" /><figcaption><a href="https://nickjanetakis.com/blog/dockerize-a-flask-celery-and-redis-application-with-docker-compose">Ref</a></figcaption></figure><p><strong>→ What is Flask?</strong></p><p>Flask is a micro web framework that can be used to build a web application. Flask is providing every tool and library to build the application. To my understanding, the flask can be very useful for API-based applications or multiple microservices-based products. Some big company such as Netflix, Uber is using flask to develop their products.</p><p><strong>How to create a virtual environment? </strong>→ <a href="https://mahedihasanjisan.medium.com/django-in-virtual-environment-python-54b91ca0f0e9">https://mahedihasanjisan.medium.com/django-in-virtual-environment-python-54b91ca0f0e9</a></p><blockquote>What is actually “app = Flask(__name__)”?</blockquote><blockquote>“<a href="https://stackoverflow.com/questions/39393926/flaskapplication-versus-flask-name">__name__</a> is just a convenient way to get the import name of the place the app is defined. Flask uses the import name to know where to look up resources, templates, static files, instance folders, etc. When using a package, if you define your app in __init__.py then the __name__ will still point at the &quot;correct&quot; place relative to where the resources are. However, if you define it elsewhere, such as mypackage/app.py, then using __name__ would tell Flask to look for resources relative to mypackage.app instead of mypackage.”</blockquote><p><strong>→ What is Celery?</strong></p><blockquote><strong>“Celery</strong> is a task queue implementation for <strong>Python</strong> web applications used to asynchronously execute work outside the HTTP request-response cycle. Task queues are used as a mechanism to distribute work across threads or machines. A task queue’s input is a unit of work called a task. Dedicated worker processes constantly monitor task queues for new work to perform.”</blockquote><p>Overall, if you want to process something behind the scene in your application, then celery could come in handy. An example would be: Uploading large-size files to your application! <a href="https://docs.celeryproject.org/en/stable/getting-started/introduction.html"><strong>More Details.</strong></a></p><p>The first container will be based on a Flask Application, which can be found here:</p><p><a href="https://github.com/Krypton3/jPy/tree/main/flask-celery-redis-docker/app">jPy/flask-celery-redis-docker/app at main · Krypton3/jPy</a></p><p>Our main focus would be Dockerfile.</p><p><strong>Dockerfile:</strong></p><pre># Base Image<br>FROM python:3.9-alpine</pre><pre># Settind celere broker which is redis (default config)<br>ENV CELERY_BROKER_URL redis://redis:6379/0<br>ENV CELERY_RESULT_BACKEND redis://redis:6379/0<br>ENV C_FORCE_ROOT true<br>ENV HOST 0.0.0.0<br>ENV PORT 5000<br>ENV DEBUG true</pre><pre># Copying everything to the container folder <br>COPY . /app<br>WORKDIR /app</pre><pre># Installing all the dependencies in the container <br>RUN pip install -U setuptools pip<br>RUN pip install -r requirements.txt</pre><pre># Exposing the app by port: 5000<br>EXPOSE 5000</pre><pre>RUN pip install gunicorn</pre><pre># Startup command for this app<br>CMD [&quot;gunicorn&quot;, &quot;--bind&quot;, &quot;0.0.0.0:5000&quot;, &quot;--workers&quot;, &quot;3&quot;, &quot;app:app&quot;]</pre><p>→Why Celery needs Redis?</p><blockquote>“Celery communicates via messages, usually using a broker to mediate between clients and workers. To initiate a task the client adds a message to the queue, the broker then delivers that message to a worker. Redis is <strong>used to store messages produced by the application code describing the work to be done in the Celery task queue</strong>. Redis also serves as storage of results coming off the celery queues which are then retrieved by consumers of the queue.”</blockquote><p><strong>→ What is gunicorn?</strong></p><blockquote><strong>“Gunicorn</strong> is a WSGI server · communicating with multiple web servers · reacting to lots of web requests at once and distributing the load · keeping multiple processes of the web application running.”</blockquote><p>The second container will be based on the celery queue. The code is given here:</p><p><a href="https://github.com/Krypton3/jPy/tree/main/flask-celery-redis-docker/celery-queue">jPy/flask-celery-redis-docker/celery-queue at main · Krypton3/jPy</a></p><p><strong>Dockerfile:</strong></p><pre># Base Image<br>FROM python:3.9-alpine</pre><pre># Setting the broker for celery<br>ENV CELERY_BROKER_URL redis://redis:6379/0<br>ENV CELERY_RESULT_BACKEND redis://redis:6379/0<br>ENV C_FORCE_ROOT true</pre><pre># Moving every files to the container<br>COPY . /queue<br>WORKDIR /queue</pre><pre># Installing the dependencies<br>RUN pip install -U setuptools pip<br>RUN pip install -r requirements.txt</pre><p>Pretty straightforward, right? Well, let’s look into the docker-compose file to handle the multiple containers together. The code can be found here:</p><p><a href="https://github.com/Krypton3/jPy/blob/main/flask-celery-redis-docker/docker-compose.yml">jPy/docker-compose.yml at main · Krypton3/jPy</a></p><p><strong>Docker-compose.yml:</strong></p><pre>version: &quot;3.7&quot;</pre><pre>services:<br> web:<br>  build: context: ./app<br>  dockerfile: Dockerfile<br>  restart: always<br>  ports:<br>   - &quot;5000:5000&quot;<br>  depends_on:<br>   - redis<br>  volumes: [&#39;./app:/app&#39;]</pre><pre> worker:<br>  build: context: ./celery-queue<br>  dockerfile: Dockerfile<br>  command: celery -A tasks worker -l info -E<br>  environment: <br>   CELERY_BROKER_URL: redis://redis<br>   CELERY_RESULT_BACKEND: redis://redis<br>  depends_on:<br>   - redis<br>  volumes: [&#39;./celery-queue:/queue&#39;]</pre><pre>monitor:<br> build: context: ./celery-queue<br> dockerfile: Dockerfile<br> ports: <br>  - &quot;5555:5555<br> command:  [&#39;celery&#39;, &#39;-A&#39;, &#39;tasks&#39;, &#39;worker&#39;]<br> environment:<br>  CELERY_BROKER_URL: redis://redis:6379/0<br>  CELERY_RESULT_BACKEND: redis://redis:6379/0<br> depends_on:<br>  - redis <br>  - worker<br> volumes: [&#39;./celery-queue:/queue&#39;]</pre><pre> redis:<br>  image: redis:alpine<br>  ports:<br>   - &quot;6379:6379&quot;</pre><p>Let’s explain the <strong>docker-compose file</strong>. Basically, we have two containers which are <strong>web and worker</strong>. “monitor” is used to monitor the celery queue task by an entity called “worker”.</p><ul><li>We have loaded the redis image from the docker hub as we need that to use celery. <strong>By default, redis is using port 6379. ports: 6379 (host) : 6379 (container).</strong></li><li>In the web container, the build context is referring to the container file location, which is <strong>“./app”</strong>. We have also mentioned the dockerfile but it is optional as docker-compose is powerful enough to figure that by itself as long as the dockerfile is in the <strong>root folder (build →context)</strong>. Ports are set to <strong>5000 (host): 5000 (container)</strong>. This container will depend on redis because this app is using celery which needs redis as the <strong>msg broker</strong>.</li><li>Volumes: “In order to be able to save (persist) data and also to share data between containers, Docker came up with the concept of volumes. Quite simply, volumes are <strong>directories (or files) that are outside of the default Union File System and exist as normal directories and files on the host filesystem</strong>.”</li><li>The worker container is for the celery. Same concept for <strong>“build → context”</strong>. The <strong>“command” </strong>will invoke the command to start the celery worker to do an asynchronous task. Then, the celery broker is set up by the <strong>environment </strong>unit. Celery obviously depends on redis. The worker container will set up the celery.</li><li><strong>Monitor</strong> container is used to monitor the celery worker to validate if it’s working properly. The configuration is basically the same as the <strong>worker</strong> container.</li></ul><p>Download the whole application from here:</p><p><a href="https://github.com/Krypton3/jPy/tree/main/flask-celery-redis-docker">jPy/flask-celery-redis-docker at main · Krypton3/jPy</a></p><p>Start the app:</p><p>→ <strong>docker-compose -f docker-compose.yml up — build</strong></p><p>This command will start the whole application. To validate: <strong>docker ps -a</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HlKgIoNDqGe4UdqZvEZpXQ.png" /></figure><p>Tips: <strong>docker exec -it &lt;container-id&gt; /bin/bash</strong></p><p>Supporting Material:</p><ul><li><a href="https://mahedihasanjisan.medium.com/everything-on-docker-37068fdc967c">Everything on Docker! (Part l)</a></li><li><a href="https://mahedihasanjisan.medium.com/everything-on-docker-part-ll-e982730d41fd">Everything on Docker (Part ll)</a></li><li><a href="https://mahedihasanjisan.medium.com/everything-on-docker-part-lll-d541b92c656b">Everything on Docker (Part lll)</a></li></ul><p>Debug the project and do the rest! 🙌 That’s it for today! Cheers! 😃</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=678c2f2c4dfa" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>