<?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 NMTechBytes on Medium]]></title>
        <description><![CDATA[Stories by NMTechBytes on Medium]]></description>
        <link>https://medium.com/@anumsarmadmalik?source=rss-81d82750f0e9------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Z5ZeJevyL4ax1o8DDXM4ag.jpeg</url>
            <title>Stories by NMTechBytes on Medium</title>
            <link>https://medium.com/@anumsarmadmalik?source=rss-81d82750f0e9------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 18:18:44 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@anumsarmadmalik/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[Solve the Best Time to Buy and Sell Stock Problem]]></title>
            <link>https://medium.com/javarevisited/solve-the-best-time-to-buy-and-sell-stock-problem-8ab9c9ff895e?source=rss-81d82750f0e9------2</link>
            <guid isPermaLink="false">https://medium.com/p/8ab9c9ff895e</guid>
            <category><![CDATA[leetcode]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[problem-solving]]></category>
            <dc:creator><![CDATA[NMTechBytes]]></dc:creator>
            <pubDate>Fri, 08 Jan 2021 08:17:31 GMT</pubDate>
            <atom:updated>2021-01-08T08:19:30.462Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CjKwAPJeE4ZWteGnth0tCA.jpeg" /><figcaption>Image by <a href="https://www.freepik.com/free-photo/capital-tablet-exchange-screen-skyscraper_1088871.htm#page=1&amp;query=stock&amp;position=5">FreePik</a></figcaption></figure><h3>1. Problem Statement</h3><p>You are given an integer array of prices where prices[i] is the price of a given stock on an ith day. Design an algorithm to find the maximum profit.</p><p>Some constraints are as follows:</p><ul><li>You may complete at most k transactions.</li><li>You may not engage in multiple transactions simultaneously (i.e., you must sell the stock before you buy again).</li></ul><p>Example 1:</p><pre>Input: k = 2, prices = [2,4,1]<br>Output: 2<br>Explanation: Buy on day 1 (price = 2) and sell on day 2 (price = 4), profit = 4-2 = 2.</pre><p>Example 2:</p><pre>Input: k = 2, prices = [3,2,6,5,0,3]<br>Output: 7<br>Explanation: Buy on day 2 (price = 2) and sell on day 3 (price = 6), profit = 6-2 = 4. Then buy on day 5 (price = 0) and sell on day 6 (price = 3), profit = 3-0 = 3.</pre><h3>2. Solution</h3><p>The problem is to find out the maximum profit you can get for a stock during a certain period of time.</p><h4>States</h4><p>We have 2 states for a stock on a Day(i):</p><blockquote>Buy: <br>* Last transaction action on the stock was a buy. <br>* This <strong>initiates</strong> a transaction and bumps the transaction count.</blockquote><blockquote>Sell: <br>* Last transaction action on the stock was a sell. <br>* This <strong>closes</strong> the transaction.</blockquote><h4>Actions</h4><p>Hence, there are 3 possible actions you can take on Day(i):</p><blockquote>Action 1. Buy the stock, if there is no Buy done on an earlier day.<br>Action 2. Sell the stock, if there is a Buy done on an earlier day.<br>Action 3. Do Nothing.</blockquote><h4>States &amp; Actions</h4><p>Let’s rearrange the above into actions and states. <br>The goal is to calculate the max profit while making sure that the state (buy or sell) stays on that day and there is no transaction overlap.</p><blockquote>Day(i) | Buy: <br>* Action 1: Do nothing = keep profit from Buy state on Day(i-1)<br> OR <br>* Action 2: Buy stock with profit from Sell state on Day(i-1) <br>[ensure that previous transaction is closed before initiating another one]</blockquote><blockquote>Day(i) | Sell: <br>* Action 1: Do nothing = keep profit from Sell state on Day(i-1)<br> OR <br>* Action 2: Sell stock and add to profit from Buy state on Day(i-1) <br>[sell what was bought earlier]</blockquote><h4>States &amp; Actions &amp; Transactions</h4><p>Now let’s add the transaction count constraint.<br>The goal is to calculate the max profit while making sure that the state (buy or sell) stays on that day, there is no transaction overlap and the transaction count is within limits.</p><blockquote>Day(i) | <strong>Transaction(t)</strong> | Buy: <br>* Action 1: Do nothing = keep profit from Buy state on Day(i-1) &amp; <strong>Transaction(t)</strong><br> OR <br>* Action 2: Buy stock with profit from Sell state on Day(i-1) &amp; <br><strong>Transaction(t-1)</strong><br>[ensure that previous transaction is closed before initiating another one and <strong>doing a buy will initiate a transaction leading to a bump so use t-1</strong>]</blockquote><blockquote>Day(i) | <strong>Transaction(t) </strong>| Sell: <br>* Action 1: Do nothing = keep profit from Sell state on Day(i-1) &amp; <strong>Transaction(t)</strong><br> OR <br>* Action 2: Sell stock and add to profit from Buy state on Day(i-1) &amp; <strong>Transaction(t) </strong><br>[sell what was bought earlier]</blockquote><p>If we calculate the above states for all days and transaction counts, we will eventually find out the maximum profit on the last day with the Sell state. Sell should be the last state since we want a transaction that’s closed towards the end since a Buy at the end would be a wasteful loss of money.</p><h4>Time &amp; Space Complexity</h4><ul><li>Time Complexity: O(n * k) where n is the max number of days and k is the max transactions allowed. This is because we have to calculate profits for 2 states for all possible combinations of days and transaction counts.</li><li>Space Complexity: O(k) where k is the max transactions allowed.</li></ul><h3>3. Optimization</h3><p>The above O(n * k) solution works very well if k less than the maximum number of transactions possible.</p><p>But what if the transaction count was unlimited or in other words greater than the maximum number of mutually-exclusive transactions possible during those days? Can we do better?</p><p>A simpler solution for this case is to iterate through the days and start a transaction each time we see a local valley and sell on the local peak.</p><figure><a href="https://www.java67.com/2018/06/data-structure-and-algorithm-interview-questions-programmers.html"><img alt="" src="https://cdn-images-1.medium.com/max/830/1*XMo8yJgmiD7puDZak5WzNg.png" /></a><figcaption><strong>Buy and Sell</strong></figcaption></figure><h3>4. Code (Java)</h3><p>The following code implements the logic explained above in Java.<br>Buy state is represented with a 1 and Sell state with 0.</p><pre><strong>public int maxProfit(int k, int[] prices) {</strong><br>    int days = prices.length;<br>    if (days&lt;=0 || k&lt;= 0) {<br>      return 0;<br>    }<br> <br>    <strong>// If transactions allowed are max possible ...</strong><br>    if (k &gt;= (days/2)) {<br>      int maxProfit = 0;<br>      int min = prices[0];<br>      for (int i=1; i&lt;days; i++) {<br>        if (prices[i] &lt; min) {<br>          min = prices[i];<br>        } else {<br>          maxProfit += (prices[i] — min);<br>          min = prices[i];<br>        }<br>      }<br>      return maxProfit;<br>    }</pre><pre>    <strong>// Find max profit for additional day with 0-k transactions.<br>    </strong>int dp[][] = new int[k+1][2];<br>    <strong>// Assigning negative values for cases which are not applicable</strong>.   <br>    for (int t = 0; t &lt;= k; t++) {<br>      dp[t][0] = -10000;<br>      dp[t][1] = -10000;<br>    }<br>    dp[0][0] = 0;<br>    dp[1][1] = -prices[0];<br>    for (int d=1; d&lt;days; d++) {<br>      int dpNew[][] = dp.clone();<br>      for (int t=0; t&lt;=k; t++) { <br>        dpNew[t][0] = Math.max(dp[t][0], dp[t][1] + prices[d]); <br>        if (t==0) {<br>          continue;<br>        }<br>        dpNew[t][1] = Math.max(dp[t][1], dp[t-1][0] — prices[d]); <br>      }<br>    }<br> <br>    <strong>// Find the max profit for the last day.</strong><br>    int maxProfit = 0;<br>    for (int t=0; t&lt;=k; t++) {<br>      maxProfit = Math.max(maxProfit, dp[t][0]);<br>    }<br>    return maxProfit;<br> <strong>}</strong></pre><p>If you found this article useful, <strong>please help me reach more dev learners!</strong></p><p>Show some ❤ by giving “claps” 👏 at the left margin of the page (on desktop) or at the bottom (on mobile). You can do so up to <strong>50</strong> times by clicking continuously!</p><h3>Anum Malik</h3><p>Follow NMTechBytes on <a href="https://twitter.com/anumsarmadmalik">Twitter</a> for my daily tech bites :)</p><h3>Special Thanks:</h3><ul><li><a href="https://leetcode.com/problems/best-time-to-buy-and-sell-stock-iv/submissions/">LeetCode Stock Problem</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8ab9c9ff895e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/javarevisited/solve-the-best-time-to-buy-and-sell-stock-problem-8ab9c9ff895e">Solve the Best Time to Buy and Sell Stock Problem</a> was originally published in <a href="https://medium.com/javarevisited">Javarevisited</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[11 Solutions to Exercises in GoLang Tour]]></title>
            <link>https://medium.com/@anumsarmadmalik/11-solutions-togolang-tours-exercises-7ee61b7b94f5?source=rss-81d82750f0e9------2</link>
            <guid isPermaLink="false">https://medium.com/p/7ee61b7b94f5</guid>
            <category><![CDATA[golang-tutorial]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[programming-languages]]></category>
            <category><![CDATA[go]]></category>
            <category><![CDATA[golang]]></category>
            <dc:creator><![CDATA[NMTechBytes]]></dc:creator>
            <pubDate>Sun, 06 Sep 2020 22:01:31 GMT</pubDate>
            <atom:updated>2020-09-07T17:27:23.349Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>Solutions to all the exercises on the Tour of Go Website.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5nXC2DQui7eoYuVbWq1S-A.png" /><figcaption>The Gopher</figcaption></figure><p>The <a href="https://tour.golang.org/">Tour of Go Website</a> is an excellent start for an developer trying to learn the language Go. It gradually introduces you to the language by explaining different parts and provides exercises to the reader to implement.</p><p>Following are the solutions I wrote for the exercises as I went through the tour.</p><h3><strong>Exercise 1: Loops and Functions</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*swu_NJ16nBlOeyAT" /><figcaption>Photo by <a href="https://unsplash.com/@antoine1003?utm_source=medium&amp;utm_medium=referral">Antoine Dautry</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><blockquote>Given a number x, we want to find the number z for which z² is most nearly x.</blockquote><pre><strong>package main</strong></pre><pre>import (<br>  &quot;fmt&quot;<br>  &quot;math&quot;<br>)</pre><pre>func <strong>Sqrt</strong>(x float64) float64 {<br>  z := float64(1)<br>  for i:=1; i&lt;=10; i++ {<br>    fmt.Println(z)<br>    z -= (z * z - x) / (2 * z)<br>  }<br>  return z<br>}</pre><pre>func <strong>main</strong>() {<br>  fmt.Println(Sqrt(2))<br>  fmt.Println(math.Sqrt(2))<br>}</pre><h3><strong>Exercise 2: Slices</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Lf3oXNKCEUg5cCKC" /><figcaption>Photo by <a href="https://unsplash.com/@barvlad?utm_source=medium&amp;utm_medium=referral">Vlad Baranov</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><blockquote>Implement Pic. It should return a slice of length dy, each element of which is a slice of dx 8-bit unsigned integers.</blockquote><pre><strong>package main</strong></pre><pre>import &quot;golang.org/x/tour/pic&quot;</pre><pre>func <strong>Pic</strong>(dx, dy int) [][]uint8 {<br>  var result = make([][]uint8, dy)<br>  for x := range result {<br>    result[x] = make([]uint8, dx)<br>    for y:= range result[x] {<br>      result[x][y] = uint8(x*y)<br>    }<br>  }<br>  return result<br>}</pre><pre>func <strong>main</strong>() {<br>  pic.Show(Pic)<br>}</pre><h3>Exercise 3: Maps</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*NeUKjxgAZm2H7BgM" /><figcaption>Photo by <a href="https://unsplash.com/@marjan_blan?utm_source=medium&amp;utm_medium=referral">Марьян Блан | @marjanblan</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><blockquote>Implement WordCount. It should return a map of the counts of each “word” in the string s. The wc. Test function runs a test suite against the provided function and prints success or failure.</blockquote><pre><strong>package main</strong></pre><pre>import (<br> &quot;golang.org/x/tour/wc&quot;<br> &quot;strings&quot;<br>)</pre><pre>func <strong>WordCount</strong>(s string) map[string]int {<br>  result := make(map[string]int)<br>  words := strings.Fields(s)<br>  for _, word := range words {<br>    result[word] += 1<br>  }<br>  return result<br>}</pre><pre>func <strong>main</strong>() {<br>  wc.Test(WordCount)<br>}</pre><h3>Exercise 4: Fibonacci Closure</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*YFHTfxmxSG2bZYRv" /><figcaption>Photo by <a href="https://unsplash.com/@nhillier?utm_source=medium&amp;utm_medium=referral">Nick Hillier</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><blockquote>Implement a fibonacci function that returns a function (a closure) that returns successive fibonacci numbers (0, 1, 1, 2, 3, 5, …)</blockquote><pre><strong>package main</strong></pre><pre>import &quot;fmt&quot;</pre><pre>func <strong>fibonacci</strong>() func() int {<br>  total, nextTotal := 0, 1<br>  return func() int {<br>    result := total<br>    total, nextTotal = nextTotal, nextTotal + result<br>    return result<br>  }<br>}</pre><pre>func <strong>main</strong>() {<br>  f := fibonacci()<br>  for i := 0; i &lt; 10; i++ {<br>    fmt.Println(f())<br>  }<br>}</pre><h3>Exercise 5: Stringers</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*b7E7PkeiUlKeRjkn" /><figcaption>Photo by <a href="https://unsplash.com/@amadorloureiroblanco?utm_source=medium&amp;utm_medium=referral">Amador Loureiro</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><blockquote>Make the IPAddr type implement fmt.Stringer to print the address as a dotted quad.</blockquote><pre><strong>package main</strong></pre><pre>import &quot;fmt&quot;</pre><pre>type <strong>IPAddr</strong> [4]byte</pre><pre>func (ia IPAddr) <strong>String</strong>() string {<br>  return fmt.Sprintf(&quot;%d %d %d %d&quot;, ia[0], ia[1], ia[2], ia[3]) <br>}</pre><pre>func <strong>main</strong>() {<br>  hosts := map[string]IPAddr{<br>    &quot;loopback&quot;:  {127, 0, 0, 1},<br>    &quot;googleDNS&quot;: {8, 8, 8, 8},<br>  }<br>  for name, ip := range hosts {<br>    fmt.Printf(&quot;%v: %v\n&quot;, name, ip)<br>  }<br>}</pre><h3>Exercise 6: Errors</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*eI934HYFV8DEYfYM" /><figcaption>Photo by <a href="https://unsplash.com/@woodies11?utm_source=medium&amp;utm_medium=referral">Romson Preechawit</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><blockquote>Sqrt should return a non-nil error value when given a negative number, as it doesn&#39;t support complex numbers.</blockquote><pre><strong>package main</strong></pre><pre>import (<br> &quot;fmt&quot;<br> &quot;math&quot;<br>)</pre><pre>type <strong>ErrNegativeSqrt</strong> float64</pre><pre>func (e ErrNegativeSqrt) <strong>Error</strong>() string {<br>  return fmt.Sprintf(&quot;cannot Sqrt negative number: %d&quot;, e)<br>}</pre><pre>func <strong>Sqrt</strong>(x float64) (float64, error) {<br>  if (x &lt; 0) {<br>    return 0, ErrNegativeSqrt(x) <br>  }<br>  z := float64(1)<br>  tolerance := 1e-6<br> <br>  for {<br>    oldz := z<br>    z -= (z * z - x) / (2 * z)<br>    if math.Abs(z-oldz) &lt; tolerance {<br>      break; <br>    }<br>  }<br>  return z, nil<br>}</pre><pre>func <strong>main</strong>() {<br>  fmt.Println(Sqrt(2))<br>  fmt.Println(Sqrt(-2))<br>}</pre><h3>Exercise 7: Readers</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*qfn-VxPTu14EPFO9" /><figcaption>Photo by <a href="https://unsplash.com/@jamie452?utm_source=medium&amp;utm_medium=referral">Jamie Street</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><blockquote>Implement a Reader type that emits an infinite stream of the ASCII character ‘A’.</blockquote><pre><strong>package main</strong></pre><pre>import &quot;golang.org/x/tour/reader&quot;</pre><pre>type <strong>MyReader</strong> struct{}</pre><pre>func (r MyReader) <strong>Read</strong>(b []byte) (int, error) {<br>  a := &#39;A&#39;<br>  for i:=0; i &lt; len(b); i++ {<br>    b[i] = a <br>  }<br>  return len(b), nil<br>}</pre><pre>// TODO: Add a Read([]byte) (int, error) method to MyReader.</pre><pre>func <strong>main</strong>() {<br>  reader.Validate(MyReader{})<br>}</pre><h3>Exercise 8: rot13Reader</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*245D6TgpkzR7YzQw" /><figcaption>Photo by <a href="https://unsplash.com/@roadtripwithraj?utm_source=medium&amp;utm_medium=referral">Road Trip with Raj</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><blockquote>Implement a rot13Reader that implements io.Reader and reads from an io.Reader, modifying the stream by applying the rot13 substitution cipher to all alphabetical characters</blockquote><pre><strong>package main</strong></pre><pre>import (<br> &quot;io&quot;<br> &quot;os&quot;<br> &quot;strings&quot;<br>)</pre><pre>type <strong>rot13Reader</strong> struct {<br>  r io.Reader<br>}</pre><pre>func (rd *rot13Reader) <strong>Read</strong>(b []byte) (n int, e error) {<br>  n, e = rd.r.Read(b)<br>  for i:=0; i&lt;len(b); i++ {<br>    c := b[i] <br>    if (c &gt;= &#39;a&#39; &amp;&amp; c &lt;= &#39;m&#39;) || (c &gt;= &#39;A&#39; &amp;&amp; c &lt;= &#39;M&#39;)  {<br>      b[i] += 13;    <br>    } else if (c &gt;= &#39;n&#39; &amp;&amp; c &lt;= &#39;z&#39;) || (c &gt;= &#39;N&#39; &amp;&amp; c &lt;= &#39;Z&#39;) {<br>      b[i]  -= 13;<br>    }<br>  } <br>  return<br>}</pre><pre>func <strong>main</strong>() {<br>  s := strings.NewReader(&quot;Lbh penpxrq gur pbqr!&quot;)<br>  r := rot13Reader{s}<br>  io.Copy(os.Stdout, &amp;r)<br>}</pre><h3><strong>Exercise 9: Images</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*1g9tZFh4tpzUnlhO" /><figcaption>Photo by <a href="https://unsplash.com/@introspectivedsgn?utm_source=medium&amp;utm_medium=referral">Erik Mclean</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><blockquote>Write another one, but this time it will return an implementation of image.Image instead of a slice of data. Define your own Image type, implement the necessary methods, and call pic.ShowImage. Bounds should return a image.Rectangle, like image.Rect(0, 0, w, h). ColorModel should return color.RGBAModel. At should return a color; the value v in the last picture generator corresponds to color.RGBA{v, v, 255, 255} in this one.</blockquote><pre><strong>package main</strong></pre><pre>import (<br>  &quot;golang.org/x/tour/pic&quot;<br>  &quot;image&quot;<br>  &quot;image/color&quot;<br>)</pre><pre>type <strong>Image</strong> struct{<br>  x int<br>  y int<br>}</pre><pre>func (i Image) <strong>Bounds</strong>() image.Rectangle {<br>  return image.Rect(0, 0, i.x, i.y)<br>}</pre><pre>func (i Image) <strong>At</strong>(x, y int) color.Color {<br>  v := uint8(x*y)<br>  return color.RGBA{v, v, 255, 255}<br>}</pre><pre>func (i Image) <strong>ColorModel</strong>() color.Model {<br>  return color.RGBAModel<br>}</pre><pre>func <strong>main</strong>() {<br>  m := Image{256, 65}<br>  pic.ShowImage(m)<br>}</pre><h3>Exercise 10: Equivalent Binary Trees</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*GDGu8JtwC68LON7P" /><figcaption>Photo by <a href="https://unsplash.com/@andreasdress?utm_source=medium&amp;utm_medium=referral">Andreas Dress</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><blockquote>Implement the Walk function and Same function using Walk to determine whether t1 and t2 store the same values.</blockquote><pre><strong>package main</strong></pre><pre>import (<br> &quot;golang.org/x/tour/tree&quot;<br> &quot;fmt&quot;<br>)</pre><pre>// Walk walks the tree t sending all values<br>// from the tree to the channel ch.<br>func <strong>Walk</strong>(t *tree.Tree, ch chan int) {<br>  WalkHelper(t, ch)<br>  close(ch)<br>}</pre><pre>func <strong>WalkHelper</strong>(t *tree.Tree, ch chan int) {<br>  if t == nil {<br>   return <br>  }<br>  WalkHelper(t.Left, ch)<br>  ch &lt;- t.Value<br>  WalkHelper(t.Right, ch)<br>}</pre><pre>// Same determines whether the trees<br>// t1 and t2 contain the same values.<br>func <strong>Same</strong>(t1, t2 *tree.Tree) bool {<br>  ch1 := make(chan int)<br>  ch2 := make(chan int)<br>  go Walk(t1, ch1)<br>  go Walk(t2, ch2)<br>  for v1 := range ch1 {<br>    v2 := &lt;-ch2<br>    if v1 != v2 {<br>      return false <br>    }<br>  }<br>  return true <br>}</pre><pre>func <strong>main</strong>() {<br>  fmt.Println(Same(tree.New(1), tree.New(1))) <br>  fmt.Println(Same(tree.New(1), tree.New(2))) <br>}</pre><h3>Exercise 11: Web Crawler</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*O0-mNq_MjMpCZPB2" /><figcaption>Photo by <a href="https://unsplash.com/@anritikhon?utm_source=medium&amp;utm_medium=referral">Andrey Tikhonovskiy</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><blockquote>Use Go’s concurrency features to parallelize a web crawler.Modify the Crawl function to fetch URLs in parallel without fetching the same URL twice.</blockquote><pre><strong>package main</strong></pre><pre>import (<br>  &quot;fmt&quot;<br>  &quot;sync&quot;<br>)</pre><pre>type <strong>Fetcher</strong> interface {<br>  // Fetch returns the body of URL and<br>  // a slice of URLs found on that page.<br>  Fetch(url string) (body string, urls []string, err error)<br>}</pre><pre>var cache = make(Cache)<br>var wg sync.WaitGroup<br>var mux sync.Mutex</pre><pre>// Crawl uses fetcher to recursively crawl<br>// pages starting with url, to a maximum of depth.<br>func <strong>Crawl</strong>(url string, depth int, fetcher Fetcher) {<br>  defer wg.Done()<br>  if cache.get(url) {<br>    fmt.Printf(&quot;xx Skipping: %s\n&quot;, url)<br>    return<br>  }<br>  fmt.Printf(&quot;** Crawling: %s\n&quot;, url)<br>  cache.set(url, true)<br> <br>  if depth &lt;= 0 {<br>    return<br>  }<br>  body, urls, err := fetcher.Fetch(url)<br>  if err != nil {<br>    fmt.Println(err)<br>    return<br>  }<br>  fmt.Printf(&quot;found: %s %q\n&quot;, url, body)<br>  for _, u := range urls {<br>    wg.Add(1)<br>    go Crawl(u, depth-1, fetcher)<br>  }<br>  return<br>}</pre><pre>func <strong>main</strong>() {<br>  wg.Add(1)<br>  Crawl(&quot;<a href="https://golang.org/">https://golang.org/</a>&quot;, 4, fetcher)<br>  wg.Wait()<br>}</pre><pre>type <strong>Cache</strong> map[string]bool</pre><pre>func (ch Cache) <strong>get</strong>(key string) bool {<br>  mux.Lock()<br>  defer mux.Unlock()<br>  return cache[key]<br>}</pre><pre>func (ch Cache) <strong>set</strong>(key string, value bool) {<br>  mux.Lock()<br>  defer mux.Unlock()<br>  cache[key] = value<br>}</pre><pre>// fakeFetcher is Fetcher that returns canned results.<br>type fakeFetcher map[string]*fakeResult</pre><pre>type <strong>fakeResult</strong> struct {<br>  body string<br>  urls []string<br>}</pre><pre>func (f fakeFetcher) <strong>Fetch</strong>(url string) (string, []string, error) {<br>  if res, ok := f[url]; ok {<br>    return res.body, res.urls, nil<br>  }<br>  return &quot;&quot;, nil, fmt.Errorf(&quot;not found: %s&quot;, url)<br>}</pre><pre>// fetcher is a populated fakeFetcher.<br>var fetcher = fakeFetcher{<br>  &quot;<a href="https://golang.org/">https://golang.org/</a>&quot;: &amp;fakeResult{<br>   &quot;The Go Programming Language&quot;,<br>  []string{<br>   &quot;<a href="https://golang.org/pkg/">https://golang.org/pkg/</a>&quot;,<br>   &quot;<a href="https://golang.org/cmd/">https://golang.org/cmd/</a>&quot;,<br>  },<br> },<br> &quot;<a href="https://golang.org/pkg/">https://golang.org/pkg/</a>&quot;: &amp;fakeResult{<br>  &quot;Packages&quot;,<br>  []string{<br>   &quot;<a href="https://golang.org/">https://golang.org/</a>&quot;,<br>   &quot;<a href="https://golang.org/cmd/">https://golang.org/cmd/</a>&quot;,<br>   &quot;<a href="https://golang.org/pkg/fmt/">https://golang.org/pkg/fmt/</a>&quot;,<br>   &quot;<a href="https://golang.org/pkg/os/">https://golang.org/pkg/os/</a>&quot;,<br>  },<br> },<br> &quot;<a href="https://golang.org/pkg/fmt/">https://golang.org/pkg/fmt/</a>&quot;: &amp;fakeResult{<br>  &quot;Package fmt&quot;,<br>  []string{<br>   &quot;<a href="https://golang.org/">https://golang.org/</a>&quot;,<br>   &quot;<a href="https://golang.org/pkg/">https://golang.org/pkg/</a>&quot;,<br>  },<br> },<br> &quot;<a href="https://golang.org/pkg/os/">https://golang.org/pkg/os/</a>&quot;: &amp;fakeResult{<br>  &quot;Package os&quot;,<br>  []string{<br>   &quot;<a href="https://golang.org/">https://golang.org/</a>&quot;,<br>   &quot;<a href="https://golang.org/pkg/">https://golang.org/pkg/</a>&quot;,<br>  },<br> },<br>}</pre><p>If you found this article useful, <strong>please help me reach more dev learners!</strong></p><p>Show some ❤ by giving “claps” 👏 at the left margin of the page (on desktop) or at the bottom (on mobile). You can do so up to <strong>50</strong> times by clicking continuously!</p><h3>Anum Malik</h3><p><a href="https://www.linkedin.com/in/anumsarmadmalik/">LinkedIn</a> | <a href="https://twitter.com/anumsarmadmalik">Twitter</a></p><h3>Special Thanks …</h3><ul><li><a href="https://tour.golang.org/">Golang Tour Exercises</a></li><li><a href="https://gist.github.com/weppos/7843653">weppos/44.go</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7ee61b7b94f5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Cracking the Minimum Candy Distribution Problem]]></title>
            <link>https://medium.com/javarevisited/how-to-solve-the-minimum-candy-distribution-problem-4c868740f16a?source=rss-81d82750f0e9------2</link>
            <guid isPermaLink="false">https://medium.com/p/4c868740f16a</guid>
            <category><![CDATA[tech]]></category>
            <category><![CDATA[women-in-tech]]></category>
            <category><![CDATA[leetcode]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[NMTechBytes]]></dc:creator>
            <pubDate>Tue, 18 Aug 2020 15:25:10 GMT</pubDate>
            <atom:updated>2020-09-07T17:32:15.981Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DhP02uJn8RY_RaL2azsKqA.png" /><figcaption>Image by <a href="https://www.freepik.com/premium-vector/colourful-fruit-candies-chocolate-sweets-flat-icons-circle-design_4080058.htm#:~:text=Copy%20link">Freepik</a></figcaption></figure><h3>Problem Statement</h3><p>There are N children standing in a line and each child is assigned a rating value. You are giving candies to these children while making sure that each child must have at least one candy and children with a higher rating get more candies than their neighbors. What is the minimum candies you must give?</p><h4>Examples:</h4><ul><li>Input: [1 ,0 , 2] | Output: 5 { <strong>Distribution</strong>: [2, 1, 2] }</li><li>Input: [1, 2, 2] | Output: 4 { <strong>Distribution</strong>: [2, 1, 1] }</li><li>Input: [0, 2, 0, 6, 6] | Output: 7 { <strong>Distribution</strong>:[1, 2, 1, 2, 1] }</li></ul><h3>Solution 🍬— Time &amp; Space Complexity O(n)</h3><p>Basically, every child has to evaluate <strong>both</strong> <strong>neighbors (previous child and next child) </strong>to find the candy count that he/she should get:</p><ul><li>If the child has a higher than the neighbor/s, then the child should get more candies than the neighbor/s.</li><li>If the child has a lower than or equals to rating than the neighbor/s, then the neighbors/s can be ignored since this has no impact on the candy count of the child in question.</li></ul><p>The concrete steps of the <a href="https://medium.com/hackernoon/50-data-structure-and-algorithms-interview-questions-for-programmers-b4b1ac61f5b0">algorithm</a> and it’s code is as follows:</p><figure><a href="https://www.java67.com/2018/06/data-structure-and-algorithm-interview-questions-programmers.html"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7fK8DuRe7xg5QTxpui342w.png" /></a><figcaption>Forward Traversal</figcaption></figure><ul><li>Forward Traversal: Start traversing the ratings from the first child and update the candy count of the next child on the way. If the rating of the current child is less than the next child’s rating, then the next child’s candy count must be at least<em> </em>1 more than the candy count of the current child.</li></ul><figure><a href="https://medium.com/javarevisited/7-free-books-to-learn-data-structure-and-algorithms-in-java-346b2d70db10"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4Cf2nIi-fTqU1ljgxJ6vRQ.png" /></a><figcaption>Backward Traversal</figcaption></figure><ul><li>Backward Traversal: Start traversing the ratings from the last child and update the candy count of the previous child on the way. If the rating of the current child is less than the previous child’s rating then the previous child’s candy count must be at least<em> </em>1 more than the candy count of the current child.</li><li>Count Candies: Calculate sum of the candy counts for each child for the final count.</li></ul><pre><strong>// Language: Java<br>// Time Complexity: O(n) 3 Linear traversals.<br>// Space Complexity: O(n) Array of candies.</strong></pre><pre>public int candy(int[] ratings) {<br>      if (ratings.length &lt; 2) {<br>        return ratings.length;<br>      }<br>        <br>      int[] candies = new int[ratings.length];<br>      Arrays.fill(candies, 1);<br>        <br>     <strong> // ** Step 1: Forward **</strong><br>      for (int i=0; i&lt;ratings.length-1; i++) {<br>        if (ratings[i] &gt;= ratings[i+1]) {<br>          continue;<br>        }         <br>        candies[i+1] = candies[i] + 1;    <br>      }<br>        <br>      <strong>// ** Step 2: Backward **</strong><br>      for (int i=ratings.length-1; i&gt;0; i--) {<br>        if (ratings[i] &gt;= ratings[i-1]) {<br>          continue;<br>        }<br>        candies[i-1] = Math.max(candies[i] + 1, candies[i-1]);   <br>      }<br>        <br>      <strong>// ** Step 3: Count Candies **</strong><br>      int count = 0;<br>      for (int i=0; i&lt;candies.length; i++) {<br>        count += candies[i];<br>      }<br>        <br>      return count;     <br> }</pre><p>This is a perfectly acceptable solution, but we can save some space by optimizing the <a href="https://medium.com/hackernoon/10-data-structure-algorithms-and-programming-courses-to-crack-any-coding-interview-e1c50b30b927?source=user_profile---------8-----------------------">algorithm </a>in the next section.</p><h3>🍬 Optimization of Space — O(n) -&gt; O(1)</h3><h4>Introduction of Basics</h4><p>Let’s visualize the distribution of input [0, 4, 9, 25, 8, 6, 5] as follows:</p><figure><a href="https://medium.com/javarevisited/20-array-coding-problems-and-questions-from-programming-interviews-869b475b9121"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QNeM9pWN495AJAfkwRK0Dw.png" /></a><figcaption>Ratings [0, 4, 9, 25, 8, 6, 5]</figcaption></figure><p>Here are some important observations:</p><ul><li>📈 <strong>Upward Slope </strong>(increasing numbers) for [0, 4, 9, 25] is of <br>length=4.</li><li>Candy count in the upward slope is 10=1+2+3+4 which is the sum of sequentially increasing numbers with n=length=4 (n*n+1/2)</li><li>📉 <strong>Downward Slope</strong> (decreasing numbers) for [25, 8, 6, 5] is of length=4.</li><li>Candy count in the downward slope is 10=4+3+2+1 which is the sum of sequentially increasing numbers with n=length=4 (n*n+1/2)</li><li>The <strong>Peak</strong> for both slopes is the middle child with rating 25.</li></ul><h4>Candy Count for Peak</h4><p><strong>Equal Slopes<br></strong>Candy count for rating 25 (peak) is 4. This is the length of the longest slope that it’s a peak of. In this example, both slopes on it’s left and right sides are coincidentally of length 4.</p><p>This makes sense, since a longer slope means more bumps of 1’s to ensure a child gets more candy than the neighbor. Eventually, the child at peak of the slope will get the maximum number of candies.</p><figure><a href="https://hackernoon.com/10-data-structure-algorithms-books-every-programmer-should-read-d50487313127"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xLYJ7bg1RZ0prgguRrb0tw.png" /></a><figcaption>Bumps of 1’s with Peak at Rating 8 for Ratings [8, 6, 5, 4, 3]</figcaption></figure><p>Let’s <strong>walk up</strong> the downward slope in [0, 4, 9, 25, 8, 6, 5] and do some candy assignments:</p><ol><li>Rating 5: 1 candy; it’s the minimum amount.</li><li>Rating 6: 2 candies &gt; rating 5.</li><li>Rating 8: 3 candies &gt; rating 6.</li><li>Rating 25: 4 candies &gt; rating 8.</li></ol><p>However, the problem is about the total number of candies and doesn’t require us to find the candy/child assignment as in the steps above.</p><p>Keeping that in mind, let’s <strong>walk down</strong> the same downward slope in [0, 4, 9, 25, 8, 6, 5] and do some candy assignments:</p><ol><li>Rating 25: 4 candies &gt; rating 9.</li><li>Rating 8: 1 candy; it’s the minimum amount. <br>This has no impact on the peak’s candy count since it should have at least 1+1=2 candies, and it already has 4.</li><li>Rating 6: 2 candies; downward slope<strong> (without Peak)</strong> has 2 children [8,6]. Ideally rating 6 should have 1 candy and rating 8 should have 2 candies to keep the constraint of higher rating = more candies. Since we don’t care about the exact child-candy pair, this swapping is harmless.<br>This has no impact on the peak’s candy count since it should have at least 2+1=3 candies, and it already has 4.</li><li>Rating 5: 3 candies; downward slope has 3 children [8, 6, 5].<br>Ideally rating 5 should have 1 candy, rating 6 should have 2 candies and rating 8 should have 3 candies to keep the constraint of higher rating = more candies. Since we don’t care about the exact child-candy pair, this swapping is harmless.<br>This has no impact on the peak’s candy count since it should have at least 3+1=4 candies, and it already has 4.</li></ol><p>The benefit in the above approach is that the length of the downward slope simply determines the amount of candies to be given to a child.</p><p><strong>Unequal Slopes<br></strong>Let’s add a child with rating 4 at the end.</p><figure><a href="https://medium.com/javarevisited/top-10-free-data-structure-and-algorithms-courses-for-beginners-best-of-lot-ad807cc55f7a?source=collection_home---4------0-----------------------"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pulxpsTtZKdV-M7X5uS4-A.png" /></a><figcaption>Ratings [0, 4, 9, 25, 8, 6, 5, 4]</figcaption></figure><p>In addition to the steps in the above section, assign 4 candies to rating 4 because the downward slope has 4 children now [8, 6, 5, 4].</p><p>Does this impact the peak at rating 25? It has 4 candies. Given the slope of length 4 ahead of it, it should have 5 candies to maintain the constraint of higher rating = more candies.</p><p>So how do we fix this?</p><p>We find the <strong>Slope Diff: </strong>if the size of this downward slope is greater than or equal to the upward slope (4 ≥ 4), then add 1(slope diff) to the candy count. With a bump of 1, 4 will essentially become a 5 at the peak.</p><p>Let’s add another child with rating 3 at the end.</p><figure><a href="https://medium.com/javarevisited/7-best-courses-to-learn-data-structure-and-algorithms-d5379ae2588?source=---------18------------------"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SGHNNLdQRerAiGs5k-daMg.png" /></a><figcaption>Ratings [0, 4, 9, 25, 8, 6, 5, 4, 3]</figcaption></figure><p>In addition to the steps above, assign 5 candies to rating 3 because the downward slope has 5 children now [8, 6, 5, 4, 3].</p><p>Because the size of the downward slope is greater than upward slope (5≥4), add 1 to the whole candy count. With a bump of 1, 5 will essentially become a 6 at the peak.</p><p>The code for the algorithm is as follows:</p><pre><strong>// Language: Java<br>// Time Complexity: O(n) Linear traversal.<br>// Space Complexity: O(1) Constant space for variables.</strong></pre><pre>public int candy(int[] ratings) {<br>      if (ratings.length &lt; 2) {<br>          return ratings.length;<br>      }<br>         <br>      int count = 1;<br>      int upSlopeLength = 0;<br>      int upSlope = 0;<br>      int downSlope = 0;<br>         <br>      for (int i=1; i&lt;ratings.length; i++) {<br>          int previous = ratings[i-1];<br>          int me = ratings[i];<br>          <br>          // <strong>** Equal Ratings **</strong>   <br>          if (me == previous) {<br>              upSlope = 0;<br>              downSlope = 0;<br>              upSlopeLength = 0;<br>              count += 1;<br>          // <strong>** Upward Slope **<br>          </strong>} else if (me &gt; previous) {<br>              upSlope = upSlope == 0 ? 1 : upSlope;<br>              upSlope += 1;<br>              downSlope = 0;<br>              count += upSlope;<br>              upSlopeLength = upSlope;<br>          // <strong>** Downward Slope **</strong><br>          } else {<br>              upSlope = 0;<br>              downSlope += 1;<br>              int slopeDiff = <br>                (downSlope + 1 - upSlopeLength) &gt; 0 ? 1 : 0;<br>              count += downSlope + slopeDiff;         <br>          }     <br>      }<br>      return count;  <br>}</pre><p>If you found this article useful, <strong>please help me reach more dev learners!</strong></p><p>Show some ❤ by giving “claps” 👏 at the left margin of the page (on desktop) or at the bottom (on mobile). You can do so up to <strong>50</strong> times by clicking continuously!</p><h3>Anum Malik</h3><p>Follow NMTechBytes on <a href="https://twitter.com/anumsarmadmalik">Twitter</a> for my daily tech bites :)</p><h4>Special Thanks:</h4><ul><li><a href="https://leetcode.com/problems/candy/discuss/135698/Simple-solution-with-one-pass-using-O(1)-space">Simple solution with one pass</a></li><li><a href="https://leetcode.com/problems/candy/submissions/">LeetCode Candy Problem</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4c868740f16a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/javarevisited/how-to-solve-the-minimum-candy-distribution-problem-4c868740f16a">Cracking the Minimum Candy Distribution Problem</a> was originally published in <a href="https://medium.com/javarevisited">Javarevisited</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Solve Super Egg Drop Problem with Dynamic Programming]]></title>
            <link>https://medium.com/javarevisited/super-egg-drop-problem-ac42a4b4b09a?source=rss-81d82750f0e9------2</link>
            <guid isPermaLink="false">https://medium.com/p/ac42a4b4b09a</guid>
            <category><![CDATA[dynamic-programming]]></category>
            <category><![CDATA[leetcode]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[algorithms]]></category>
            <dc:creator><![CDATA[NMTechBytes]]></dc:creator>
            <pubDate>Thu, 06 Aug 2020 17:36:15 GMT</pubDate>
            <atom:updated>2020-09-05T02:57:27.777Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>Find the minimum number of egg drops needed to know the lowest floor in a building from which an egg won’t break.</blockquote><h3>Problem Description</h3><figure><a href="https://medium.com/javarevisited/20-array-coding-problems-and-questions-from-programming-interviews-869b475b9121"><img alt="" src="https://cdn-images-1.medium.com/max/512/1*n10o4GdNHxmqNIxMZybD9w.png" /></a><figcaption>By <a href="https://www.flaticon.com/authors/freepik">FreePik</a></figcaption></figure><p>There are<strong> E eggs (= allowed egg breaks)</strong>, a building with <strong>F</strong> <strong>floors</strong> [<strong>1 ≥ F] </strong>and<strong> </strong>a special floor<strong> S</strong> [<strong>0 ≤ S ≤ F] -</strong> any unbroken egg dropped at a floor higher than S<strong> </strong>will break and any egg dropped at or below this floor will not break.</p><p>Given that an unbroken egg can be dropped from any floor, what is the minimum number of <strong>egg drops D [1 ≤ D ≤ F] </strong>needed<strong> </strong>in order to find S<strong> </strong>in the worst case?</p><p>Input1: E =1 , F=1 | Output1: D=1<br>Input2: E =1 , F=2 | Output2: D=2<br>Input3: E =1 , F=7 | Output3: D=7<br>Input4: E =2 , F=7 | Output4: D=4<br>Input5: E =3 , F=7 | Output5: D=3</p><h4>Common confusion points:</h4><ul><li>What is “Worst case”? It means that egg breaking must happen only when the search range from top to bottom is exhausted.</li><li>What is “floor0” in the range for special floor? Treat it as a basement where egg drop isn’t allowed but can be used for reference. Example: S=0 incase the the egg breaks on floor 1 which would mean any drop above floor 0 will result in a break.</li></ul><h3>🍳 Solutions</h3><h4>Linear Search</h4><p>Take an egg to floor1 and start dropping it by going up 1 floor at a time until it breaks or we go beyond the top floor. The worst case is going through all floors [O(F)] to find S=F.</p><figure><a href="https://hackernoon.com/10-data-structure-algorithms-books-every-programmer-should-read-d50487313127"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EfFj4OjmjpziC6DFhd4kAA.png" /></a><figcaption>Linear Search in a Building</figcaption></figure><p>Unfortunately, this algorithm will not work because we have to find the <strong>minimum</strong> number of egg drops needed to find S which will be smaller than S in several cases.</p><h4><strong>Modified Binary Search</strong></h4><p>A typical binary search will get us O(Log2(F)) egg drops. Here we will repeatedly do an egg drop from the middle floor in a range (bottom to top floor) to check whether it breaks. In the illustration below, you can see bottom=1, top=7 and middle=4 for a building in the first iteration.</p><figure><a href="https://medium.com/javarevisited/top-10-free-data-structure-and-algorithms-courses-for-beginners-best-of-lot-ad807cc55f7a?source=collection_home---4------0-----------------------"><img alt="" src="https://cdn-images-1.medium.com/max/798/1*jsELkfNPZ_zt4XNmVfrjYA.png" /></a><figcaption>Binary Search in a Building</figcaption></figure><p>If the egg breaks at floor4, then this floor is above S because an egg will break on all floors above S. So bottom stays as 1 but top changes to middle-1=4 -1=3. If the egg doesn’t break at floor4, then this floor is below S because an egg will not break on any floor below S. So top stays as 7 but bottom changes to middle+1=4 +1=5. After the range change, we continually repeat this process until we find S. The worst case is going through Log2(F) floors to find that S=F or S=0.</p><p>This works great in a world with <strong>unlimited eggs (=egg breaks) </strong>but will be much less efficient with an egg break limit. In the scenario above, what if the first egg breaks from floor4 and then the second egg also breaks from floor2? Since there will be no additional eggs left to continue the algorithm, it will be impossible to find whether S=1 or S=0. To make this work, instead of dropping the second egg at floor2 we can take the second egg to the bottom(floor1) and do a linear search by dropping it as we go up 1 floor at a time.</p><p>Even with this modification, imagine a case with 1000 floors and 2 eggs, we will end up going through 500 floors anyways which is F/2 ~ O(F) in this case. Can we do better?</p><h4>O(ExF) Complexity</h4><p><strong>Two Egg Breaks</strong></p><p>Lets revisit the problem of F floors with a limit of 2 eggs for now along with the modified <a href="https://medium.com/javarevisited/binary-search-in-java-algorithm-eca288cb9bc2?source=extreme_sidebar----d3a191ac6ed-----0-1----------------------">binary search algorithm</a> we learnt to understand the basic theme of the algorithm.</p><p>Assume that we already know that <strong>X</strong> egg drops need to be performed to find S. Given these constraints, the first egg has to be dropped at floor X <strong>(jump to X directly)</strong>. This is necessary to keep the egg drop count equal to X at the end.</p><p>When the first egg breaks, we start the linear search with the second egg from floor1.</p><pre>X =   1 (drop at floor X with first egg) <br>    + X-1 (drops from floor 1 to floor X-1 with second egg)</pre><p>When the first egg doesn’t break at floor X, we can jump up by X-1 and drop it on the floor (X+(X-1))=2X-1. Incase the first egg breaks on this second drop, then we start the linear search at X+1, otherwise we continue to jump up.</p><pre>X =    1 (drop at floor X with first egg) <br>     + 1 (drop at floor 2X-1 with first egg)<br>     + X-2 (drops from floor X+1 to floor 2X-2 with second egg)</pre><p>We keep reducing the jumps by one each time we jump up, until we only have one floor left. To generalize for 2 eggs, in worst case the sum of the jumps should be greater than or equal to the number of floors as follows:</p><pre>X + (X-1) + (X-2) + … + 2 + 1 &gt;= F</pre><p><strong>Limited E Egg Breaks</strong></p><p>Let’s recall a few things before we dive into the actual algorithm:</p><ol><li>Total number of floors in a building = <br> current floor <br> + floors explored when egg breaks at current(bottom to current-1) <br> + floors explored when egg doesn’t break at current(current+1 to top)</li><li>It is possible find egg drops from number of floors and vice-versa (as per the equation) under a constraint of egg breaks.</li></ol><p>We have a 2-D matrix <strong>floors</strong> which is D x E and <strong>floors[d][e]</strong> is the number of floors that we can find S for with egg drops <strong>d </strong>and<strong> </strong>egg breaks <strong>e</strong> (basically the number of eggs) allowed.</p><pre>floors[d][e] =   1 (new floor against new egg drop)<br>               + floors[d-1][e-1] <br>                 (floors with 1 less egg drop and 1 less egg break)<br>               + floors[d-1][e] <br>                 (floors with 1 less egg drop)</pre><p>floors[d][e] is the number of floors we can find S for with d egg drops and e egg breaks. As we drop a new egg, if egg breaks then S is below the current floor else it’s above the current floor. The total number of floors is the sum of the three values:</p><ul><li><strong>current + floors below towards the bottom</strong>: 1 + floors[d-1][e-1] is total number of floors that we can get to from the bottom, given that the egg breaks on the new drop.</li><li><strong>floors above towards the top</strong>: floors[d-1][e] is the number of floors that we can get to from the new floor to the top.</li></ul><p><strong>Code</strong></p><pre># Language: Java<br># Time Complexity: O(ExF) because of the nested loop.</pre><pre>public int superEggDrop(int E, int F) {<br>        <br>        int[][] floors = new int[F+1][E+1];<br>        <br>        for (int d=1; d&lt;=F; d++) {<br>            for (int e=1; e&lt;=E; e++) {<br>                <br>                floors[d][e] = 1 <br>                    + floors[d-1][e-1] <br>                    + floors[d-1][e];<br>                <br>                if (floors[d][e] &gt;= F) {<br>                    return d;<br>                }<br>            }<br>        }<br>        <br>        return -1;<br>}</pre><p>Lets discuss an example in detail; floors is 10 for for D=4 and E=2. The visualization of the floors matrix (for more dimensions than what the code will calculate) is as follows:</p><figure><a href="https://medium.com/javarevisited/7-best-courses-to-learn-data-structure-and-algorithms-d5379ae2588?source=---------18------------------"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eTkBYbGhGwaEaGcx-LT7Lw.png" /></a><figcaption>Floors Matrix 7x7</figcaption></figure><p>Notice how E=1 column values are for the linear search on the floors as only 1 egg break is allowed and E=2 column values follow the logic described in Two Egg Breaks section.</p><figure><a href="https://medium.com/hackernoon/10-data-structure-algorithms-and-programming-courses-to-crack-any-coding-interview-e1c50b30b927?source=user_profile---------8-----------------------"><img alt="" src="https://cdn-images-1.medium.com/max/660/1*8pWzcxZ2Xo3dCZi2eJeeIQ.png" /></a><figcaption>Floors(4,2)</figcaption></figure><p>The algorithm steps are:</p><p>Step1: Drop egg at floor=floors(3,1)+1=3+1=4. We have 3 egg drops left. If broken, <a href="https://javarevisited.blogspot.com/2020/01/how-to-implement-linear-or-sequential-search-in-java.html#axzz6VYKcmyZz">linear search</a> from floor1 to floor3, else go to Step2.</p><p>Step2: Drop egg at floor=4+(4–1)=4+3=7. We have 2 egg drops left. If broken, linear search from floor5 to floor6, else go to Step3.</p><p>Step3: Drop egg at floor=7+(4–2)=9. We have 1 egg drop left. If broken, drop egg at floor 8 else at floor 9.</p><p>If you found this article useful, <strong>please help me reach more dev learners!</strong></p><p>Show some ❤ by giving “claps” 👏 at the left margin of the page (on desktop) or at the bottom (on mobile). You can do so up to 50 times by clicking continuously!</p><h3>Anum Malik</h3><p><a href="https://www.linkedin.com/in/anumsarmadmalik/">LinkedIn</a> | <a href="https://twitter.com/anumsarmadmalik">Twitter</a></p><h4>Special Thanks …</h4><p>[1] <a href="https://leetcode.com/problems/super-egg-drop/discuss/443089/Simplest-Python-DP-Solution-with-Detailed-Explanation-99Time-100Mem">Simplest - Python DP Solution with Detailed Explanation</a><br>[2] <a href="https://labuladong.gitbook.io/algo-en/i.-dynamic-programming/throwingeggsinhighbuildings">Classic DP Super Egg</a><br>[3] <a href="http://datagenetics.com/blog/july22012/index.html">The Two Egg Problem</a><br>[4] <a href="https://leetcode.com/problems/super-egg-drop/">887. Super Egg Drop</a></p><p>Other <strong>Data Structure and Algorithms Articles</strong> you may like:</p><ul><li><a href="https://medium.com/javarevisited/50-data-structure-and-algorithms-interview-questions-for-programmers-b4b1ac61f5b0">Top 50 Data Structure and Algorithms Interview Questions for Programmers</a></li><li><a href="https://medium.com/javarevisited/top-10-data-structure-and-algorithms-courses-for-java-developers-25161ee2edc0">Top 10 Data Structure and Algorithms courses for Java Developers</a></li><li><a href="https://medium.com/javarevisited/top-21-string-programming-interview-questions-for-beginners-and-experienced-developers-56037048de45">Top 21 String Programming Interview Questions for Beginners and Experienced Developers</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ac42a4b4b09a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/javarevisited/super-egg-drop-problem-ac42a4b4b09a">How to Solve Super Egg Drop Problem with Dynamic Programming</a> was originally published in <a href="https://medium.com/javarevisited">Javarevisited</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[LeetCode: Longest Palindromic Substring With Manachar’s Algorithm]]></title>
            <link>https://medium.com/swlh/leetcode-longest-palindromic-substring-with-manachars-algorithm-8cc42aeae465?source=rss-81d82750f0e9------2</link>
            <guid isPermaLink="false">https://medium.com/p/8cc42aeae465</guid>
            <category><![CDATA[palindrome]]></category>
            <category><![CDATA[leetcode]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[substring]]></category>
            <category><![CDATA[coding]]></category>
            <dc:creator><![CDATA[NMTechBytes]]></dc:creator>
            <pubDate>Sun, 26 Jul 2020 09:13:51 GMT</pubDate>
            <atom:updated>2020-09-07T17:32:02.710Z</atom:updated>
            <content:encoded><![CDATA[<h3>Longest Palindromic Substring With Manachar’s Algorithm</h3><blockquote>LeetCode: Given a string s, find the longest palindromic substring in s.</blockquote><h3>What is a Palindrome?</h3><p>A palindrome is a word that reads the same forwards and backwards. In my universe, there are two kinds of palindrome: <strong><em>“Odd Pal”</em></strong> and <strong><em>“Even Pal”</em></strong>.</p><h4>Even Pal</h4><p>Even Pal is a palindrome which has an even length, for example: “ZYXXYZ”. In the visualization below you can see how we can split it into 2 parts that have size 3: “ZYX” and “XYZ” . This palindrome will always have two centres called <strong>“<em>Left Center”</em></strong> at index2 and <strong><em>“Right Center”</em></strong> at index3.</p><figure><img alt="Even Pals" src="https://cdn-images-1.medium.com/max/528/1*iQpx3puD-dXk8TSIeqQAQg.png" /><figcaption>“Even Pal”</figcaption></figure><p>Notice that:</p><ul><li>character at index2 = character at index3 <strong><em>(mirror 1)</em></strong></li><li>character at index1 = character at index4 <strong><em>(mirror 2)</em></strong></li><li>character at index0 = character at index5 <strong><em>(mirror 3)</em></strong></li></ul><p>It is because of the above equality of characters at their respective indexes that the string is a palindrome and the two parts look like a sequence of <strong><em>3 mirrors.</em></strong></p><h4>Odd Pal</h4><p>Odd Pal is a palindrome which has an odd length, example: “ZYXWXYZ”. In the visualization below you can see how we can split the string into 2 parts that have size 3: “ZYX” and “XYZ”, while “W” at index3 becomes the center.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/578/1*-QRR7aJP71g7irhSIFxw8g.png" /><figcaption>“Odd Pal”</figcaption></figure><p>Notice that:</p><ul><li>character at index2 = character at index4 <strong><em>(mirror 1)</em></strong></li><li>character at index1 = character at index5 <strong><em>(mirror 2)</em></strong></li><li>character at index0 = character at index6 <strong><em>(mirror 3)</em></strong></li></ul><p>Notice how again the two parts look like a sequence of <strong><em>3 mirrors.</em></strong></p><h3>Problem</h3><p>The problem states that we have to find the longest substring that is a palindrome in the string. A substring is a section of a string that consists of contiguous elements. Some examples are:</p><p>Input1: “BABAD” | Output1: “BAB” or “ABA”<br>Input2: “CBBD” | Output2: “BB”<br>Input3: “A” | Output3: “A”</p><h3>Solutions</h3><h4>O(n²) Complexity</h4><p>The simplest way to solve for this is to take every index as 1) a center 2) a Left Center and <em>“</em><strong><em>expand outwards</em></strong><em>”</em> to make character comparisons and find mirrors. The sequence with the maximum number of mirrors would be returned. Seems very simple and intuitive but the complexity is O(n²) because expanding a palindrome around a center could take O(n) time and we will explore every index in the string to be a center and left center, so O(n²) would be the time complexity.</p><h4>O(n) Complexity</h4><p>We can improve this runtime if we think of a way where we can leverage the previous palindromes found (as we navigate through the string) and reduce the “expanding outwards” part. Luckily, this is possible with <strong><em>“Manachar’s algorithm”</em></strong>.</p><h3>Manachar’s algorithm</h3><p>Before diving into the algorithm itself, we need to learn a few things first. For simplicity we will be focusing on Odd Pals for the most part. So let’s learn a few things in order:</p><h4>1. Find mirror for an index around a center.</h4><p>The distance between centerIndex (index of the center) and index should be equal to the distance between mirrorIndex (index of the mirror) and centerIndex:</p><pre>centerIndex - index = mirrorIndex - centerIndex</pre><p>A little re-arranging gives us:</p><pre>mirrorIndex = centerIndex + centerIndex - index<br>mirrorIndex = 2 * centerIndex - index</pre><h4><strong>2. Calculate mirrors around each center in a palindrome.</strong></h4><p>The mirrors row in the following illustration has the maximum number of mirrors around an index assuming it’s the center.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/766/1*kzwGeWoh95Rjlmd7TPchag.png" /></figure><p>Lets look at the first 4 indexes to make the calculation logic more clear:</p><ul><li>index0: X has no mirrors since it has no characters on the left which could be mirrors.</li><li>index1: Y has [index0/index2] as 1 mirror.</li><li>index2: X has [index1/index3, index0/index4] as 2 mirrors.</li><li>index3: Y has [index2/index4, index1/index5, index0/index6] as 3 mirrors.</li><li>index4: X has [index3/index5, index2/index6, index1/index2, index0/index8] as 4 mirrors.</li></ul><p>After the center for the longest palindrome, index4, notice how the mirror count is the same for as it’s mirror index:</p><ul><li>index5: MirrorIndex=2*4–5=index3 which has the same mirrors as 3.</li><li>index6: MirrorIndex=2*4–6=index2 which has the same mirrors as 2.</li><li>index7: MirrorIndex=2*4–7=index1 which has the same mirrors as 1.</li><li>index8: MirrorIndex=2*4–8=index0 which has the same mirrors as 0.</li></ul><p>The reason behind this is because it has already been established that index0 to index8 is a palindrome around a center index4 and hence the property of it reading same as forward and backwards ensure this equality.</p><h4>3. Re-calculate mirrors with characters outside the palindrome.</h4><p>Let’s add a new character outside one of the longest palindrome range to see how the mirror values are different from the values before.</p><p>The following illustration demonstrates the new mirror values where longest palindrome is at index 4(i am ignoring index5 with the same number for simplicity). The “<strong><em>right boundary” </em></strong>for center index4 is index8 and we have added “Y” at index9.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/710/1*DbROOaULB5au9FdHj7ChBg.png" /></figure><p>Lets look at the last 4 indexes to make the calculation logic more clear:</p><ul><li>index5: MirrorIndex has 3 mirrors but it has 4 mirrors because of an additional match of index1 and index9.</li><li>index6: MirrorIndex has 2 mirrors but it has 3 mirrors because of an additional match of index3 and index9.</li><li>index7: MirrorIndex has 2 mirrors but it has 3 mirrors because of an additional match of index5 and index9.</li><li>index8: MirrorIndex has 1 mirror but it has 2 mirrors because of an additional match of index7 and index9.</li></ul><p>This basically means that with more characters outside the palindrome, the mirrors will have to be recalculated for every index. Hence, it seems like each time we will have to expand outwards at every index(as described earlier) to figure out the right max, but instead of starting from the center index every time, can we use information that we know about the previous palindrome found to reduce the effort? Yes, we can.</p><h4>4. Can we expand outwards with reduced effort?</h4><p>To reduce effort, we need to find where to start the attempt to expand and for that we have to find the minimum mirrors that exist around that index as follows:</p><pre>minimumMirrors = Min(rightBoundary-index, mirrors[mirrorIndex])</pre><p>The maximum count of mirrors from the mirror index that we can use for index is a count that stays inside the last found palindrome because if the count crosses the boundary of the palindrome then it is bringing in extra characters that we never checked with current index as center.</p><p>If it stays inside the boundary then we use the value as-is but if it’s outside the boundary, then it means that at-least the characters between mirrorIndex and the left boundary is palindromic with characters on the other side of the mirrorIndex. This is because the original mirror count is high enough to cross the boundary, so anything smaller should be a palindrome as well.</p><p>The count of this is actually the distance of the mirror index with the left boundary which is equal to the distance between the right boundary and index. Basically:</p><pre>mirrorIndex — leftBoundary = rightBoundary - index</pre><p>Now that we have a revised mirror count, we expand outwards from index+mirrors[index]+1 and index-mirrors[index]-1 to make character comparisons, rather than starting from the center.</p><h4>5. Code</h4><p>The code will now accommodate Even Pals as well by adding hashes in the input string as hypothetical centers.</p><pre>/**** main function ****/<br>public String longestPalindrome(String s) {<br>  if (s.length() &lt; 2) {<br>    return s;<br>  }<br>        <br>  // add hashes to String, example &quot;abc&quot; would become &quot;#a#b#c#&quot; <br>  // this is because we need to find even pals as well.</pre><pre>  String hash = &quot;#&quot;;<br>  String hashedString = insertInto(s, hash);<br>  int[] mirrors = new int[hashedString.length()];<br>  int centerIndex = 0;<br>  int rightBoundary = 0;<br>        <br>  for (int index=1; index&lt;hashedString.length(); index++) { <br>    // find mirrorIndex.<br>    int mirrorIndex = 2 * centerIndex - index;<br>            <br>    // adjust number of mirrors.<br>    if (index &lt; rightBoundary) {<br>      mirrors[index] = Math.min(rightBoundary - index;<br>                                mirrors[mirrorIndex]); <br>    }<br>            <br>    // expand outwards and make comparisons.<br>    int leftIndex;<br>    int rightIndex;<br>    while((leftIndex = index - mirrors[index] - 1) &gt;= 0 <br>      &amp;&amp; (rightIndex = index + mirrors[index] + 1) <br>          &lt; mirrors.length<br>      &amp;&amp; hashedString.charAt(leftIndex) <br>          == hashedString.charAt(rightIndex)) {<br>      mirrors[index]++;<br>    }<br>            <br>    // adjust center and rightBoundary if the new palindrome <br>    // found lies outside the boundary.<br>    if (index + mirrors[index] &gt; rightBoundary) {<br>      centerIndex = index;<br>      rightBoundary = centerIndex + mirrors[index];<br>    }     <br>  }<br>        <br>  int maxIndex = getIndexWithMaxMirrors(mirrors);<br>  int maxMirrors = mirrors[maxIndex];<br>  String maxString = hashedString<br>         .substring(maxIndex - maxMirrors,  <br>                    maxMirrors + maxIndex + 1)<br>         .replace(hash,&quot;&quot;);<br>  return maxString;<br>}</pre><pre>/**** private helpers ****/<br>private int getIndexWithMaxMirrors(int[] mirrors) {<br>  int maxValue = -1;<br>  int maxIndex = -1;     <br>  for (int index=0; index&lt;mirrors.length; index++) {<br>    if (mirrors[index] &lt;= maxValue) {<br>      continue;<br>    }<br>    maxValue = mirrors[index];<br>    maxIndex = index;<br>  } <br>  return maxIndex;      <br>}<br>    <br>private String insertInto(String s, String marker) {<br>  StringBuilder sb = new StringBuilder();<br>  for (char ch: s.toCharArray()) {<br>    sb.append(marker);<br>    sb.append(ch);          <br>  }<br>  sb.append(marker);<br>  return sb.toString();<br>}</pre><h4>6. Wait — how is the complexity O(N)?</h4><p>The rightBoundary always moves to the right and at max will take N steps. Plus you never repeat a step and don’t start from the center but leverage on already found palindromes and mirror calculations.</p><p>If you found this article useful, <strong>please help me reach more dev learners</strong>!</p><p>Show some ❤ by giving “claps” 👏 at the left margin of the page (on desktop) or at the bottom (on mobile). You can do so up to 50 times by clicking continuously!</p><h3>Anum Malik</h3><p>Follow NMTechBytes on <a href="https://twitter.com/anumsarmadmalik">Twitter</a> for my daily tech bites :)</p><h4>Special Thanks</h4><p>[1] Longest Palindromic Substring O(N) Manacher’s Algorithm:<br><a href="https://www.youtube.com/watch?v=nbTSfrEfo6M">https://www.youtube.com/watch?v=nbTSfrEfo6M</a><br>[2] Manacher’s Algorithm: <a href="https://www.hackerrank.com/topics/manachers-algorithm">https://www.hackerrank.com/topics/manachers-algorithm</a><br>[3] How do I analyze the time complexity of Manacher’s algorithm?:<a href="https://www.quora.com/How-do-I-analyze-the-time-complexity-of-Manachers-algorithm">https://www.quora.com/How-do-I-analyze-the-time-complexity-of-Manachers-algorithm</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8cc42aeae465" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/leetcode-longest-palindromic-substring-with-manachars-algorithm-8cc42aeae465">LeetCode: Longest Palindromic Substring With Manachar’s Algorithm</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Where can I learn AWS (Amazon Web Services) from?]]></title>
            <link>https://medium.com/javarevisited/where-can-i-learn-aws-amazon-web-services-from-fe6eb0348?source=rss-81d82750f0e9------2</link>
            <guid isPermaLink="false">https://medium.com/p/fe6eb0348</guid>
            <category><![CDATA[aws-certification]]></category>
            <category><![CDATA[cloud]]></category>
            <category><![CDATA[amazon-web-services]]></category>
            <category><![CDATA[certification]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[NMTechBytes]]></dc:creator>
            <pubDate>Sun, 19 Jul 2020 21:30:39 GMT</pubDate>
            <atom:updated>2020-09-07T17:32:41.707Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Where can I start learning AWS (Amazon Web Services)?</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5eemhl1TDovbs4ozb8XnZw.png" /></figure><p>I have been recently asked a question: “Where can I start learning about AWS (Amazon Web Services) as a beginner ?”</p><p>There are lots of resources you can learn AWS from; following are 6 different ways that I know of:</p><ol><li><a href="https://aws.amazon.com/training/self-paced-labs/">AWS Self-Paced Labs</a>:<br> 💡 Individual Lab: Learn a single AWS Service.<br> 💡 Quest Labs: Multiple labs to learn related AWS Services.</li><li>Play around with 60+ services with the following <a href="https://aws.amazon.com/free">AWS Free Tier</a> options:<br> 💡 Free for life.<br> 💡 Free for 12 months post sign-up date.<br> 💡 Short-term offer post service-activation date.</li><li>Read and follow:<br> 💡 <a href="https://docs.aws.amazon.com/index.html">AWS Documentation</a><br> 💡 <a href="https://aws.amazon.com/whitepapers/?whitepapers-main.sort-by=item.additionalFields.sortDate&amp;whitepapers-main.sort-order=desc">AWS WhitePapers</a><br> 💡 <a href="https://aws.amazon.com/blogs/aws/">AWS Blog</a><br> 💡 <a href="https://awsinsider.net/Home.aspx">AWS Insider</a><br> 💡 <a href="https://github.com/donnemartin/awesome-aws">AWS Tools and Libraries</a><br> 💡 <a href="https://wa.aws.amazon.com/index.en.html">AWS Well-Architected Framework</a><br> 💡 <a href="https://wellarchitectedlabs.com/">AWS Well-Architected Labs</a><br> 💡 <a href="https://blog.cloudthat.com/">CloudThat</a><br> 💡 <a href="https://egghead.io/courses/build-an-app-with-the-aws-cloud-development-kit">Build an app with AWS Cloud Development Kit</a><br> 💡 <a href="https://github.com/dwyl/learn-amazon-web-services">Learn AWS</a><br> 💡 <a href="https://github.com/open-guides/og-aws">Open Guide to AWS</a><br> 💡 <a href="https://github.com/aws-samples">Github AWS Samples</a></li><li>Watch:<br> 💡 <a href="https://www.youtube.com/channel/UCd6MoB9NC6uYN2grvUNT-Zg">AWS Web Services</a><br> 💡 <a href="https://www.youtube.com/channel/UC1Yf7IBfhSNFTIyb7v83o_g">AWS Training Center</a><br> 💡 <a href="http://linkedin-learning.pxf.io/c/1193463/449670/8005?u=https%3A%2F%2Fwww.linkedin.com%2Flearning%2Fpaths%2Fbecome-an-aws-cloud-practitioner">LinkedIn Learning</a></li><li>Courses:<br> 💡 <a href="https://pages.awscloud.com/digital-learning-training-certification.html">AWS Training</a><br> 💡 <a href="http://linkedin-learning.pxf.io/c/1193463/449670/8005?u=https%3A%2F%2Fwww.linkedin.com%2Flearning%2Fpaths%2Fbecome-an-aws-cloud-practitioner">LinkedIn Learning</a><br> 💡 <a href="https://acloud.guru/aws-cloud-training">A Cloud Guru</a><br> 💡 <a href="https://click.linksynergy.com/deeplink?id=JVFxdTr9V80&amp;mid=39197&amp;murl=https%3A%2F%2Fwww.udemy.com%2Fcourse%2Faws-certified-associate-architect-developer-sysops-admin%2F">Udemy</a><br> 💡 <a href="https://click.linksynergy.com/deeplink?id=JVFxdTr9V80&amp;mid=40328&amp;murl=https%3A%2F%2Fwww.coursera.org%2Fspecializations%2Faws-fundamentals">Coursera</a><br> 💡 <a href="https://cloudacademy.com/library/amazon-web-services">Cloud Academy</a><br> 💡 <a href="https://www.qwiklabs.com/">Qwiklabs</a></li><li><a href="https://aws.amazon.com/certification/">AWS Certifications</a>:<br> 💡 <a href="https://aws.amazon.com/training/learning-paths/">AWS Learning Paths</a><br> 💡 <a href="https://shrsl.com/25qj6">Whiz Labs</a><br> 💡 <a href="https://gist.github.com/leonardofed/bbf6459ad154ad5215d354f3825435dc">List of resources for Preparation</a><br> 💡 <a href="https://github.com/Rome84/AWS-EXAMS">Sample Exams</a></li></ol><p>Hope this helps, have fun!</p><p>Follow NMTechBytes on <a href="https://twitter.com/anumsarmadmalik">Twitter</a> for my daily tech bites :)</p><h4>Other AWS articles you may find interested</h4><ul><li><a href="https://medium.com/javarevisited/top-5-aws-training-courses-to-crack-amazon-web-service-solutions-architect-associate-certification-3f4affa8f660">My Favorite Courses to Crack AWS Solutions Architect Associate Certification in 2020</a></li><li><a href="https://medium.com/javarevisited/top-15-online-courses-to-learn-docker-kubernetes-and-aws-for-fullstack-developers-and-devops-d8cc4f16e773">Top 15 online courses to learn Docker, Kubernetes, and AWS in 2024</a></li><li><a href="https://medium.com/javarevisited/top-10-courses-to-learn-amazon-web-services-aws-cloud-in-2020-best-and-free-317f10d7c21d">My Favorite Courses to Learn Amazon Web Services (AWS) and Cloud Computing for Beginners</a></li></ul><p><em>Note: I work at Amazon, but all my articles reflect my own opinion.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fe6eb0348" width="1" height="1" alt=""><hr><p><a href="https://medium.com/javarevisited/where-can-i-learn-aws-amazon-web-services-from-fe6eb0348">Where can I learn AWS (Amazon Web Services) from?</a> was originally published in <a href="https://medium.com/javarevisited">Javarevisited</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>