<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Graph on Code Mirroring</title><link>https://www.codemirroring.com/ds-algo/graph/</link><description>Recent content in Graph on Code Mirroring</description><generator>Hugo</generator><language>en-us</language><atom:link href="https://www.codemirroring.com/ds-algo/graph/index.xml" rel="self" type="application/rss+xml"/><item><title>Number of Provinces</title><link>https://www.codemirroring.com/ds-algo/graph/number-of-provinces/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://www.codemirroring.com/ds-algo/graph/number-of-provinces/</guid><description>&lt;h2 id="problem-statement"&gt;Problem statement&lt;/h2&gt;
&lt;p&gt;You get an &lt;code&gt;n × n&lt;/code&gt; matrix &lt;code&gt;isConnected&lt;/code&gt; for &lt;code&gt;n&lt;/code&gt; cities. &lt;code&gt;isConnected[i][j] == 1&lt;/code&gt; means city &lt;code&gt;i&lt;/code&gt; and city &lt;code&gt;j&lt;/code&gt; are directly linked (and the matrix is symmetric). A &lt;strong&gt;province&lt;/strong&gt; is a set of cities connected directly or through other cities — essentially one connected component.&lt;/p&gt;
&lt;p&gt;Return how many provinces there are.&lt;/p&gt;
&lt;p&gt;Example:&lt;/p&gt;
&lt;p&gt;Input:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;isConnected = [[1,1,0],[1,1,0],[0,0,1]]
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Expected output:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;2
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Why: cities &lt;code&gt;0&lt;/code&gt; and &lt;code&gt;1&lt;/code&gt; form one province; city &lt;code&gt;2&lt;/code&gt; is alone.&lt;/p&gt;</description></item></channel></rss>