<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Daisy Rono</title>
    <description>The latest articles on DEV Community by Daisy Rono (@daisy2111cheneno).</description>
    <link>https://dev.to/daisy2111cheneno</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F877759%2F7f65e503-1a78-4d7b-9aa5-95f618098ebf.png</url>
      <title>DEV Community: Daisy Rono</title>
      <link>https://dev.to/daisy2111cheneno</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/daisy2111cheneno"/>
    <language>en</language>
    <item>
      <title>Data Structure and Algorithms 102: Deep Dive into Data Structure and Algorithms</title>
      <dc:creator>Daisy Rono</dc:creator>
      <pubDate>Sun, 26 Jun 2022 06:36:41 +0000</pubDate>
      <link>https://dev.to/daisy2111cheneno/data-structure-and-algorithms-102-deep-dive-into-data-structure-and-algorithms-12nj</link>
      <guid>https://dev.to/daisy2111cheneno/data-structure-and-algorithms-102-deep-dive-into-data-structure-and-algorithms-12nj</guid>
      <description>&lt;p&gt;Alice and Bob each created one problem for HackerRank. A reviewer rates the two challenges, awarding points on a scale from 1 to 100 for three categories: problem clarity, originality, and difficulty.&lt;/p&gt;

&lt;p&gt;The rating for Alice's challenge is the triplet a = (a[0], a[1], a[2]), and the rating for Bob's challenge is the triplet b = (b[0], b[1], b[2]).&lt;/p&gt;

&lt;p&gt;The task is to find their comparison points by comparing a[0] with b[0], a[1] with b[1], and a[2] with b[2].&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If a[i] &amp;gt; b[i], then Alice is awarded 1 point.&lt;/li&gt;
&lt;li&gt;If a[i] &amp;lt; b[i], then Bob is awarded 1 point.&lt;/li&gt;
&lt;li&gt;If a[i] = b[i], then neither person receives a point.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Comparison points is the total points a person earned.&lt;/p&gt;

&lt;p&gt;Given a and b, determine their respective comparison points.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;a = [1, 2, 3]&lt;br&gt;
b = [3, 2, 1]&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;For elements &lt;em&gt;0&lt;/em&gt;, Bob is awarded a point because a[0] .&lt;/li&gt;
&lt;li&gt;For the equal elements a[1] and b[1], no points are earned.&lt;/li&gt;
&lt;li&gt;Finally, for elements 2, a[2] &amp;gt; b[2] so Alice receives a point.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The return array is [1, 1] with Alice's score first and Bob's second.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Function Description&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Complete the function compareTriplets in the editor below.&lt;/p&gt;

&lt;p&gt;compareTriplets has the following parameter(s):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;int a[3]: Alice's challenge rating&lt;/li&gt;
&lt;li&gt;int b[3]: Bob's challenge rating&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Return&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;int[2]: Alice's score is in the first position, and Bob's score is in the second.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Input Format&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The first line contains 3 space-separated integers, a[0], a[1], and a[2], the respective values in triplet a.&lt;br&gt;
The second line contains 3 space-separated integers, b[0], b[1], and b[2], the respective values in triplet b.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Constraints&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;1 ≤ a[i] ≤ 100&lt;/li&gt;
&lt;li&gt;1 ≤ b[i] ≤ 100&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Sample Input 0&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;5 6 7
3 6 10
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Sample Output 0&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1 1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Explanation 0&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In this example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;a = (a[0],a[1],a[2])=(5,6,7)&lt;/li&gt;
&lt;li&gt;b = (b[0],b[1],b[2])=(3,6,10)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now, let's compare each individual score:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;a[0] &amp;gt; b[0], so Alice receives  point.&lt;/li&gt;
&lt;li&gt;a[1] = b[1], so nobody receives a point.&lt;/li&gt;
&lt;li&gt;a[2] &amp;lt; b[2], so Bob receives  point.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Alice's comparison score is 1, and Bob's comparison score is 1. Thus, we return the array [1,1].&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Sample Input 1&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;17 28 30
99 16 8
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Sample Output 1&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;2 1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Explanation 1&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Comparing the 0#th elements 17&amp;lt;99, so Bob receives a point.&lt;br&gt;
Comparing the 1#st and 2#nd elements, 28&amp;gt;16 and 30&amp;gt;18 so Alice receives two points. The return array is [2,1].&lt;/p&gt;

&lt;p&gt;The solution in PHP:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function compareTriplets($a, $b) {
    // Write your code here
    $aAward = 0;
    $bAward = 0;

    for ($i=0;$i&amp;lt;3;$i++){
        if($a[$i]&amp;gt;$b[$i]){
            $aAward +=1;
        }elseif($a[$i]&amp;lt;$b[$i]){
            $bAward +=1;
        }
    }

return array($aAward,$bAward);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In Python3:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def compareTriplets(a, b):
    # Write your code here
    aAward = 0
    bAward = 0

    for i in range(0,3):
        if(a[i]&amp;gt;b[i]):
            aAward += 1
        if (a[i]&amp;lt;b[i]):
            bAward += 1

    return [aAward,bAward] 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In Kotlin:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fun compareTriplets(a: Array&amp;lt;Int&amp;gt;, b: Array&amp;lt;Int&amp;gt;): Array&amp;lt;Int&amp;gt; {

    var aAward =0 
    var bAward= 0 
    // Write your code here

    for (i in 0..2){
        if(a[i]&amp;gt;b[i]){
            aAward += 1
        }
        if(a[i]&amp;lt;b[i]){
            bAward +=1
        } 
    }
return arrayOf(aAward,bAward);
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>Splitting a 3x3 matrix into all possible 2x2 matrices using PHP</title>
      <dc:creator>Daisy Rono</dc:creator>
      <pubDate>Sat, 18 Jun 2022 12:01:08 +0000</pubDate>
      <link>https://dev.to/daisy2111cheneno/splitting-a-3x3-matrix-into-all-possible-2x2-matrices-using-php-k1l</link>
      <guid>https://dev.to/daisy2111cheneno/splitting-a-3x3-matrix-into-all-possible-2x2-matrices-using-php-k1l</guid>
      <description>&lt;h2&gt;
  
  
  &lt;u&gt;Creating the 3x3 matrix&lt;/u&gt;
&lt;/h2&gt;

&lt;p&gt;To create a 3x3 matrix, begin with an array&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$a = array(array(1,5,7),array(7,3,5),array(2,6,9));
$rows = count($a);
$cols = count($a[0]);

for ($k = 0; $k &amp;lt; $rows; $k++){
    for ($j = 0; $j &amp;lt; $cols; $j++){
        echo ($a[$k][$j]."  ");
    }
    echo ("&amp;lt;br&amp;gt;");
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will result in&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1 5 7
7 3 5
2 6 9
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;strong&gt;&lt;u&gt;Getting 2x2 matrices&lt;/u&gt;&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;There are 4 possible 2x2 matrices that could be derived from the 3x3 matrix above. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Begin with row index zero and column index zero and reduce the number of rows and columns by one. (since its a 3x3 matrix we wish to reduce to a 2x2, the row and column both reduce by one)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;To create another matrix, Increment either the row by one. Repeat this step with the column, this time holding the row constant.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The first 2x2 matrix is begins at k = 0 and j = 0. However, the arrays are reduced by one from both ends like seen in the code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for ($k = 0; $k &amp;lt; $rows-1; $k++){
    for ($j = 0; $j &amp;lt; $cols-1; $j++){
        echo ($a[$k][$j]." ");
    }
    echo ("&amp;lt;br&amp;gt;");
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The output of this is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1 5
7 3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The maximum and minimum values of this matrix are 7 and 1 respectively.&lt;/p&gt;

&lt;p&gt;The second 2x2 matrix has the row starting at k=0 and ending at k &amp;lt; row-1 but the column starts at j =1 and ends at j &amp;lt; cols as shown below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for ($k = 0; $k &amp;lt; $rows-1; $k++){
    for ($j = 1; $j &amp;lt; $cols; $j++){
        echo ($a[$k][$j]." ");
    }
    echo ("&amp;lt;br&amp;gt;");
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The output of this is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;5 7
3 5
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The maximum and minimum values of this matrix are 7 and 3 respectively.&lt;/p&gt;

&lt;p&gt;Here, the rows start at k =1 while the columns start at j =0.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for ($k = 1; $k &amp;lt; $rows; $k++){
    for ($j = 0; $j &amp;lt; $cols-1; $j++){
        echo ($a[$k][$j]." ");
    }
    echo ("&amp;lt;br&amp;gt;");
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The output of this is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;7 3
2 6
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The maximum and minimum values of this matrix are 7 and 2 respectively.&lt;/p&gt;

&lt;p&gt;Now, both rows and columns start at 1.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for ($k = 1; $k &amp;lt; $rows; $k++){
    for ($j = 1; $j &amp;lt; $cols; $j++){
        echo ($a[$k][$j]." ");
    }
    echo ("&amp;lt;br&amp;gt;");
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The output of this is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;3 5
6 9

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The maximum and minimum values of this matrix are 9 and 3 respectively.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;u&gt;The Minimum and Maximum values Matrices&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To merging the minimum values to form other matrix of minimum values using arrays, use&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#minimum value
echo "&amp;lt;br&amp;gt;";
$b =array(array(1,3),array(2,3));
$rows_b = count($b);
$cols_b = count($b[0]);
for ($i = 0; $i &amp;lt; $rows_b; $i++){
    for ($l = 0; $l &amp;lt; $cols_b; $l++){
        echo ($b[$i][$l]."  ");
    }
    echo ("&amp;lt;br&amp;gt;");
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This results to a matrix of the form&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1 3
2 3

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The same concept is applied to maximum values using&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$c =array(array(7,7),array(7,9));
$rows_c = count($c);
$cols_c = count($c[0]);
for ($m = 0; $m &amp;lt; $rows_c; $m++){
    for ($n = 0; $n &amp;lt; $cols_c; $n++){
        echo ($c[$m][$n]."  ");
    }
    echo ("&amp;lt;br&amp;gt;");
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;resulting in the 2x2 matrix below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;7 7
7 9

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>php</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Data Structures 101: Introduction to Data Structures and Algorithms.</title>
      <dc:creator>Daisy Rono</dc:creator>
      <pubDate>Thu, 16 Jun 2022 08:25:57 +0000</pubDate>
      <link>https://dev.to/daisy2111cheneno/hackerrank-simple-array-sum-problem-using-php-1pjp</link>
      <guid>https://dev.to/daisy2111cheneno/hackerrank-simple-array-sum-problem-using-php-1pjp</guid>
      <description>&lt;p&gt;&lt;strong&gt;Problem&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Given an array of integers, find the sum of its elements.&lt;br&gt;
For example, if the array &lt;strong&gt;ar=[1,2,3],1+2+3=6&lt;/strong&gt;,so return 6.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Function Description&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Complete the simpleArraySum function in the editor below. It must return the sum of the array elements as an integer.&lt;/p&gt;

&lt;p&gt;simpleArraySum has the following parameter(s):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;ar: an array of integers&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Input Format&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The first line contains an integer, &lt;strong&gt;n&lt;/strong&gt;, denoting the size of the array.&lt;br&gt;
The second line contains &lt;strong&gt;n&lt;/strong&gt; space-separated integers representing the array's elements.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Constraints&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;0 &amp;lt; n, ar[i] &amp;lt; 1000&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Output Format&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Print the sum of the array's elements as a single integer.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Sample Input&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;6
1 2 3 4 10 11
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Sample Output&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;31
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Explanation&lt;/p&gt;

&lt;p&gt;We print the sum of the array's elements:&lt;br&gt;
&lt;strong&gt;1+2+3+4+10+11=31&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Solution&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Here, three approaches are used to solve this problem.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Foreach&lt;/strong&gt;&lt;br&gt;
This approach does not require the the size of the array hence the most likely loop to be used for this problem.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function simpleArraySum($ar) {
    // Write your code here
    $sum = 0;
    foreach($ar as $value){
        $sum += $value;
    }
        return $sum;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. For Loop&lt;/strong&gt;&lt;br&gt;
The size of the array and the sum of the array are initialized before using for loop. The indices of the arrays to be summed are incremented by one to move to the next item in the array.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function simpleArraySum($ar) {
    $size = count($ar);
    $sum = 0;

    for($i=0 ; $i &amp;lt; $size; $i++){
      $sum += $ar[$i];
    }

    return $sum;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3. While Loop&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This is the same as for loop but the operation stops when the condition &lt;code&gt;$i &amp;lt; count($ar)&lt;/code&gt; is no longer true.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function simpleArraySum($ar){
    $sum = 0;
    $i = 0;
    while($i &amp;lt; count($ar)){
        $sum += $ar[$i];
        $i++;
    }
    return $sum;

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The output of all three approaches is&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;31
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>beginners</category>
      <category>php</category>
    </item>
  </channel>
</rss>
