<?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 Serra Saracoglu on Medium]]></title>
        <description><![CDATA[Stories by Serra Saracoglu on Medium]]></description>
        <link>https://medium.com/@serrasaracoglu?source=rss-5abf90748079------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*_uKTWUDfFb7T-4PbHdM8FA.jpeg</url>
            <title>Stories by Serra Saracoglu on Medium</title>
            <link>https://medium.com/@serrasaracoglu?source=rss-5abf90748079------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 07:58:57 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@serrasaracoglu/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[VIP /CLEAN SWIFT DESIGN PATTERN (SWIFT-iOS)]]></title>
            <link>https://serrasaracoglu.medium.com/vip-clean-swift-design-pattern-swift-ios-6a9a40b70475?source=rss-5abf90748079------2</link>
            <guid isPermaLink="false">https://medium.com/p/6a9a40b70475</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[vip]]></category>
            <category><![CDATA[design-patterns]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[viper]]></category>
            <dc:creator><![CDATA[Serra Saracoglu]]></dc:creator>
            <pubDate>Fri, 13 Aug 2021 11:27:31 GMT</pubDate>
            <atom:updated>2021-08-13T11:27:31.292Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*foKEwXhMUum1qFpWjJtSHg.png" /></figure><h4>WHY WE NEED DESIGN ARCHITETURES?</h4><p>Design patterns are the solutions for the problems which developers face during coding and it everyone can find out their solutions. We have many of them out there as technology grows and we find out new problems our way to approach to them is also changing.</p><h4>WHY VIP?</h4><p>As apps becoming complex and bigger by the time developers needs and preferences has changed as we mentioned above and VIP architecture opened very exciting way to iOS developers for handling complex work .</p><p>If many developers work on the same project,</p><p>If you have limited time,</p><p>If you need easy testing for whole project ,</p><p>If you have hard times struggling with many view controllers and feels like impossible to add new feature or debug and fixing it,</p><p>it would nice to find out VIP architecture- aka Clean-Swift.</p><p>Design architectures also show us a practical way for clean coding as well. They make easier to understand code for developer and even for user which is important duty of clean coding as well.</p><p>After explaining why design patterns are important for us we can start to learn about VIP!</p><h4>HOW TO CREATE VIP</h4><p>As we understand from it’s name we have three main component for VIP architecture,</p><p>First is as you can guess from its’ initial ;</p><p><strong>View Controller</strong>: Which we see all times of development cycle and main responsible of view controller is <strong>interacting with the user</strong>.</p><p>It has all UI, it will be our starting point for whole story.When you click generate joke button from view controller it will send a request to the interactor for doing some other job and after some user interaction presenter will give route us the thing what we wanted.</p><p><strong>Interactor</strong> is the second component of our VIP architecture, <strong>it is the place where we do all API jobs and calls.You fetch the data exactly here.</strong></p><p>And our last component is</p><p><strong>Presenter ; It calls view controller by passsing data.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iYm3aWqqyHgF1ip6ArLS8g.png" /></figure><p>Those were our main three components but additionally we have some other components such as Worker,Router etc.</p><blockquote>To be enlightened about VIP we first may understand scenes. VIP has a lot of scenes and t<strong>hose scenes has VIP cycle under all of them.</strong></blockquote><blockquote>For example adding book is a scene, register is a scene or login is a. Scene. It is different for every project and we can have many of them depend on how big and complicated our project is.</blockquote><figure><img alt="scenes" src="https://cdn-images-1.medium.com/max/460/1*da31OPK1Vq_duvSysGJh0w.png" /></figure><p>Communication between our components will be done by protocols.</p><blockquote>A <em>protocol</em> defines a blueprint of methods, properties, and other requirements that suit a particular task or piece of functionality. The protocol can then be <em>adopted</em> by a class, structure, or enumeration to provide an actual implementation of those requirements. Any type that satisfies the requirements of a protocol is said to <em>conform</em> to that protocol.</blockquote><p>Each our components should have protocols to receive and passing data between them.</p><p>So what about the other components like Router and Models?</p><h3>The Model</h3><ul><li>Decoupled data abstractions.</li></ul><h3>The Router</h3><ul><li>Extracts this navigation logic out of the view controller.</li><li>Keeps a weak reference to the source (View Controller).</li><li>We can use segues with VIP unlike VIPER:)</li></ul><h4>WHAT ARE THE SOURCES TO LEARN</h4><p>Amazing one;</p><blockquote><a href="https://www.netguru.com/blog/clean-swift-ios-architecture-pattern">https://www.netguru.com/blog/clean-swift-ios-architecture-pattern</a></blockquote><ul><li><a href="https://docs.swift.org/swift-book/LanguageGuide/Protocols.html">Protocols - The Swift Programming Language (Swift 5.7)</a></li><li><a href="https://clean-swift.com/">Get Started with Clean Swift - Clean Swift</a></li><li><a href="https://medium.com/@mlukacs_42903/part-1-what-is-clean-swift-vip-a-brief-overview-a43d4d66e664">Part 1: What is clean swift(VIP), a brief overview</a></li></ul><p>Thank you for reading the article, after learning about VIP next step is making a something real to learn it completely and well.</p><p>So good luck with it. You can find many templates on GitHub to work on easily and help you to understand the structure well.</p><p>Share your project GitHub link under the comments for inspiration for all of us, and all comments and suggestions are welcome.</p><p>Have a nice day of coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6a9a40b70475" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[OOP Basics of JavaScript]]></title>
            <link>https://serrasaracoglu.medium.com/oop-basics-of-javascript-90341f9733f0?source=rss-5abf90748079------2</link>
            <guid isPermaLink="false">https://medium.com/p/90341f9733f0</guid>
            <category><![CDATA[oop]]></category>
            <category><![CDATA[salesforce]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Serra Saracoglu]]></dc:creator>
            <pubDate>Mon, 09 Aug 2021 14:51:10 GMT</pubDate>
            <atom:updated>2021-08-09T14:51:10.504Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OHwT4m8VomSCdfqJlHXa1g.png" /></figure><p>Hello hello,</p><p>Today we are going to talk about delightful topic.</p><p>OOP with JavaScript as we all know it is not totally object oriented programming language but it is designed on a simple object-based model.</p><p>And as usual I have homework to do with JavaScript and I will share definitions with you to understand how do we do .</p><h4>Let’s start with how to create objects,</h4><p>var objectName={</p><p>propertyName:valueOfProperty,</p><p>propertyName:valueOfProperty</p><p>}</p><p>objectName is the name which we want to call our object like(person, student, employee etc.). propertyNames are the names which are the qualifications of our objects and valueOfProperty is the thing what that property has like what is the name age and so on.We use “=” sign as you have seen above .</p><p>Here we have one example from real code world;</p><blockquote>var Student={</blockquote><blockquote>firstName:”Alex”,</blockquote><blockquote>lastName:”Sun”,</blockquote><blockquote>age:12</blockquote><blockquote>}</blockquote><p>We have student object above, in JavaScript we can have objects with any classes.They don’t have to belong a class.</p><p>After objects we have one another main character of OOP, and here you go everyone we are gonna see <strong>Constructor function</strong>.</p><p>With constructors “<strong>this</strong>” operator use for to refer current object,</p><p>we should have “=” sign for properties and function.</p><p>There will be <strong>no return</strong>.</p><blockquote><em>function student(firstName,lastName,age){</em></blockquote><blockquote><em>this.firstName=firstName;</em></blockquote><blockquote><em>this.lastName=lastName;</em></blockquote><blockquote><em>this.age=age;</em></blockquote><blockquote>}</blockquote><p>At above we have our constructor function example.Value of objects depends on the parameters passed on the function.</p><p><strong>Properties</strong> are the things which are define the objects.You can define properties by assigning them some values.</p><p>How do we access properties you think?</p><p>We have two way for it, most general one is “dot notation” as you all know and the other is with brackets.</p><blockquote>var student{name:”David”}</blockquote><blockquote>student.name</blockquote><blockquote>student[name]</blockquote><blockquote>We can reach properties values as you have seen</blockquote><p>We have two more point to explain for that writing.</p><p>Functions and classes…</p><p>We need <strong>function</strong> key word then<strong> name and prantheses ()</strong>:)</p><p>Code will be executed between {} braces.</p><p>function <em>name</em>(<em>parameter1, parameter2, parameter3</em>) {<br> // <em>code to be executed</em><br>}</p><p><strong>return</strong> keyword will stop function execution.</p><p><strong>For classes</strong> we are using <strong>class</strong> keyword and then remember adding <strong>constructor() </strong>all the time.</p><p>class Book {<br> constructor(name, price) {<br> this.name = name;<br> this.price = price;<br> }<br>}</p><p>In this writing we have remembered basic JS OOP elements.</p><p>Next writing will be about applications of them and also encapsulation, inheritance with JS OOP.</p><p>How we can implement those to JS?</p><p>Stay with good technology, good luck!</p><p><a href="https://www.w3schools.com/">W3Schools.com</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=90341f9733f0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SWIFT OPTIONALS]]></title>
            <link>https://serrasaracoglu.medium.com/swift-optionals-d8531acb0a14?source=rss-5abf90748079------2</link>
            <guid isPermaLink="false">https://medium.com/p/d8531acb0a14</guid>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[apple]]></category>
            <category><![CDATA[swift-optionals]]></category>
            <category><![CDATA[swift-programming]]></category>
            <dc:creator><![CDATA[Serra Saracoglu]]></dc:creator>
            <pubDate>Sat, 10 Apr 2021 14:20:20 GMT</pubDate>
            <atom:updated>2021-04-10T14:20:20.377Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-_g457OLEvQllNSdxVWMzQ.png" /></figure><p>Today we will be discussing<strong> ”?”,”!”</strong> and the terms which are related to those in programming.</p><p><strong>What do we know about nil values?</strong> They are the values which they don’t have anything. We can see that as a null which does mean “0” in some other languages. It does mean <strong>“nothing”, non-existent”.</strong></p><h3>Let’s start with “?”;</h3><p>In the Swift programming language, we have this term “<strong>optional</strong>”. We cannot know our value will return any value to us and we will use the question mark to check if it has any value or is it null. Null values are not allowed in Swift, that’s why we should use <strong>optionals</strong>. So it means our type, value, a variable could be equal to some value or it is not equal to anything else. If its value is nil that means our variable is optional otherwise it is not something possible.</p><blockquote>Just a reminder Int and Int? is a different type that you can’t even add to each other.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*-SO_8vtSOaaNpEZAZtoTjw.png" /></figure><p>For example, I can create an integer like below, I will get nil because my variable is not initialized to anything.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gfcOOaL3YSuKuuGCTvit_g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ksbx_55KXHVLHpG5iZ_wnQ.png" /></figure><p>So, now we know why we use question mark but not everything is easy like how it looks. We are gonna need some other spice to use this question mark and now we have a brand-new term “<strong>unwrapping</strong>” and let’s get to know “<strong>!</strong>”. If our variable has a nil value we had to <strong>unwrap</strong> them.</p><blockquote>We change our Optional value to normal value with unwrapping to get rid of an optional keyword.</blockquote><h3>Force Unwrapping</h3><p>We call <strong>Force Unwrapping</strong> when we use <strong>“!” </strong>and when we check if it is nil or not, it will just respond to us with the keyword “optional” but <strong>if we use “!” to force unwrap we will get rid of the optional type of value we will get the normal type of value.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Qh3rJHYtADWrh5qsZNN8Tw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*01pWZgD6lWkQdIu4YXQIoA.png" /></figure><h3>Automatic Unwrapping</h3><p>We can use directly “!” exclamation mark instead of question mark. We won’t need to use any other exclamation mark . Just like you see in the example below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/606/1*jPP8J5LMA1uOhYcS1Z8Low.png" /></figure><p>If we want to use <strong>Implicit Unwrapping </strong>it is like promising the compiler I will define a value for sure this variable won’t be nil I promise. So we don’t have to unwrap the value.</p><blockquote><em>In short if we use </em><strong><em>? ; </em></strong><em>it means, just checking if it has a value or will it be a nil value.</em></blockquote><blockquote><em>If we use ! it means I promise my variable will get a value it won’t be nil and our compiler is happy now. If we use “!” if we unwrap the value and if there is no value our code will crash and we will get a run time error.</em></blockquote><h3><strong>Optional Binding:</strong></h3><p>It is same like Force Unwrapping ,We will change our Optional variable to normal type.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1020/1*hrAe3ZEo0UWWZ2enaZu9zA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/204/1*IYXGIGaTgchopa_S-cUzFQ.png" /></figure><p>It is all for now I hope you liked.Have a nice techy dayss:)))</p><p>Github: <a href="https://github.com/SerraSrcgl">https://github.com/SerraSrcgl</a></p><p>Linkedin: <a href="https://www.linkedin.com/in/serrasaracoglu/">https://www.linkedin.com/in/serrasaracoglu/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d8531acb0a14" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What is Memento Design Pattern]]></title>
            <link>https://serrasaracoglu.medium.com/what-is-memento-design-pattern-c2e8c322916b?source=rss-5abf90748079------2</link>
            <guid isPermaLink="false">https://medium.com/p/c2e8c322916b</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[design-patterns]]></category>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[memento]]></category>
            <dc:creator><![CDATA[Serra Saracoglu]]></dc:creator>
            <pubDate>Thu, 12 Nov 2020 00:21:29 GMT</pubDate>
            <atom:updated>2020-11-12T00:21:29.449Z</atom:updated>
            <content:encoded><![CDATA[<h3>Why do we use patterns?</h3><p><em>They require us a way to solve problems related to software development with a proven solution</em>.</p><p>We will start to talk about design patterns in programming and our first pattern is going to be Memento Pattern.The main aim of <strong>the Memento</strong> pattern is to save the state of an object and the restore it again if necessary.</p><blockquote>If you are asking what is what is state of object? Check this link out before I write whole another paper: <a href="https://marcus-biel.com/what-is-an-objects-state/">https://marcus-biel.com/what-is-an-objects-state/</a></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kQiNQfIrA9kySldjM0QjQQ.png" /></figure><p>We can easily define it as a UNDO action like in MS Word or like used in some games which have been saved before, long in short you can use memento pattern when you want to restore your state of object to previous state of the object.</p><p>So, how we will do it?</p><p>We are gonna have three special classes in this pattern which are they called originator, memento and caretaker.</p><p>What originator class do ?What do you think?</p><p>Originator class; is going to be our “saver and restorer” of state object.</p><p>Caretaker class; will store all states of the object on which it operates and returns these states and adds new states of the object.</p><p>Memento class; will store the current state of the object, its state can be read by the Originator class.</p><figure><img alt="memento Pattern" src="https://cdn-images-1.medium.com/max/584/1*Mt2cdJAIrBacewp-RKdrEQ.png" /></figure><p>So after all technical and theorical part we need some codes and we have to finish homework actually:) We are gonna write code for undo our move.</p><p>Let’s start with the Memento Class!</p><pre>public class StateMove {<br>    private String move;<br><br>    public StateMove(String move) {<br>        this.move = move;<br>    }<br><br>    public StateMove createMove() {<br>        return new StateMove(move);<br>    }<br><br>    public void restore(StateMove state) {<br>        move = state.getMove();<br>    }<br><br>    public String getMove() {<br>        return move;<br>    }<br><br><br>}</pre><p>It stores and returns the current state of the object.</p><p>Let’s go on with our caretaker class.</p><pre>import java.util.ArrayList;<br>import java.util.List;<br><br>public class PrevMove {<br>    private List&lt;StateMove&gt; moves=new ArrayList&lt;&gt;();<br>    <br>    public void push(StateMove move){<br>        moves.add(move);<br>    }<br>    public StateMove pop(){<br>        var lastIndex=moves.size()-1;<br>        var lastState=moves.get(lastIndex);<br>        moves.remove(lastState);<br>        return lastState;<br>    }<br>}</pre><p>Here is our originator class…</p><pre>public class Move {<br>    private String move;<br><br>    public String getMove() {<br>        return move;<br>    }<br><br>    public void setMove(String move) {<br>        this.move = move;<br>    }<br>    public StateMove createMove(){<br>        return new StateMove(move);<br>    }<br>    public void restore(StateMove state){<br>        move=state.getMove();<br>    }<br>}</pre><p>And we can’t forget our Main class never ever of course.</p><pre>public class Main {<br>    public static void main(String[] args) {<br><br>        Move move = new Move();        //move object created<br>        PrevMove prevMove = new PrevMove();         //previous move object also ceated<br><br>        move.setMove(&quot;Be Bad Guy&quot;);       //set move comes from originator it gets move object<br>        //move.setMove(&quot;Make Him Cry&quot;);<br>        prevMove.push(move.createMove()); //return state object<br><br>        move.setMove(&quot;Apologize&quot;);<br>        prevMove.push(move.createMove());<br><br>        move.setMove(&quot;Smile&quot;);<br>        System.<em>out</em>.println(&quot;Current State: &quot; + move.getMove());<br><br>       move.restore(prevMove.pop());  //what stored in the previous mode at above<br>        System.<em>out</em>.println(&quot;First saved State: &quot; + move.getMove());<br>       move.restore(prevMove.pop());<br>        System.<em>out</em>.println(&quot;Second saved State: &quot; + move.getMove());<br><br>    }<br>}</pre><figure><img alt="design Patterns" src="https://cdn-images-1.medium.com/max/1024/1*YhrhWWANZVgfsycp4149Ow.png" /></figure><p>I hope it was explaining enough you to understand the basic structure.</p><p>I want to keep update with other main design patterns as well.</p><p>See you in next pattern.</p><p>Byee!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c2e8c322916b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Binary Search Algorithm With JavaScript]]></title>
            <link>https://serrasaracoglu.medium.com/binary-search-algorithm-with-javascript-9ac46431615f?source=rss-5abf90748079------2</link>
            <guid isPermaLink="false">https://medium.com/p/9ac46431615f</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[binary-search]]></category>
            <category><![CDATA[algorithms]]></category>
            <dc:creator><![CDATA[Serra Saracoglu]]></dc:creator>
            <pubDate>Sun, 08 Nov 2020 15:33:18 GMT</pubDate>
            <atom:updated>2020-11-09T12:15:19.519Z</atom:updated>
            <content:encoded><![CDATA[<p>First of all before everything we should understand what” Binary Search” is. As we all understand from the name we will search something and it is going to be with famous Divide and Conquer approach.</p><blockquote>arr []={1,2,4,5,6,7}</blockquote><blockquote>x= 5</blockquote><blockquote>We found it!</blockquote><figure><img alt="From geeks for geeks" src="https://cdn-images-1.medium.com/max/1024/1*tyh5EfBnl9_Vkkc66tVCeA.png" /></figure><p>First Step: We should define our middle index</p><p>Second Step: After that if the number which we searching is less than our middle number we should start to investigate our left subarray, if not we will check right partof our array by doing this we will get our target number eventually.</p><p>We could have recursive and iterative approach to find to solution.</p><p>First of all we need to have start and end points then while start index is less or equal than end index</p><p>we should define the middle point of our array to compare our values.</p><p>function binary_Search(arr, value){</p><p>let firstIndex = 0;</p><p>let lastIndex = arr.length — 1;</p><p>let middleIndex = Math.floor((lastIndex + firstIndex)/2); while(items[middleIndex] != value &amp;&amp; firstIndex &lt; lastIndex) {</p><p>if (value &lt; items[middleIndex]) {</p><p>lastIndex = middleIndex — 1; — -we are cahnging our end points here</p><p>} else if (value &gt; items[middleIndex]) {</p><p>firstIndex = middleIndex + 1;</p><p>}</p><p>middleIndex = Math.floor((lastIndex + firstIndex)/2);</p><p>}</p><p>return (items[middleIndex] != value) ? -1 : middleIndex;</p><p>}</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/247/1*3eOrsoF9idyOp-0Ll9I9PA.png" /></figure><p><a href="https://en.wikipedia.org/wiki/Binary_search_algorithm">Binary search works on sorted arrays. Binary search begins by comparing an element in the middle of the array with the target value. If the target value matches the element, its position in the array is returned. If the target value is less than the element, the search continues in the lower half of the array. If the target value is greater than the element, the search continues in the upper half of the array. By doing this, the algorithm eliminates the half in which the target value cannot lie in each iteration.</a></p><p>tip: LEss →LEft</p><p>moRe →Right</p><p>Here we have code for JavaScript you can try by yourself with other languages as well.</p><p>Have fun!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9ac46431615f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[First Step To Algorithm Questions]]></title>
            <link>https://serrasaracoglu.medium.com/first-step-to-algorithm-questions-adb329fb6d54?source=rss-5abf90748079------2</link>
            <guid isPermaLink="false">https://medium.com/p/adb329fb6d54</guid>
            <category><![CDATA[java]]></category>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[leetcode]]></category>
            <dc:creator><![CDATA[Serra Saracoglu]]></dc:creator>
            <pubDate>Sun, 08 Nov 2020 01:19:56 GMT</pubDate>
            <atom:updated>2020-11-08T15:36:20.929Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Photo by Antonio Batinić from Pexels" src="https://cdn-images-1.medium.com/max/1024/1*pNz6L9LH-OB6dmeKQBlLxA.jpeg" /></figure><h3>Maximum consecutive one’s (or zeros) in a binary array</h3><p><em>Hello everybody, after I realized I need to keep track of the algorithm questions that I have solved and understood well. I started to write this series of explanations. These are for me in the first place then I hope it can help you as well. I came across this question at the “Leet Code” in the array part.</em></p><blockquote>Given a binary array, find the maximum number of consecutive 1s in this array.</blockquote><blockquote>e.g.</blockquote><blockquote>input:arr[]={1,1,0,0,1,1,1,1,0,0}</blockquote><blockquote>output:4</blockquote><blockquote>input:arr[]={1,0,1,0,0,1,1,1}</blockquote><blockquote>output:3</blockquote><p><strong><em>So how we can solve that kind of question let me think…</em></strong></p><p><strong><em>We need count 1s, we know that. Then additionally we had to visit each element of an array. Which we called a traversing the array. (Just start with the index 0 and loop while the index is less than length.)In the end, we need to have a result as well. Let’s start to write code with the given frame.</em></strong></p><p><strong>class Solution {</strong></p><p><strong>public int findMaxConsecutiveOnes(int[] nums,int n) {</strong></p><p><strong>}</strong></p><p><strong>}</strong></p><p>This is what we have at first then;</p><p>Initialize count and initialize max result value then traverse the array.</p><p><strong>class Solution {</strong></p><p><strong>public int findMaxConsecutiveOnes(int[] nums,int n) {</strong></p><p>int count=0,res=0;</p><p>for(int i=0;i&lt;nums.length;i++) — — — -&gt;traverse array left to right</p><p>{</p><p>if(nums[i]==0) — — →if we see 0 we reset count as 0</p><p>count=0;</p><p>else — — -&gt; if we see 1 we will increase our count</p><p>{</p><p>count++;</p><p>res=Math.max(res,count); — — →this max function accept two parameter and return the max one</p><p>}</p><p>}</p><p>return res;</p><p><strong>}</strong></p><p><strong>}</strong></p><p>It was end of the solution I hope it may help you.Have a great day!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=adb329fb6d54" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>