<?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[Code In Christ - Medium]]></title>
        <description><![CDATA[Before I’m an engineer (or anything else really), I’m a Christian. As Christians, we’re called to glorify God in all we do, including work. ‘Code In Christ’ is all about using software engineering principles, as analogies, to explain and share the gospel of Christ Jesus - Medium]]></description>
        <link>https://medium.com/code-in-christ?source=rss----409190cc0838---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Code In Christ - Medium</title>
            <link>https://medium.com/code-in-christ?source=rss----409190cc0838---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 27 Nov 2026 13:17:38 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/code-in-christ" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[The Two-Pointer Pattern, And Pointing to Christ]]></title>
            <link>https://medium.com/code-in-christ/the-two-pointer-pattern-and-pointing-to-christ-1bc5bccd9b9e?source=rss----409190cc0838---4</link>
            <guid isPermaLink="false">https://medium.com/p/1bc5bccd9b9e</guid>
            <category><![CDATA[gospel-of-jesus-christ]]></category>
            <category><![CDATA[coding-patterns]]></category>
            <category><![CDATA[two-pointer-pattern]]></category>
            <dc:creator><![CDATA[Muraya Elijah]]></dc:creator>
            <pubDate>Mon, 25 Nov 2024 21:41:43 GMT</pubDate>
            <atom:updated>2024-11-26T05:26:17.222Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>The Concept</strong></h3><p>The two-pointer pattern refers to the idea of using two-pointers to efficiently traverse a linear data structure (e.g. arrays) to solve a given problem. The two-pointers typically start at different points (e.g. the beginning and end of a list) and move across the data structure in opposite directions, given that a specific condition is met.</p><h4>Problems that the pattern solves</h4><p>A coding problem can be solved using this pattern if it:</p><ul><li>Requires finding a pair of elements that satisfy a given condition e.g. finding two elements in an array whose sum equates to a given value</li><li>Involves a reversal of elements e.g. reversing an array</li><li>Requires you to process two elements at a time in a given data set e.g. palindrome check</li></ul><h4>Pre-requisites to using the pattern</h4><p>To use this pattern, the following checks need to be met:</p><ul><li>The elements in the data structure need to be sorted. This helps improve time complexities, but does not apply to all problems</li><li>Two elements should be processed at the same time in a data set e.g. comparing values in an array</li></ul><h3><strong>The Code</strong></h3><p>We can leverage this pattern, for example, to check whether a word is a palindrome.</p><p>We’re techies, not literature majors, so let me educate you on what a palindrome is 😄. A palindrome is a word that is spelled the same forward and backward e.g. Abba, Eve, Anna.</p><h4>The Problem</h4><blockquote>Given a string word, return true if it is a palindrome, and false if it is not.</blockquote><h4>Explanation</h4><ul><li>We’ll first initialise the first pointer at the beginning of the string, and the other pointer at the end of the string</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/420/1*V39pkFKDvgjKTfsDQYJfAw.png" /></figure><ul><li>Next, we’ll check if the two values match.</li></ul><p>If they match, we’ll move the start pointer to the right, and the last pointer to the left, one time each. If they do not match, we return false and terminate the flow</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/420/1*iFp_Pt00t4QyI0Zp9nKTlQ.png" /></figure><ul><li>If the pointers meet, and the character is the same, the algorithm returns true</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/420/1*meWSfJuqUS7xxMIIkUPRnw.png" /></figure><h4>Solution</h4><p>Below is the complete code solution in Java</p><pre>import java.util.*;<br><br>public class Main{<br>    public static boolean isPalindrome(String word) {<br>    // We initialize the twon pointers as the start and end index<br>      int startIndex = 0;<br>      int endIndex = word.length() - 1;<br>      boolean result = true;<br>      <br>      // This loop returns true, as long as the two pointers have not met<br>      while (startIndex &lt; endIndex) {<br>       // Check if the elements at the twon points match<br>        if( word.charAt(startIndex) != word.charAt(endIndex) ) {<br>          return false;<br>        }<br>        // Move startIndex one step to the right, and endIndex to the left<br>        startIndex++;<br>        endIndex--;<br>      }<br>        return result;<br>    }<br>}</pre><h3>The Christ Connection</h3><blockquote><strong><em>Ephesians 2:4–5</em></strong> [4] But God, being rich in mercy, because of the great love with which he loved us, [5] even when we were dead in our trespasses, made us alive together with Christ — by grace you have been saved — (ESV)</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hXf_oXMbnwHns31Z_88nuw.png" /><figcaption>Man separated from God because of Sin</figcaption></figure><p>Think of your relationship with God as two elements in an array. You’re on the first index of the array, and God is on the last index of the array. You need to be reconciled with God. Why do we need to be reconciled with God? Because we’ve all sinned and fallen short of His Glory(Romans 3:23). For some, the natural assumption is that we move a step closer to God, and He moves a step closer to us.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L4T37xDALEKUkssDVJjzkg.png" /><figcaption>Man is dead to Sin, and can’t do anything to be reconciled to God</figcaption></figure><p>There’s only one problem, you can not move a step closer to God in the array, because <strong><em>you are dead in your trespasses</em></strong><em>. </em>Dead men do not move. The verse Ephesians 2:4–5<strong><em> </em></strong>teaches us that, we by ourselves, can not reconcile ourselves to God, because we’re inherently ‘dead’ in sin. Outside of Christ, our desire is for sin and sin only. We do not have the ability to desire God, let alone draw near to Him. It’s not just a matter of won’t, it’s also a matter of can’t.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Vzq_78NPJzNPMjeAkoiQjQ.png" /><figcaption>Christ died for our sins, so that we can be made alive in Him, and reconciled to God</figcaption></figure><p><strong>But God, rich in mercy, loved us even when dead in our trespasses,</strong> that He sent His Son Jesus Christ, to pay the penalty of sin, so that we can be reconciled to God. Once we put our trust in Jesus, as our redeemer from sin, God now moves from the very end of the list to the first index of the list, where we are, and makes us alive in Christ.</p><blockquote><strong>Romans 5:8</strong> But God shows His love for us in that while we were still sinners, Christ died for us.</blockquote><p><strong>This is the wonderful news of the Gospel! 🙏🏽</strong></p><p><em>To be notified whenever we do a new publication, consider subscribing </em><a href="https://medium.com/@elimuraya.dev/subscribe"><em>here</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1bc5bccd9b9e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/code-in-christ/the-two-pointer-pattern-and-pointing-to-christ-1bc5bccd9b9e">The Two-Pointer Pattern, And Pointing to Christ</a> was originally published in <a href="https://medium.com/code-in-christ">Code In Christ</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>